哪位大神帮我看看这些代码
时间:10-02
整理:3721RD
点击:
为了实现1.由上位机发送1给单片机时,蜂鸣器以400ms频率发声,发2时以200ms频率发声,发3时以100ms频率发声,发4时关闲蜂鸣器
#include<reg52.h>
#define uchar unsigned char
uchar a,b,c,flag;
sbit beep=P2^3;
void main()
{
TMOD=0x21;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=0xfd;
TL1=0xfd;
EA=1;
ES=1;
TR1=1;
SM0=0;
SM1=1;
REN=1;
ET0=1;
while(1)
{
if(flag==1)
{
flag=0;
if(a==c)
{
a=0;
beep=~beep;
}
}
}
}
void Timer1() interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
a++;
}
void ser() interrupt 4
{
RI=0;
flag=1;
b=SBUF;
switch(b)
{
case 1:c=8;break;
case 2:c=4;break;
case 3:c=2;break;
case 4:beep=1;break;
}
}
#include<reg52.h>
#define uchar unsigned char
uchar a,b,c,flag;
sbit beep=P2^3;
void main()
{
TMOD=0x21;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=0xfd;
TL1=0xfd;
EA=1;
ES=1;
TR1=1;
SM0=0;
SM1=1;
REN=1;
ET0=1;
while(1)
{
if(flag==1)
{
flag=0;
if(a==c)
{
a=0;
beep=~beep;
}
}
}
}
void Timer1() interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
a++;
}
void ser() interrupt 4
{
RI=0;
flag=1;
b=SBUF;
switch(b)
{
case 1:c=8;break;
case 2:c=4;break;
case 3:c=2;break;
case 4:beep=1;break;
}
}