#include <reg51.h>
#define p1 P1
#define p2 P2
#define p0 P0
#define p3 P3
#define uchar unsigned char
sbit p27=P2^7;
sbit p16=P1^6;
sbit p15=P1^5;
sbit p14=P1^4;
sbit p17=P1^7;
sbit p00=P0^0;
sbit p05=P0^5;
sbit p06=P0^6;
sbit p07=P0^7;
void delay(uchar ms)
{
uchar i;
for(;ms>0;ms--)
for(i=10;i>0;i--);
}
void main(void)
{
int v1,v2,v3,v4,v5;
uchar qianwei,baiwei,shiwei,gewei,bian,dd;
uchar k,h,i,j,sec,ssec,min;
uchar bai1,shi1,ge1,b,v;
uchar qian1,bai3,shi3,ge3,e,f;
TMOD=0x61;
TH0=0x3c;
TL0=0xb0;
TH1=0X00;//设置计数初值
TL1=0X00;
TR0=1; //T0定时运行
TR1=1; //T1计数开始
ET0=0; //T0禁止中断
ET1=0; //T1禁止中断
EA=0;
while(1)
{
if(p27==0)
{
{
if(TF1==1)
{
v1++;
TF1=0;
}
//速度计算
v2=v1*256+TL1;
v4=min*60+ssec*10+sec+k/19;
v3=v2/(v4*23);
qianwei=v3/1000;
bian=v3/100;
baiwei=bian%10;
dd=v3/10;
shiwei=dd%10;
gewei=v3%10;
//计数1计数完显示
v=TL1;
bai1=v/100;//百位
ge1=v%10;//个位
b=v/10;
shi1=b%10;//十位
//计数1循环次数数字显示
v5=v1;
qian1=v5/1000;//千位
ge3=v5%10;//个位
e=v5/10;
shi3=e%10;//十位
f=e/10;
bai3=f%10;//百位
//时间计算
if(TF0==1)
{
h=0;
++k;
TH0=0x3c;
TL0=0xb0;
TF0=0;
TR0=1;
if(k==20)
{
k=0;
h=1;
}
if(h)
{ ++i;
sec=i;
if(i>9)
{ i=0;
++j;
ssec=j;
}
if(j>5)
{
j=0;
ssec=0;
min++;
}
if(min>9)
{
min=0;
}
TH0=0x3c;
TL0=0xb0;
}
}
//数码管动态扫描
//计数显示
p1=ge1;
p2=0x00;
delay(35);
p2=0x0ff;
p1=shi1;
p2=0x01;
delay(35);
p2=0x0ff;
p1=bai1;
p2=0x02;
delay(35);
p2=0x0ff;
//计数循环数字显示
p1=ge3;
p2=0x03;
delay(35);
p2=0x0ff;
p1=shi3;
p2=0x04;
delay(35);
p2=0x0ff;
p1=bai3;
p2=0x05;
delay(35);
p2=0x0ff;
p1=qian1;
p2=0x06;
delay(35);
p2=0x0ff;
}
//定时显示
p0=sec;
p05=0;
delay(35);
p05=1;
p0=ssec;
p06=0;
delay(35);
p06=1;
p0=min;
p07=0;
delay(35);
p07=1;
//速度显示
p3=gewei;
p14=0;
delay(35);
p14=1;
p3=shiwei;
p15=0;
delay(35);
p15=1;
p3=baiwei;
p16=0;
delay(35);
p16=1;
p3=qianwei;
p17=0;
delay(35);
p17=1;
}
else
{
TR0=0;
TR1=0;
//时间显示
p0=sec;
p05=0;
delay(10);
p05=1;
p0=ssec;
p06=0;
delay(10);
p06=1;
p0=min;
p07=0;
delay(10);
p07=1;
//速度扫描显示
p3=gewei;
p14=0;
delay(35);
p14=1;
p3=shiwei;
p15=0;
delay(35);
p15=1;
p3=baiwei;
p16=0;
delay(35);
p16=1;
p3=qianwei;
p17=0;
delay(35);
p17=1;
//计数显示
p1=ge1;
p2=0x00;
delay(35);
p2=0x0ff;
p1=shi1;
p2=0x01;
delay(35);
p2=0x0ff;
p1=bai1;
p2=0x02;
delay(35);
p2=0x0ff;
//计数循环数字显示
p1=ge3;
p2=0x03;
delay(35);
p2=0x0ff;
p1=shi3;
p2=0x04;
delay(35);
p2=0x0ff;
p1=bai3;
p2=0x05;
delay(35);
p2=0x0ff;
p1=qian1;
p2=0x06;
delay(35);
p2=0x0ff;
}
}
}