Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
11/24/04 10:03
Read: times


 
#81816 - mistakes
Responding to: ???'s previous message
hi,

here are some errors I see from the first look at your code:

- Error with TI flag at transmitter side
void Serial_Init(void) 
{ 
SCON=0x52; 
//...
//...
void Transmit_Char(unsigned char c) 
{ 
SBUF=c; 
while(!TI){} //Waits until transmit
//...
When you load SCON with 0x52, you do set TI flag. As result, wait loop in transmit routine has no sense. In fact, your program transmit only one char so it is not actual problem but it will come up when you try to send next byte(s). Modify it to:
void Transmit_Char(unsigned char c) 
{ 
while(!TI){} //Waits until transmit
TI=0; 
SBUF=c; 
}
- At receiver side:
You do set TI flag as well with SCON=0x52; but your interrupt routine has no code for this case. Should be:
void call() interrupt 4 
{ 
if(RI) 
{ 
   P1=SBUF; 
   RI=0; 
}
if (TI)
   TI=0; 
}

The main error I see is that you allow serial interrupt at transmitter side (EA=1; ES=1;) but you have not interrupt service routine there! As I already said, when you do SCON=0x52; then you set bit TI. This bit causes interrupt routine to be called after serial interrupt allowed. As result, program comes to serial interrupt service routine vector and then goes to undefined bahaviour because you have not programmed ISR. Either disable serial interrupt at transmitter side or implement transmit function inside serial interrupt service routine.

Regards,
Oleg


List of 14 messages in thread
TopicAuthorDate
AT89c51 serial communication problem            01/01/70 00:00      
   Try            01/01/70 00:00      
   While loop in Transmit Char function            01/01/70 00:00      
   mistakes            01/01/70 00:00      
      mistakes fixed but still in a fix            01/01/70 00:00      
         too more fix            01/01/70 00:00      
   Give little more details            01/01/70 00:00      
      more details            01/01/70 00:00      
   problem solved            01/01/70 00:00      
      answer wrong            01/01/70 00:00      
   Yet another problem you must fix.            01/01/70 00:00      
      Hex files needed            01/01/70 00:00      
      Check The serial port            01/01/70 00:00      
         Problem solved            01/01/70 00:00      

Back to Subject List