一、题目:中断系统练习:外部中断每发生一次在数码管上显示一个数字, 且每中断一次显示的数值增1或减1 外 部中断0为增1,外部中断1为减1。
#include<reg52.h>
typedef unsigned int uint;
void delay(int x)
{
int a, b;
for(a=x; a>0; a--)
for(b=500; b>0; b--);
}
uint array[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x98};
uint m=0;
int main()
{
P0=0xff;
EA=1;
EX0=1;
IT0=1;
EX1=1;
IT1=1;
while(1);
return 0;
}
void INT_0() interrupt 0
{
EX0=0;
delay(20);
EX0=1;
if(m==10)
m=0;
else P0=array[m++];
}
void INT_1()interrupt 2
{
EX1=0;
delay(20);
EX1=1;
if(m==0)
m=10;
else P0=array[--m];
}