This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Serial port Communication PC and AT89C52 ( continuted )

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;
} 
By the way,how to select AT89C52 Timer 2 Serial Clock Divisor? right now, I am sure my MCU is working correctly for receiving and sending out the data ( I did this under a friend's suggestion ). SO I thought the Serial Clock Divisor of AT89C52 is wrong.

Would you help me to check it?

Thank you.

Parents
  • 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.

Reply
  • 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.

Children
No data