#include<reg52.h>
typedef unsigned int u16;
typedef unsigned char u8;
sbit key = P3^2;//
sbit led = P1^0;//
//延时函数
void delay(u16 num)
{
u16 x,y;
for (x=num; x>0; x--)
for (y=110; y>0; y--);
}
int main (void)
{
TCON |= 0x01;//配置寄存器
IE = 0x81;
while(1)
{
;
}
}
//设置中断 入口地址0
void ext_int0 (void) interrupt 0
{
//延时10ms
delay(10);
//检查key 还是为0 也就是真的被按下了
if (key == 0)
{
led = ~led;
}
while(!key);
}