|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2011-2-13 10:21:36
|
显示全部楼层
这是现在写的程序
#include<reg51.h>
unsigned char code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
0x80,0x90};
unsigned int s,fen;
delay(unsigned int x)
{
for(;x>0;x--);
}
void TimerInit()
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void disp()
{
P0=0xff;
P2=duan[s%10];
P0=0xfe;
delay(100);
P0=0xff;
P2=duan[s/10];
P0=0xfd;
delay(100);
P0=0xff;
P2=duan[fen%10];
P0=0xfb;
delay(100);
P0=0xff;
P2=duan[fen/10];
P0=0xf7;
delay(100);
}
void main()
{
fen=12; // 初始化
s=0;
TimerInit();
while(1)
{
disp();
}
}
void Timer0() interrupt 1
{
static unsigned char count = 0;
count++;
if(count==20) // 1s
{
count=0;
s++;
}
if(s==60)
{
s=0;
fen++;
}
if(fen==60)
{
fen=0;
}
TL0 =(65536-50000) % 256;
TH0 =(65536-50000) / 256
} |
|