#include <reg51.h>
#include <intrins.h>
char temp;
bit flag;
void ser() interrupt 4
{
RI=0;
temp=SBUF;
flag=1;
}
void serinit()
{
TMOD=0x20;
TH1=0xfd;
TL1=0xfd; //set baud rate 9600
SM0=0;
SM1=1;
REN=1;
TR1=1;
ES=1;
EA=1;
}
{ void main()
{
serinit();
while(1)
{
if(flag==1) // Determine if reception is complete
{
flag=0;
ES=0; // Serial interrupt shutdown
SBUF=temp; // give the originally sent value to the buffer (receive and send are the same, but have different meanings)
while(!TI); // determine if the send is complete
TI=0; // if yes, hardware clear 0
ES=1; // turn on the serial interrupt again
}
}
}