#include <reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit SPK = P3^7;
uchar FRQ = 0x00;
void Delayms(uint ms)
{
uchar i;
while(ms--)
{
for(i=0;i<120;i++);
}
}
void main()
{
P2 = 0x00;
TMOD = 0x11;//两个16bit定时器全开
TH0 = 0x00;
TL0 = 0xff;
IT0 = 1;
IE = 0x8b;//10001011三个中断被允许
IP = 0x01;//外部中断0优先级最高
TR0 = 0;
TR1 = 0;
while(1)
{
FRQ++;
Delayms(1);
}
}
void EX0_INT() interrupt 0
{
TR0 = !TR0;
TR1 = !TR1;
if(P2 == 0x00)//当前状态决定了按键的作用
P2 = 0xe0;//同时亮3个
else
P2 = 0x00;
}
void T0_INT() interrupt 1//响铃
{
TH0 = 0xfe;
TL0 = FRQ;//随时间增加(中断加快,频率提高,声调变高),之后溢出
SPK = ~SPK;
}
void T1_INT() interrupt 3//亮灯
{
TH0 = -45000/256;
TL0 = -45000%256;
P2 = _crol_(P2,1);
}