做的作业,题目如图:
下面是程序,想先写一个一种频率的,可写出来后发现蜂鸣器应该是常响的,然后停一会,再常响,可是在响的时候是很规律间歇性的响,求大神帮忙看看是哪里出错了
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
uint aa,d2,d3;
uchar bb,d1,d4;
sbit P2_0=P2^0;
void main()
{
aa=0;
d3=0xfe;
P2_0=1;
d1=0;
TMOD=0x11;
TH0=(65536-50)/256;
TL0=(65536-50)%256;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
EA=1;
ET0=1;
ET1=1;
PT1=1;
PT0=0;
TR1=1;
TR0=1;
while(1)
{
if(aa==seg[d4])
{
P2_0=~P2_0;
aa=0;
}
}
}
void T0led()interrupt 1
{
TH0=(65536-50)/256;
TL0=(65536-50)%256;
aa++;
}
void T1led()interrupt 3
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
bb++;
d1++;
if(bb==20)
{
d4++;
}
if(d1==26)
{
if(d4==7)
{
d4=1;
}
d1=0;
bb=0;
}
}
-
一周热门 更多>