man1234567 发表于 2021-7-27 07:54
贴上原代码很困难么
#include<reg52.h>
#define uint unsigned int;
#define uchar unsigned char;
uchar tt,num,ge,shi,bai;
sbit wei=P2^7;
sbit zi=P2^6;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void init();
void xianshi(uchar bai,shi,ge);
void delay(uint z);
void main()
{
init();
while(1)
{
if(tt==20)
{
tt=0;
num++;
if(num==100)
{
num=0;
}
bai=num/100;
shi=num%100/10;
ge=num%10;
}
xianshi(uchar bai,shi,ge);
}
}
void delay(uint z)
{
uint x,y;
for(x=110;x>0;x--)
for(y=z;y>0;y--);
}
void init()
{
num=0;
TMOD=0x01;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void xianshi(uchar bai,shi,ge)
{
zi=1;
P0=table[bai];
zi=0;
P0=0xff;
wei=1;
P0=0xfe;
wei=0;
delay(1);
zi=1;
P0=table[shi];
zi=0;
P0=0xff;
wei=1;
P0=0xfd;
wei=0;
delay(1);
zi=1;
P0=table[ge];
zi=0;
P0=0xff;
wei=1;
P0=0xfb;
wei=0;
delay(1);
}
void timer0() interrupt 1
{
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
tt++;
} |