-------------------------------------------------- From: "nidhi mittal hada" Sent: Wednesday, September 08, 2010 10:32 AM To: ; Subject: PIC18F4550 rs232 communication to PC > I am a newbie to microcontroller programming I am using ccsc compiler and > written a program to communicate to PC thru RS232 interface > It uses users232 directive.just that ..and after that i wrote putc > functions. > But its not sending the character i mentioned in putc but any random > character is coming on hyperterminal .... I would turn the interrupts off if you are not using them - if you are=20 polling in a loop then you don't need them. Also if you are at 9600 baud, and you are using 20MHz crystal then it's=20 likely you are loading the Tx buffer too quickly and it may be writing to i= t=20 whilst sending the last character causing an overflow error or corrupting=20 the data. Try adding a delay between receiving and sending the character if= =20 keeping the code as it is. It might be a good idea to check if a character has been received by pollin= g=20 the interrupt flag (you don't need to have interrupts enabled to do this)=20 and only sending a character if one is received. I don't know the compiler you are using, but also check the UART and=20 Hyperterminals settings match exactly, and the *baud rate error* is=20 acceptable. You may want to consider changing over to Hi-Tech (Microchips main compiler= =20 now) or C18 compilers (Microchips "old" compiler - support will eventually= =20 die out as they are promoting Hi-Tech now) as they are far more popular and= =20 both pretty good. Something like the below code (the definition for the interrupt flag would= =20 be easier to use, I don't know what it is for your compiler though - if you= =20 want to use it you will have to check what it is defined as in your=20 compiler, or look in the datasheet for the PIC and change it over) For example in C18 it is PIR1bits.RCIF for the receive flag, it may be=20 something similar for your compiler. If it doesn't work (I haven't had much sleep so it's very possible..) then= =20 let us know, sure someone will get go going.. void main() { char c; int i =3D 0; set_tris_c(0xBF); //enable_interrupts(GLOBAL); //enable_interrupts(INT_RDA); while(TRUE) { if((PIR1 & 0b00100000) !=3D 0) // check bit 5 (RCIF) of PIR1 to see i= f=20 anything received { PIR1 &=3D 0b11011111; // clear flag (cleared by reading register= I=20 think anyway) c=3Dgetc(); //if getc() timeouts 0 is returned to c // try a short delay like the following lines (make longer if not=20 checking flag) i =3D 100; while(i > 0) i--; putc(c); } } } =20 --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .