另外我这程序不知道哪里不对,显示的时间好像是乱的
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uint m=0;
sbit A1=P3^4;
sbit A2=P3^5;
uint count,t;
uchar d,e,f;
uchar code table[]={0x14,0xde,0x38,0x1a,0xd2,0x13,0x11,0x9e,0x10,0x12};
uchar code cnt[]={10000,1000,100,10,1};
void delay(void) //误差 0us
{
unsigned char a,b,c;
for(c=67;c>0;c--)
for(b=124;b>0;b--)
for(a=167;a>0;a--);
}
void start()
{
TMOD=0x01; //T0 使用工作方式 1
TH0=(65536-1000)/256; //1ms 定时
TL0=(65536-1000)%256;
EA=1;
ET0=1;
TR0=0;
}
void time0(void) interrupt 1 //T0 中断服务子程序
{
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
count++;
if(count>=1)
{count=0;
t++;
if(t>=60000)
{t=0;}
}
}
void display(uint t) //显示子程序,从第一位开始逐位显示
{
uint k=0,v;
for(;k<5;k++)
{
v=t/cnt[k]%10 ;
P0=table[v];
delay();
{for(f=23;f>0;f--)
for(e=152;e>0;e--)
for(d=70;d>0;d--)
P0=0xFF;
}
}
}
void main(void)
{ start();
while(1)
{
P0=0xb7;
P3=0x30;
if(P3!=0x30)
{if(A1==0) //按键扫描
{TR0=1;}
if(A2==0)
{
TR0=0;
while(!A2);
while(P3==0x30)
{
display(t);
}
}
}
}
}
|