#include#define uchar unsigned char
#define uint unsigned int
#define SYSCLK 11059200
uintBAUDRATE;
uchar flag,a;
unsigned char flag_on;
void main()
{
SCON=0x50;
TMOD=0x20;
TH1=0xfd;
TL1=0xfd;
TR1=1;
EA=1;
ES=1;
while(1)
{
if(flag==1)
{
flag=0;//标志位清0
ES=0;
TI=1;
switch(flag_on)
{
case 0: BAUDRATE=4800;
TH1=-SYSCLK/BAUDRATE/32/12;
TL1=-SYSCLK/BAUDRATE/32/12;
printf("baudrate is %d\n",BAUDRATE);
break;
case 1: BAUDRATE=9600;
TH1=-SYSCLK/BAUDRATE/32/12;
TL1=-SYSCLK/BAUDRATE/32/12;
printf("baudrate is %d\n",BAUDRATE);
break;
case 2: BAUDRATE=19200;
TH1=-SYSCLK/BAUDRATE/32/12;
TL1=-SYSCLK/BAUDRATE/32/12;
printf("baudrate is %d\n",BAUDRATE);
break;
}
while(!TI);
TI=0;
ES=1;
}
}
}
void ser() interrupt 4
{
RI=0;
a=SBUF;
flag=1;
if(a==1)
flag_on=0;
else if(a==2)
flag_on=1;
else
flag_on=2;
}
这个是错的请朋友们帮修改下!