#include<reg51.h>
#define TOHIGH Ox3C
#define TOLOW OxB0
sbit P3_5=P3^5;
sbit P3_0=P3^0;
sbit P3_1=P3^1;
sbit P3_3=P3^3;
sbit P3_7=P3^7;
void count(void);
void display(void);
void disp_init(void);
unsigned char i,number;
unsigned int n,len[4],sum=0;
char code table[]={OxC0,OxF9,OxA4,OxB0,Ox99,Ox92,Ox82,OxF8,Ox80,Ox90,Oxff};
void main(void)
{
disp_init();
while(1)
{ while(! P3_3){}
if(P3_3){
sum++;
while(P3_3){}
}
}
}
void count(void)
{
n=sum*20;
if(n>6000&&n<600){
len[0]=0;
len[1]=0;
len[2]=0;
len[3]=0;
}
len[0]=n/1000;
len[1]=n%1000/100;
len[2]=n%1000%100/10;
len[3]=n%10;
}
void display(void)
{
TMOD=Ox1;
TCON=Ox00;
TH0=TOHIGH;
TL0=TOLOW;
IE=Ox82;
TR0=1;
}
void system_tick(void) interrut 1
{
static unsigned char second_cnt=20;
TR0=0;
TH0=TOHIGH;
TL0=TOLOW;
second_cnt--;
if(! second_cnt)
{
count();
P3_7=0;
P3_5=1;
P3_1=1;
P3_0=1;
number=table[len[3]];
display();
P3_7=1;
P3_5=0;
P3_1=1;
P3_0=1;
number=table[len[2]];
display();
P3_7=1;
P3_5=1;
P3_1=0;
P3_0=1;
number=table[len[1]];
display();
P3_7=1;
P3_5=1;
P3_1=1;
P3_0=0;
number=table[len[0]];
display();
second_cnt=20;
sum=0;
TR0=1;
}
TR0=1;
} |