Discussion in "PIC Microcontroller Discussion" started by    navintiwari08    Mar 24, 2014.
Mon Mar 24 2014, 02:04 am
#1
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..
#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
#2
are you getting atleast 1 byte? or not?

and.. if you are not servicing tx interrupt then do not enable TXIE (TXIE = 1; )

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

ChrisLub
Tue Apr 23 2024, 05:21 pm
Davidbab
Tue Apr 23 2024, 10:41 am
Richardrit
Tue Apr 23 2024, 09:54 am
HenryLaf
Mon Apr 22 2024, 03:50 pm
bleradrar
Mon Apr 22 2024, 06:38 am
ppu-pro_ka
Sun Apr 21 2024, 07:39 pm
Infewow
Sun Apr 21 2024, 06:30 pm
HumanTak
Sun Apr 21 2024, 12:26 pm