Stc12c5a60s2 single chip microcomputer uses serial port 1 to communicate, and there is confusion in both receiving and sending codes.

problem description

when I use the serial port assistant, I originally want to send when I receive 0X4a, but I can only send it when I receive 0Xaa, and it is also garbled.

the environmental background of the problems and what methods you have tried

is a problem when using serial port to communicate. It is found that only by entering aa can the sending operation be performed

related codes

/ / Please paste the code text below (do not replace the code with pictures)

< H1 > include < reg52.h > < / H1 > < H1 > define uint unsigned int < / H1 > < H1 > define uchar unsigned charu < / H1 >

char sbuf b; / an is used to fetch the value in sbuf, b is used to determine whether to send data
void UartInit ();
void shu ();
uchar hello [] = {0X48Power0X450X4cPower0X4cPower0X4cPower0X4F0X0X0a}; / / send out the text "hello!" Where 0X0d void UartInit 0X0a is a newline operation
void UartInit ()
{

TMOD=0X20;    
TH1=0Xfa; //960012M    
TL1=0Xfa;     
TR1=1;    
SCON=0X50;    
PCON|=0X80;    
EA=1;    
ES=1;

}
void shu ()
{

uchar i;    
for(i=0;i<8;iPP) 
{    
     SBUF=hello[i];    
     while(!TI); TI=0;    
}

}
void main ()
{

  P0=0X00;    
  b=0;    
  UartInit();    
  while(1)    
  { 
       if(b==1)
       {shu();b=0;}    
  }

}
void zhongduan () interrupt 4
{

 if(RI)
  {    
        RI=0;    
        a=SBUF;    
        if(a==0X4a)b=1;    
 }

}

what result do you expect? What is the error message actually seen?

I hope that when the serial assistant enters aa, the computer will display "Hello!"
however, all I received was a pile of garbled codes

C
Jul.05,2022
Menu