C51代码最终调试版本
0赞
#include <at89x52.h>
bit flag=0;
unsigned char ch;
void send(unsigned char b)
{
TI=1;
SBUF=b;
while(TI==0);
TI=0;
}
//串口接收中断函数
void serial() interrupt 4 using 3
{
if(RI)
{
ch=SBUF;
while(RI==0);
RI = 0;
flag=1;
}
}
main()
{
//unsigned char ch;
SCON = 0x50; //SCON: serail mode 1, 8-bit UART, enable ucvr
TMOD |= 0x20; //TMOD: timer 1, mode 2, 8-bit reload
PCON |= 0x00; //SMOD=0;
TH1 = 0xFD; //Baud:9600 fosc=11.0592MHz
//TH1 = 0xFA; //Baud:4800 fosc=11.0592MHz
IE |= 0x90; //Enable Serial Interrupt
TR1 = 1; // timer 1 run*/
while(1)
{
if(flag==1)
{
flag=0;
switch(ch)
{
case '1':
send('a');
break;
case '2':
send('b');
break;
default:
send('o');
break;
}
}
}
}
我自己用VC6.0写的串口调试助手Comm.exe,绿色软件无需安装,可以满足基本需要。提供下载:http://202.38.64.10/~cgp/Comm.exe
