How to Interface UART with PIC16F877A

UART Interfacing With PIC16F877A Slicker

Tags: Interfacing uart with pic16f877a, UART program using pic16f877a, uart source code for PIC, Schematics for UART, Circuit Diagram to Interface UART with PIC16F877A, C Program to display a text in PC from PIC16F877A,
Overall rating
PIC16F/18F Slicker Board

The PIC16F/18F Slicker board is specifically designed to help students to master the required skills in the area of embedded systems. The kit is designed in such way that all the possible features of the microcontroller will be easily used by the students. The kit supports in system programming (ISP) which is done through USB port.

Microchip’s PIC (PIC16F877A), PIC16F/18F Slicker Kit is proposed to smooth the progress of developing and debugging of various designs encompassing of High speed 8-bit Microcontrollers.


UART (Universal Asynchronous Receiver Transmitter) are one of the basic interfaces which provide a cost effective simple and reliable communication between one controller to another controller or between a controller and PC.

RS-232 Level Converter

Usually all the digital ICs work on TTL or CMOS voltage levels which cannot be used to communicate over RS-232 protocol. So a voltage or level converter is needed which can convert TTL to RS232 and RS232 to TTL voltage levels. The most commonly used RS-232 level converter is MAX232.

This IC includes charge pump which can generate RS232 voltage levels (-10V and +10V) from 5V power supply. It also includes two receiver and two transmitters and is capable of full-duplex UART/USART communication.

  • RS-232 communication enables point-to-point data transfer. It is commonly used in data acquisition applications, for the transfer of data between the microcontroller and a PC.

The voltage levels of a microcontroller and PC are not directly compatible with those of RS-232, a level transition buffer such as MAX232 be used.

Interfacing UART

Fig. 1 shows how to interface the UART to microcontroller. To communicate over UART or USART, we just need three basic signals which are namely, RXD (receive), TXD (transmit), GND (common ground). So to interface UART with LPC2148, we just need the basic signals.


Fig. 1 Interfacing UART to Microcontroller

Interfacing UART with PIC16F877A

We now want to display a text in PC from PIC16F/18F Slicker Board by using UART module. In PIC16F/18F Slicker Board contains two serial interfaces that are UART & UART1. Here we are using UART. The Transmitter pins send the data into PC and the receiver pin receives the data from PC. The PC and microcontroller speed are denoted by using baud rate. When the baud rates of both PC and Microcontroller are same, then only the data transmit and receive correctly otherwise not.

Pin Assignment with PIC16F877A



UART DB-9 Connector


Processor Lines

Serial Port Section






* Turn ON TXD and RXD Pins of  

    CONFIG switch SW1.

*  Connect Serial cable between USART

    Section in the Board and PC.

*  Open HyperTerminal

*  Press RESET Once (If Necessary)



Output: Type a character, same character will be returned from Board.


Circuit Diagram to Interface UART with PIC16F877A


Source Code

The Interfacing UART with PIC16F877A program is very simple and straight forward, which display a text in PC from PIC16F877A Slicker Board through UART. Some delay is occurring when a single data is sent to PC. The C programs are written in Mplab software with Hi-Tech C Compiler. The baud rate of microcontroller is 9600.

C Program to display a text in PC from PIC16F877A


Title : Program to display a text in PC from PIC16F877A through UART






#define FOSC       10000    //10Mhz==>10000Khz

#define BAUD_RATE   9.6     //9600 Baudrate

#define BAUD_VAL   (char)(FOSC/ (16 * BAUD_RATE )) - 1;       

//Calculation For 9600 Baudrate @10Mhz

void main()


   unsigned char ReceiveChar;  

   TRISC=0xc0; //RC7,RC6 set to usart mode(INPUT)

   TXSTA=0x24; //Transmit Enable

   SPBRG=BAUD_VAL; //9600 baud at 10Mhz

   RCSTA=0x90; //Usart Enable, Continus receive enable





       if (RCIF==1) //char received? Send 'A' back to Terminal



       if(TXIF==1) TXREG=ReceiveChar;







To compile the above C code you need the Mplab software & Hi-Tech C Compiler. They must be properly set up and a project with correct settings must be created in order to compile the code. To compile the above code, the C file must be added to the project.

In Mplab, you want to develop or debug the project without any hardware setup. You must compile the code for generating HEX file. In debugging Mode, you want to check the port output without PIC16F/18F Slicker Board.

The PICKIT2 software is used to download the hex file into your microcontroller IC PIC16F877A through USB port.

Testing the UART with PIC16F877A

Give +12V power supply to PIC16F/18F Slicker Board; the serial cable is connected between the PIC16F/18F Slicker Board and PC. Open the Hyper Terminal screen, select which port you are using and set the default settings. Now the screen should show some text messages.

If you are not reading any text from UART, then you just check the jumper connections & just check the serial cable is working. Otherwise you just check the code with debugging mode in Mplab. If you want to see more details about debugging just see the videos in below link.

Join the World's Largest Technical Community

we respect your privacy.