#51 为什么中断程序中只有KEY3有用
#include "reg52.h"
typedef unsigned int u16; //对系统默认数据类型进行重定义
typedef unsigned char u8;
//定义LED1管脚
sbit LED1=P2^0;
//定义独立按键控制脚
sbit KEY1=P3^1;
sbit KEY2=P3^0 ;
sbit KEY3=P3^2;
sbit KEY4=P3^3;
#define SMG_A_DP_PORT P0 //使用宏定义数码管段码口
//共阴极数码管显示0~F的段码数据
u8 gsmg_code[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
/*******************************************************************************
* 函 数 名 : delay_10us
* 函数功能 : 延时函数,ten_us=1时,大约延时10us
* 输 入 : ten_us
* 输 出 : 无
*******************************************************************************/
void delay_10us(u16 ten_us)
{
while(ten_us--);
}
void main()
{
IT0=1;//跳变沿触发方式(下降沿)
EX0=1;//打开INT0的中断允许
EA=1;//打开总中断
while(1)
{
}
}
void exti0() interrupt 0 //外部中断0中断函数
{
delay_10us(1000);//消斗
if(KEY1==0)//判断按键是否按下
SMG_A_DP_PORT=gsmg_code[0];//将数组第1个数据赋值给数码管段选口
if(KEY2==0)
SMG_A_DP_PORT=gsmg_code[1];
if(KEY3==0)
SMG_A_DP_PORT=gsmg_code[2];
if(KEY4==0)
SMG_A_DP_PORT=gsmg_code[3];
}
```