Here was my plan to realize the communication between PC and AT89C52, Both of them are set to 2400 (baud rate), N, 8, 1. 1. I have shortened pin 2 and pin 3 of RS-232 attached to PC. When my pc was sending out DATA, at the same time it can receive this DATA. After doing this, I found my PC can correctly receive the DATA just sent out. 2. The following is my C51 code. After receiving the incoming data, I want to show that data by LED connected to P1 port. I thought my C51 code should be wrong, but I really have no idea……Please help me…. Sincere Thanks in advance.
unsigned char ISRIN; unsigned char ISROUT; unsigned char SERIALISRIN; void DELAY (); void INI_SERIAL(); unsigned char RECE_SERIAL (); void main () { unsigned char DATD; P1 = 0xff; INI_SERIAL(); While(1) { if (ISRIN ) { ISRIN = 0; DATD = RECE_SERIAL (); } } } void SERIAL_ISR ( ) interrupt 4 using 1 ( if ( TI ) { TI = 0 ; ISROUT = 1; } if ( RI ) { RI = 0; ISRIN = 1; } } void INI_SERIAL() { EA = 0; T2CON = 0x34; RCAP2L = 0x64; RCAP2H = 0xff; TL2 = 0x64; TH2 = 0xff; SCON= 0x50; TI = 0; RI = 0; TR2 = 1; ES= 1; EA =1; } unsigned char RECE_SERIAL () { unsigned char DAT; P1 = SBUF; DAT = P1; DELAY (); P1 = 0xff; return DAT; }
You now have 3 threads on the same subject and, since I do not know which one to naswer in, I shall not answer. In your previous duplicate it was clearly stated by someone "do not start a new thread" and if you can not read, what good does it do to answer you? Erik
Maybe this helps: http://www.keil.com/c51/baudrate.asp
So sorry about that. Since Andrew Neil want to correct them and I do not my question to sink, I have to start a new thread. Please me here... Thank you so much.
So sorry about that. Since Andrew Neil want me to correct them and I do not want my question to sink, I have to start a new thread. Please help me here... Thank you so much.
Your question will not "sink" as long as you keep up the dialog by clarifying the issues for those seeking to help you, by posting well formatted code (which you have now done), and by sharing what you have done thus far that has not worked. If the solution is not blatantly obvious, those that help you here have no choice but to iterate you toward your solution. Show progress and they (likely) will too.
"1. I have shortened pin 2 and pin 3 of RS-232 attached to PC. When my pc was sending out DATA, at the same time it can receive this DATA." What this demonstrates is that the data from the PC is correctly reaching your micro's RX pin, and the data from your micro's TX pin is correctly reaching the PC. This is purely a hardware test to demonstrate that your cable(s), RS232 transceivers, and PCB wiring are intact. Note that this test would "pass" if your PCB wiring had the micro's RX and TX pins transposed. Note that this test would also "pass" if your PC COM: port was set to some totally wrong configuration (baud rate, data bits, parity, etc). The next thing to test would be that you can correctly transmit something from the micro to the PC. The easiest way to do this would be to use the standard "hello, world" example that ships with the Keil tools. The example includes setting up the UART and baud rate generator.
What does your DELAY() function do? As an aside, note that ALL-UPPERCASE is conventionally reserved for #defined symbols in 'C'.
What DELAY () does is to help me to check the received data by showing them on P1 port. I have done following steps to check my MCU and PC: 1. Shorten Pin 11 and Pin 12 of MAX232, I am sure PC can receive the sent data correctly. 2. Shorten P3.0 and Pin 3.1 of AT89C52, I am sure AT89C52 can receive the sent data correctly. Based on above tests, I think the setting of baud rate for AT89C52 is wrong, but according to the baud rate calculator posted on this website, my setting for 2400 bits using timer2 should be right. Only one thing I am confused is how to select the Serial Clock Divisor of AT89C52 Timer 2 (should be 32 or…?).