I downloaded AT89C51ED2 UART source code from ATMEL web. when I connected from PC COM1 to AT89C51ED2 and sended a byte data, it sended a wrong byte data back. Have some solutions about this @@?
I use C51 UART Mode1 Timer1 (24 KB, updated 06/04) 9600bps later PS. using 115200 in "3.C51 UART Mode1 Timer2" which is it? software setting it that send a byte one by one. thus you have changed something. if you are running 115k you need be careful that the processing is not too slow Erik
because the example (3.C51 UART Mode1 Timer2) says: RCAP2H=0xFF; /* reload value, 115200 Bds at 11.059MHz */ RCAP2L=0xFD; /* reload value, 115200 Bds at 11.059MHz */ so, i changed my baudrate in this case. but have the same result....>_<
1) show by cut and paste the exact code you use 2) are you sure your crystal is fundamental? 3) do you have (access to) a scope? erik
1) actually, i didnt modify source code that download from ATMEL's website. #include "reg_c51.h" char uart_data; void main (void) { SCON = 0x50; /* uart in mode 1 (8 bit), REN=1 */ TMOD = TMOD | 0x20 ; /* Timer 1 in mode 2 */ TH1 = 0xFD; /* 9600 Bds at 11.059MHz */ TL1 = 0xFD; /* 9600 Bds at 11.059MHz */ ES = 1; /* Enable serial interrupt */ EA = 1; /* Enable global interrupt */ TR1 = 1; /* Timer 1 run */ while(1); /* endless */ } void serial_IT(void) interrupt 4 { if (RI == 1) { /* if reception occur */ RI = 0; /* clear reception flag for next reception */ uart_data = SBUF; /* Read receive data */ SBUF = uart_data; /* Send back same data on uart*/ } else TI = 0; /* if emission occur */ /* clear emission flag for next emission*/ } 2) there are a 11.0592MHz mark on the crystal. I can programming with ISP in this development kit board. So, I think the crystal is fine. 3) scope? you mean the oscilloscope figure? if this is, i dont have one. (i have no money to buy one...sorry) Regard.
hmm.... is 11.059MHz same with 11.0592MHz?
"is 11.059MHz same with 11.0592MHz?" The reload value shown is correct for 11.0592MHz. Are you absolutaly certain you aren't using a 12MHz crystal?
I can programming with ISP in this development kit board. So, I think the crystal is fine. The ISP probably autobauds, so "any" crystal will be fine. is 11.059MHz same with 11.0592MHz close enough the code looks Ok, just for kicks try changing void serial_IT(void) interrupt 4 to void serial_IT(void) interrupt 4 using 1 All I can see is OK. Do you have something else that has a 232 connector on it? If so, try working out hyperterminal seetings. Erik
hi erik "void serial_IT(void) interrupt 4 using 1" why use this "using 1"? can I ask for why? that is nothing on the rs232 connector. Hyperterminal seetings....i will try it. and another question, can I use 11.0592Mhz crystal? because code says it is using 11.059MHz. Regard. Yu-Hung Hsiao
"void serial_IT(void) interrupt 4 using 1" why use this "using 1"? can I ask for why? It makes the compiler use another register stack for the ISR. and another question, can I use 11.0592Mhz crystal? because code says it is using 11.059MHz. who wrote the code was a bit lazy, and dis not include the last digit, the "correct" crystal is 11.0592 Erik