pic16f877a uart not working
Discussion in "PIC Microcontroller Discussion" started by navintiwari08 Mar 24, 2014.
Mon Mar 24 2014, 02:04 am
hello there!
I'm trying to communicate with PC using pic16f877a's uart.. I've written a code in HITECH C.. but it doesn't seem to work.. pls help.. I'm using 20 MHz crystal and 9600 bauds..
the code is given below..
I'm trying to communicate with PC using pic16f877a's uart.. I've written a code in HITECH C.. but it doesn't seem to work.. pls help.. I'm using 20 MHz crystal and 9600 bauds..
the code is given below..
#include <htc.h> #define _XTAL_FREQ 20000000 __CONFIG(FOSC_HS&LVP_OFF&CP_OFF&BOREN_OFF&PWRTE_OFF&WRT_OFF&WDTE_OFF); unsigned char x; void main() { TRISC6 = 1; TRISC7 = 1; BRGH = 1; SYNC = 0; SPEN = 1; SPBRG = 129; //9600 baud with 20MHz TXIE = 1; RCIE = 1; GIE = 1; PEIE = 1; CREN = 1; TXEN = 1; while(1); } void interrupt ISR(void) { if(RCIE && RCIF) { x = RCREG; if(TXIF) TXREG = x; __delay_ms(100); } }
[ Edited Mon Mar 24 2014, 02:12 am ]
Wed Mar 26 2014, 11:37 am
are you getting atleast 1 byte? or not?
and.. if you are not servicing tx interrupt then do not enable TXIE (TXIE = 1; )
and.. if you are not servicing tx interrupt then do not enable TXIE (TXIE = 1; )
Powered by e107 Forum System