#include<reg51.h>
unsigned int table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned int place[]={0x1f,0x2f,0x37,0x3b,0x3d,0x3e};
unsigned int doc[]={0x3f,0x3f,0x3f,0x3f,0x3f,0x3f};
unsigned char t=0;
unsigned int count[6]={0,0,0,0,0,0};
unsigned int k1_count=0;
void reset();
void initDoc();
void initCount();
void suspend();
void init();
void timerRun();
void t1(void);
void delay1ms(void)
{
unsigned char a,b;
for(a=199;a>0;a--)
for(b=1;b>0;b--);
}
void initDoc()
{
unsigned int i;
for(i=0;i<6;i++)
doc[i]=table[0];
}
void initCount()
{
unsigned int i;
for(i=0;i<6;i++)
count[i]=0;
}
void display()
{
unsigned int i;
for(i=0;i<6;i++)
{
P0=doc[i];
P2=place[i];
delay1ms();
delay1ms();
P0=0x00;
delay1ms();
}
}
void run()
{
unsigned char i;
if(count[0]<9)
count[0]++;
else
{
count[0]=0;
count[1]++;
if(count[1]>9)
{
count[1]=0;
count[2]++;
if(count[2]>9)
{
count[2]=0;
count[3]++;
if(count[3]>6)
{
count[3]=0;
count[4]++;
if(count[4]>9)
{
count[4]=0;
count[5]++;
if(count[5]>6)
count[5]=0;
}
}
}
}
}
for(i=0;i<6;i++)
{
doc[i]=table[count[i]];
}
}
void t1(void) interrupt 3
{
TH1=0xd8;
TL1=0xf0;;
run();
}
void int_int0(void) interrupt 0
{
if(k1_count==0)
k1_count=1;
else
k1_count=0;
}
void int_int1(void) interrupt 2
{
k1_count=2;
}
void timerRun()
{
P1=0x02;
TMOD=0x10;
TR1=1;
ET1=1;
EA=1;
while(k1_count==1)
{
display();
}
if(k1_count==0)
suspend();
if(k1_count==2)
{
reset();
}
}
void init()
{
P1=0x01;
initdoc();
IT0=1;
EA=1;
EX0=1;
IT1=1;
EX1=1;
while(k1_count==0)
{
display();
}
if(k1_count==1)
{
timerRun();
}
}
void suspend()
{
P1=0x01;
TR1=0;
while(k1_count==0)
{
display();
}
if(k1_count==1)
{
timerRun();
}
else if(k1_count==2)
{
reset();
}
}
void reset()
{
P1=0x01;
TR1=0;
initcount();
IT0=1;
EA=1;
EX0=1;
IT1=1;
EX1=1;
k1_count=0;
while(k1_count==0)
{
display();
}
if(k1_count==1)
{
timerRun();
}
if(k1_count==2)
reset();
}
void main()
{
init();
}
|