uart pic error

Status
Not open for further replies.

neelam29

New Member
hi all
m designing a project in which i m using 2 pic controllers 16f688 and making them coomunicate using uart. the code runs well in the starting.but as i go on adding more varaibles and functions in the code the communication stops.what might be the error?
waiting for kind reply

Code:
//PROGRAMM FOR rs232 communication//// PROCESSOR : PIC16F688// CLOCK : 20MHz, EXTERNAL// SPEED : 9600 bps(1bit=104us) 
#include <pic.h> 
__CONFIG(WDTDIS & MCLREN & BORDIS & HS & PWRTEN & FCMDIS & IESODIS) ; 
unsigned char ch; 
void InitUsart(void) { 
// TX Pin - output
TRISC4 = 0; 
// RX Pin - inputT
RISC5 = 1; 
// RX Setting, 8bit, enable receive,
RCSTA = 0x90; 
// TX Setting, 8bit, Asinchronius mode, High speed
TXSTA = 0x24; 
// Baudcontrol - disable auto mode, 8bit baudrate
BAUDCTL = 0x00; 
// Set Baudrade - 9600 (from datasheet baudrade table)
SPBRG = 129;
} 
void WriteByte(unsigned char byte) { 
while(!TXIF); 
TXREG = byte;
} 
unsigned char ReadByte(void) { 
while(!RCIF); 
return RCREG; 
} 
// main functionvoid 
main( void ) { 
// Init Interface
InitUsart(); 
while(1) { ch = ReadByte(); //wait to receive character
WriteByte(ch); //send it back followed by “*”
WriteByte('*');
}
} 
[code]
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…