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 @@?
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
Check whether X2 in CKCON0 is being set via either the Hardware Security Byte or any post-reset startup code.
before doing what Dan suggest, try setting hyperterminal for 19k2. if that works, Dan is on the right track. Erik
Oh My God.... It is work correctly when I using 19200 baudrate..... why??? It is different from code comment. I have no idea about that.... However... Thanks for erik ,Stefan and Dan. Regard. Yu-hung Hsiao
because it is in X2 mode? so it is 6 clock periods per peripheral clock cycle. then 9600 x 2 = 19200...?
then 9600 x 2 = 19200...? Why the question mark? I thought Chinese math was the same as ours :) Anyhow, you need to dig out the datasheet for your chip and pore over the multple references to 6 clock mode. I have never, and never will again, use an Atmel chip, but the similar Philips chip has all kinds of settings for what runs by which clock (x12 or x6). You can not work with '51 chips and be ignorant of the architecture of the chip. Erik i get the impression that you are new to the '51 in which case you will need to faniliarize yourself with "the bible" here are the links to "the bible" Chapter 1 http://www.semiconductors.philips.com/acrobat/various/80C51_FAM_ARCH_1.pdf chapter 2 http://www.semiconductors.philips.com/acrobat/various/80C51_FAM_PROG_GUIDE_1.pdf chapter 3 http://www.semiconductors.philips.com/acrobat/various/80C51_FAM_HARDWARE_1.pdf
grammatical correction: I have never, and never will again, use an Atmel chip should, of course be I have once, and never will again, usa an Atmel chip. I am so adamant on the "never" that is slipped in. Erik
Shock!!! How do you know where am i? hmm....I didnt seen any infomation in this web. :) (include ip address) you are right!! i am a beginner in '51. i will download the bible and try to be familiar with '51. thanks a lot.