- This topic has 2 replies, 3 voices, and was last updated 10 years, 11 months ago by .
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.
|
Microcontroller › PIC › pic16f877a uart not working
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..
<code>
#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);
}
}
</code>
Hi Navin,
I would suggest to simplify the code by avoid the interrupt. Place that piece of code which writes into the transmit buffer inside the infinite loop of the main code and try again.
check your loop or try to use mikroC it is easier to understand..there is a library for uart…