我写的STC89C52的利用定时器1在六位数码管前三位显示秒表。精确到0.01秒,你可以参考下,改下IO口。不知道你的硬件设计只能给予程序参考。
#include
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
uchar code tabledu[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};//段选编码表
uchar code tablewe[]={
0xfe,0xfd,0xfb,
0xf7,0xef,0xdf}; //位选编码表
void delay();
void inti();
uint temp;
display(temp);
void main()
{
inti();
while(1)
{
display(temp);
}
}
void inti()
{
temp=0;
TMOD=0x10;
TH1=(65536-10000)/256;
TL1=(65536-10000)%256;
EA=1;
ET1=1;
TR1=1;
}
void timer1() interrupt 3
{
TH1=(65536-10000)/256;
TL1=(65536-10000)%256;
temp++;
if(temp==999)
temp=0;
}
display(x)
{
uchar bai,shi,ge;
bai=x/100;
shi=x%100/10;
ge=x%10;
wela=1;
P0=tablewe[2];
wela=0;
dula=1;
P0=tabledu[ge];
dula=0;
delay();
P0=0xff;
wela=1;
P0=tablewe[1];
wela=0;
dula=1;
P0=tabledu[shi];
dula=0;
delay();
P0=0xff;
wela=1;
P0=tablewe[0];
wela=0;
dula=1;
P0=tabledu[bai];
dula=0;
delay();
}
void delay()
{
uint i,j;
for(i=1;i>0;i--)
for(j=110;j>0;j--);
}