外部中断0控制报警器发声,按键按下,喇叭响。按键放开,喇叭停止响,程序经学习板测试。图一为500Hz--150ms的信号波形,图二为1KHz--250ms的信号波形。
#include"reg51.h"
#include"intrins.h"
#define uchar unsigned char
uchar count;
bit flag;
sbit BEEP=P3^7;
void delay500()
{
uchar i;
for(i=250;i>0;i--)
{
_nop_();
}
}
void main()
{
EA=1;
EX0=1;
while(1);
{
}
}
void timer() interrupt 0
{
for(count=150;count>0;count--)
{
BEEP=~BEEP;
delay500();
}
for(count=250;count>0;count--)
{
BEEP=~BEEP;
delay500();
delay500();
}
}


