Thursday, February 4, 2016

PIC16F877A UART example

MikroC UART example for PIC16F877A
This is a small example shows how to use UART module of PIC16F877A microcontroller using mikroC compiler. Here mikroC Pro for PIC UART library will be used for more details about the UART library go to the following page: UART Library.
PIC16F877A UART connection circuit schematic:
Pins RC6 and RC7 are used for the UART (serial) communication between the microcontroller and the computer. To change between TTL and RS232 signals, an IC is needed which is max232 and its connection as shown in the following schematic:
 pic16f877a uart example mikroc code pic16f877a projects

PIC16F877A UART example mikroC code:

 /* PIC16F877A UART example
  * Used microcontroller: PIC16F877A @ 8MHz
  * Written by: BENCHEROUDA Okba
  * E-mail:
  * Website:
 char i ;
 void main() {
   UART1_Init(19200);            // Initialize USART module
                                  // (8 bit, 19200 baud rate, no parity bit...)
   UART1_Write_Text("Hello world!");
   UART1_Write(13);      // Start a new line
   UART1_Write_Text("PIC16F877A UART example");
   UART1_Write(13);     // Start a new line
   while (1) {
     if (UART1_Data_Ready()) { // If data has been received
      i = UART1_Read();     // read it
      UART1_Write(i);       // and send it back

The following video has some descriptions of the code and some tests: