中断程序
时间:10-02
整理:3721RD
点击:
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar num;
uchar code table[ ]= {0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90};
void delayms(xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void display(num)
{
uchar bai,shi,ge;
bai=num/100;
shi=num%100/10;
ge=num%10;
P0=table[bai];
P2=0xfb;
delayms(5);
P0=table[shi];
P2=0xfd;
delayms(5);
P0=table[ge];
P2=0xfe;
delayms(5);
}
void main()
{
IT0=0;
EA=1;
EX1=1;
EX0=1;
while(1)
{ display(num);
}
}
void inter()interrupt 0
{ unsigned char x;
EX0=0;
num++;
if(num==256)
num=0;
for(x=0;x<20;x++)
{display(num);}
EX0=1;
}
void inter1()interrupt 2
{ unsigned char x;
EX1=0;
num--;
if(num==0)
num=256;
for(x=0;x<20;x++)
{display(num);}
EX1=1;
}
#define uchar unsigned char
#define uint unsigned int
uchar num;
uchar code table[ ]= {0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90};
void delayms(xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void display(num)
{
uchar bai,shi,ge;
bai=num/100;
shi=num%100/10;
ge=num%10;
P0=table[bai];
P2=0xfb;
delayms(5);
P0=table[shi];
P2=0xfd;
delayms(5);
P0=table[ge];
P2=0xfe;
delayms(5);
}
void main()
{
IT0=0;
EA=1;
EX1=1;
EX0=1;
while(1)
{ display(num);
}
}
void inter()interrupt 0
{ unsigned char x;
EX0=0;
num++;
if(num==256)
num=0;
for(x=0;x<20;x++)
{display(num);}
EX0=1;
}
void inter1()interrupt 2
{ unsigned char x;
EX1=0;
num--;
if(num==0)
num=256;
for(x=0;x<20;x++)
{display(num);}
EX1=1;
}