#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit kuai=P3^0;
uint num;
uchar bai,shi,ge,aa;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void display(uchar bai,uchar shi,uchar ge);
void init();
void main()
{
init();
while(1)
{
if(aa==1)
{
aa=0;
num++;
}
if(num==999)
{
num=0;
}
bai=num/100;
shi=num%100/10;
ge=num%10;
display(bai,shi,ge);
}
}
void init()
{
kuai=0;
P0=0xff;
num=0;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void display(uchar bai,uchar shi,uchar ge)
{
kuai=1;
P1=table[bai];
kuai=0;
P0=0xfe;
P0=0xff;
kuai=1;
P1=table[shi];
kuai=0;
P0=0xfd;
P0=0xff;
kuai=1;
P1=table[ge];
kuai=0;
P0=0xfb;
P0=0xff;
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
aa++;
}
这是我写的程序,这个是基本的,还要加些东西上去,就是0-999的显示 |