#include
#define uint unsigned int
#define uchar unsigned char
***it dula=P2^6;
***it wela=P2^7;
uchar code tabledu[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void delayms(uint);
void display(uchar,uchar,uchar,uchar,uchar,uchar);
uint disnum;
uchar count,swan,wan,qian,bai,shi,ge;
void main()
{
TMOD=0x10;
EA=1;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
ET0=1;
ET1=1;
TR0=1;
TR1=1;
while(1)
{
display(disnum/100000,disnum%100000/10000,disnum%100000%10000/1000,
disnum%100000%10000%1000/100,disnum%100000%10000%1000%100/10,
disnum%100000%10000%1000%100%10 );
}
}
void display(char swan,char wan,char qian,char bai,char shi,char ge)
{
P0=0xff;
wela=1;
wela=0;
P0=tabledu[swan];
dula=1;
dula=0;
P0=0xfe;
wela=1;
wela=0;
delayms(1);
P0=0xff;
wela=1;
wela=0;
P0=tabledu[wan];
dula=1;
dula=0;
P0=0xfd;
wela=1;
wela=0;
delayms(1);
P0=0xff;
wela=1;
wela=0;
P0=tabledu[qian];
dula=1;
dula=0;
P0=0xfb;
wela=1;
wela=0;
delayms(1);
P0=0xff;
wela=1;
wela=0;
P0=tabledu[bai];
dula=1;
dula=0;
P0=0xf7;
wela=1;
wela=0;
delayms(1);
P0=0xff;
wela=1;
wela=0;
P0=tabledu[shi];
dula=1;
dula=0;
P0=0xef;
wela=1;
wela=0;
delayms(1);
P0=0xff;
wela=1;
wela=0;
P0=tabledu[ge];
dula=1;
dula=0;
P0=0xdf;
wela=1;
wela=0;
delayms(1);
}
void tim1() interrupt 3
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
if(count==20)
{
count=0;
disnum++;
}
}
void delayms(uint x)
{uint i,j;
for(i=x;i>0;i--)
for(j=225;j>0;j--);
}为什么这段程序运行时除了低位的一个发光较亮,其余的都比较 暗?
|