#include<htc.h>
#define _XTAL_FREQ 20e6
__CONFIG(0x3F3A);
void uart_init()
{
TRISC6=0;
TXSTA=0b00100100; //CHECK THE DATA SHEET FOR TXSTA
RCSTA=0b10010000; //SEE THE DATA SHEET FOR RCSTA
BRGH=0; // low baud rate
SPBRG=129; //baud rate 2400
}
void interrupt_enable()
{
GIE=1;
PEIE=1;
RCIE=1;
}
void txd(char write_data)
{
TXREG = write_data;
while(!TRMT);
}
void interrupt UART() //interrupt service routine
{
PORTD = RCREG; //simply to get the received ASCII on PORTD
}
main()
{
TRISD=0;
uart_init();
interrupt_enable();
txd('W');
txd('E');
txd('L');
txd('C');
txd('O');
txd('M');
txd('E'); //DISPLAY "WELCOME" at starting
while(1); //WAITING FOR INTERRUPT (SEE RESULT ON PORT D)
}