#include<reg51.h>
#define SEG7P P1
#define SCANP P2
char code TAB[10]={0xc0, 0xf9, 0xa4, 0xb0, 0x99,
0x92, 0x83, 0xf8, 0x80, 0x98 };
char disp[4]={0,0,0,0};
void delay_ms(int x);
char scan[4]={0xfe,0xfd,0xfb,0xf7};
char i,j;
void display();
int show=0000;
void get_disp();
main()
{
IE=0X85;
TCON=0X05;
while(1)
{
get_disp();
display();
}
}
void delay_ms(int x)
{ int i,j;
for (i=0;i<x;i++)
for (j=0;j<120;j++);
}
void display()
{
for(i=0;i<4;i++)
{ j=disp[3-i];
SCANP=scan[i];
SEG7P=TAB[j];
delay_ms(4);
}
}
void INT0_ISR(void) interrupt 0
{
if(show<9999)
show++;
else show=0;
}
void_INT1_ISR(void) interrupt 2
{
if(show>0)
show--;
else show=9999;
}
void get_disp ()
{
disp[0]=show/1000;
disp[1]=show%1000/100;
disp[2]=show%100/10;
disp[3]=show%10;
}
评论0