目标:外部中断0实现led闪烁
#include<reg52.h>
typedef unsigned int u16;
typedef unsigned char u8;
sbit k3 = P3^2; //独立按键,连接外部中断0
sbit led = P2^0;
void delay(u16 i)
{
while(i--);
}
void Int0_init() //提前把外部中断0的参数准备好
{
EA = 1;
IT0 = 1;
EX0 = 1;
}
void main()
{
Int0_init();
while(1);
}
void INT0() interrupt 0
{
delay(1000);
if(k3==0){ //按键按下
led = ~led; //led取反
}
}