你在串口中断中应该进行一次判断是发送还是接受不然可能会产生错误
建议格式为
void Com_Service(void) interrupt 4
{
if(RI)
{
RI=0;
a=SBUF;
if(a==0xAA)
{
flag=1;
}
if(a==0xFF)
{
flag=0;
}
if(TI)
{
TI=0;
}
}
//你想在接受到)ff后停止接受,不能关闭串口中断,不然你就不能接受开始指令了,只要在接收到停止指令)0xff后将发送程序关闭即可
void main ()
{
uartinit();
EA=1;
while(1)
{
if(flag==1)
{
senstring(buffer);
} //buffer为要发送的字节数组 unsigened char型
}
{ES=0;}改成{ES=0;}