Home > Electronic Tutorials > Microcontroller Tutorials > PIC 16F877A Project Tutorial > Output Messages to Computer Screen

PIC16F877A Microcontroller Project Tutorial

Output Messages to Computer Screen

Have used 2 methods.

1. PICkit 2 Development Programmer/Debugger. See their instructions in the program or website.

2. Serial port. I used HyperTerminal to read text from the serial port & display on screen, but other programs can do that too. Make sure the baud rate is 9600 bits / sec, just like in the PIC code: #use rs232(baud=9600, xmit=PIN_C6, invert)

Serial Port Pin Diagram

Serial Port Steps (if using HyperTerminal)

1. Wire serial port pin 2 to pin TX (same as RC6) on the PIC.
2. Wire serial port pin 5 to ground.
3. Connect serial port to computer. Use a serial-USB adapter if computer has no serial port.
4. Open HyperTerminal.
5. Enter any name, select the icon that says “MCI”
6. Connect using COM5/COM13/etc. If there are multiple COMs: pull out the USB, reopen HyperTerminal, & see which COM has vanished. That’s the one you want.
7. Set bits per second = 9600.
8. HyperTerminal is set up. It will keep reading input until you close the program.
9. Load code onto PIC
10. Hit switch to turn on PIC

Code

#include <16F877A.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //Highspeed Osc > 4mhz
#FUSES PUT //Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#use delay(clock=20000000) // Sets crystal oscillator at 20 megahertz
#use rs232(baud=9600, xmit=PIN_C6, invert) //Sets up serial port output pin & baud rate

void main(){
     int x = 0;
     while(true){
          x = x + 1;

          //This is an ordinary C language printf statement that will display on the screen of your PC.
          //But, you need to open a special program to read serial port input, like HyperTerminal.
          //Make sure the baud rate of the program matches this code’s baud rate (9600 bits / second)

          printf("hello, x=%d\r\n",x); //send this text to serial port

          delay_ms(100); //wait 100 milliseconds
     }
}

Note: To report broken links or to submit your projects please send email to Webmaster

Discover

     more......