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; }