mprabu20
Newbie

Hi experts,
I am using AT89S52 microcontroller to implement a generic relay board. I am using RS232 to communicate.
when we sent data from laptop, RI interrupt is not being raised, and receive is not working. If I try only transmit its working fine. When I simulate on keil its working. But it fails on proteus simulation and on hardware. Please some one help.
Here is my code.
I am using AT89S52 microcontroller to implement a generic relay board. I am using RS232 to communicate.
when we sent data from laptop, RI interrupt is not being raised, and receive is not working. If I try only transmit its working fine. When I simulate on keil its working. But it fails on proteus simulation and on hardware. Please some one help.
Here is my code.
Code:
#include <reg51.h>
/* ---------------------------->This code is commented and working only transmission.
void main () {
SCON = 0x50;
TMOD = 0x20;
TH1 = 0xFD;
TR1 = 1;
SBUF = 'Y';
while (TI == 0);
TI = 0;
}----------------------------------Till this commented
*/
volatile bit rx_flag = 0;
volatile char rdata = 'K';
void init_serial();
void main() {
init_serial();
while ( 1 ) {
//RI = 1;
if (rx_flag == 1) {
SBUF = rdata;
while (TI == 0);
//rdata++;
TI = 0;
rx_flag = 0;
}
}
}
void init_serial() {
SCON = 0x50;
TMOD = 0x20;
TH1 = 0xFD;
TR1 = 1;
ES = 1; // Enable serial port interrupt
EA = 1; // Enable global interrupts
//P3 = 0x03;
}
void serial_isr() interrupt 4 {
if (RI) {
rdata = SBUF;
RI = 0; // Clear the receive interrupt flag
rdata++;/// = '7';
rx_flag = 1; // Set the flag to indicate that data has been received
}
}
Last edited by a moderator: