#include “reg52.h” //此文件中定义了单片机的一些特殊功能寄存器
typedef unsigned int u16; //对数据类型进行声明定义
typedef unsigned char u8;
unsigned char code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff,0x88};
u8 num;
void Int0Init()
{
//设置INT0
IT0=1;//跳变沿出发方式(下降沿)
EX0=1;//打开INT0的中断允许。
EA=1;//打开总中断
}
/*******************************************************************************
- 函 数 名 : main
- 函数功能 : 主函数
- 输 入 : 无
- 输 出 : 无
*******************************************************************************/
void main()
{
Int0Init(); // 设置外部中断0
while(1)
{
P2=tab[num];
}
}
/*******************************************************************************
- 函 数 名 : Int0() interrupt 0
- 函数功能 : 外部中断0的中断函数
- 输 入 : 无
- 输 出 : 无
*******************************************************************************/
void Int0() interrupt 0 //外部中断0的中断函数
{
num++;
if(num>9) num=0;
}