#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit beep=P2^4;
uchar num,num1,flag,a;
void init()
{
TMOD=0X21;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=0XFD;
TL1=0XFD;
ET1=0;
TR1=1;
SM0=0;
SM1=1;
REN=1;
EA=1;
ET0=1;
ES=1;
}
void main()
{
init();
while(1)
{
if(flag==1)//到这不时卡住了,调试后看到flag=0的
{
TR0=1;
ES=0;
switch(a)
{
case 1:num=4;break;
case 2:num=2;break;
}
ES=1;
flag=0;
}
}
}
void ser() interrupt 4
{
RI=0;
a=SBUF;
P1=SBUF;//验证串口是否能接收到数据用
flag=1;
}
void time() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num1++;
if(num1=num)
{
num1=0;
beep=~beep;
}
}
|