#include "STC/STC15F2K60S2.H"
#define uchar unsigned char
sbit K=P3^2;
sbit BELL=P4^5;
sbit Relay=P5^5;
//延迟
void delay02s(void)
{
uchar i,t=200;
while(t--)
for(i = 150;i > 0;i--);
}
void main (void)
{
EA=1;
EX0=1;
IT0=1;
while(1)
{
P0=0xfe;
delay02s();
P0=0xff;
delay02s();
}
}
//中断
void int0() interrupt 0
{
while(!K)
{
P0= 0xfd;
BELL = 0;
Relay = 0;
}
P0= 0xff;
BELL = 1;
Relay = 1;
}
单片机外部中断应用
最新推荐文章于 2024-01-15 19:53:22 发布