#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
unsigned char code duan[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //段码控制
unsigned char code wei[]={0xdf,0xef,0xf7,0xfb,0xfd,0xfe}; //位选控制 查表的方法控制
void display(uchar,uchar,uchar,uchar,uchar,uchar);
void delay(uint);
uchar num,a,b,c,d,e,f;
ulong m;
void main()
{
TMOD=0x15;
TH0=0;
TL0=0;
TH1=(65536-45872)/256;
TL1=(65536-45872)%256;
EA=1;
ET0=1;
ET1=1;
TR0=1;
TR1=1;
while(1)
display(a,b,c,d,e,f);
}
void display(uchar a,uchar b,uchar c,uchar d,uchar e,uchar f)
{
P0=0xff;
P2=0;
delay(1);
P0=wei[0];
P2=duan[a];
delay(1);
P0=wei[1];
P2=duan
;
delay(1);
P0=wei[2];
P2=duan[c];
delay(1);
P0=wei[3];
P2=duan[d];
delay(1);
P0=wei[4];
P2=duan[e];
delay(1);
P0=wei[5];
P2=duan[f];
delay(1);
}
void delay(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void T1_time()interrupt 3
{
TH1=(65536-45872)/256;
TL1=(65536-45872)%256;
num++;
if(num==20)
{
EA=0;
TR0=0;
TR1=0;
m=256*TH1+TL1;
a=m/100000;
b=m/10000;
c=m/1000;
d=m/100;
e=m/10;
f=m%10;
}
}
一周热门 更多>