PIC16F877A-HITECH C – UART

Photo of author

By Jackson Taylor

Transmission
#include<pic.h>
#define _XTAL_FREQ 16000000 void main() { SPEN=1; //enables serial port SYNC=0; //setting in asynchronous mode BRGH=0; //selects low speed baud rate SPBRG=25; //setting baud rate @ 9600 TXEN=1; //enables transmission TX9=0; //sets transmission in 8-bit mode while(1) { if(TRMT==1) //check status of transmit shift register status for empty { TXREG=’A’; // writes ascii value of letter A } } }
Reception
Note– i have used PORTB to see incoming ascii value
#include<pic.h>
#define _XTAL_FREQ 16000000
void main()
{
SPEN=1; //enables serial port
SYNC=0; //setting in asynchronous mode
BRGH=0; //selects low speed baud rate
SPBRG=25; //setting baud rate @ 9600
CREN=1; //enables reception
RX9=0; //sets reception in 8-bit mode
TRISB=0;
PORTB=0;
while(1)
{
PORTB=(RCREG-0x30); // writes ascii value of letter A
}
}
see software UART at http://jimmyjosep.blogspot.in/2013/11/under-standing-uartsoft.html