本帖最后由 wuwei1029 于 2010-2-3 15:33 编辑
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit Key = P3^3;
sbit DoorBell = P2^0;
uint p = 0;
void delay(uint x)
{
uchar i;
while(x--)
{
for(i=120;i>0;i--);
}
}
void Timer0() interrupt 1
{
DoorBell = ~DoorBell;
p++;
if(p<400)
{
TH0 = (8192-700)/32;
TL0 = (8192-700)%32;
}
else if(p<800)
{
TH0 = (8192-1000)/32;
TL0 = (8192-1000)%32;
}
else
{
TR0 = 0;
P = 0;
DoorBell=1;
}
}
void main()
{
IE = 0x82;
TMOD = 0x00;
TH0 = (8192-700)/32;
TL0 = (8192-700)%32;
while(1)
{
if(Key == 0)
{
delay(5);
if(Key == 0)
{
TR0 = 1;
while(Key==0);
}
}
}
}
我的门铃程序有点问题!按键 响一下“叮咚”。再按就没声音了
好像不能进入中断了,大虾们看看哪里有问题 |