51單片機(jī)中斷方式(已消抖)
#define uint unsigned int
#define uchar unsigned char
uchar flag,p;
sbit l5=P0^4;
sbit beep=P3^4;
uchar scan_key(void)
{
uchar temp;
temp=P0;
return temp;
}
void delay(uint k)
{
uint i,j;
for(i=0;i
for(j=0;j<121;j++)
{;}
}
}
void init() interrupt 0
{
EX0=0;
delay(1);
if(l5==0) //s1是外部中斷對(duì)應(yīng)的IO口
{
beep=~beep;
}
while(!l5);
EX0=1;//開(kāi)外部中斷
}
void main(void)
{
TMOD=0x01;
EX0=1; //開(kāi)外部中斷 0
IT0=0; //設(shè)置成 低電平觸發(fā)方式
EA=1;
p=0;
beep=0;
while(1)
{
delay(3);
}
}
評(píng)論