用动态扫描方法和定时器0在数码管的前三位显示出秒表,精确到1%秒,即后两位显示1%秒,一直循环下去。
#include<reg52.h>
#define ui unsigned int
#define uc unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
void delay(int z);
void display(uc ,uc , uc );
ui aa,fen,miao1,miao2,tt;
uc code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void main()
{
TMOD=0x01;
TH0=(65536-20000)/256;
TL0=(65536-20000)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{
display(fen ,miao1 , miao2);
}
}
void saomiao() interrupt 1
{
TH0=(65536-20000)/256;
TL0=(65536-20000)%256;
aa++;
if(aa==50)
{
aa=0;
}
tt++;
if(tt==1000)
{tt=0;}
fen=tt/100;
miao1=tt%100/10;
miao2=tt%100%10;
}
void display(uc fen,uc miao1, uc miao2)
{
dula=1;
P0=table[fen];
dula=0;
P0=0xff;//关闭段选数据的输入
wela=1;
P0=0xfe;
wela=0;
delay(1);
dula=1;
P0=table[miao1];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(1);
dula=1;
P0=table[miao2];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay(1);
}
void delay(int z)
{
int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
为什么分那位不能一秒一秒变啊 |
|