本帖最后由 后影遁 于 2018-7-30 19:09 编辑
#include<reg52.h>
#define ulint unsigned long
#define uint unsigned int
unsigned char code table[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uint shiw,wan,qia,bai,shi,ge,aa;
ulint num;
sbit dula=P2^6;
sbit wela=P2^7;
void deplay(uint shiw,uint wan,uint qia,uint bai,uint shi,uint ge);
void init();
void delay(uint);
void main()
{
init();
while(1)
{
if(aa==2)
{
num--;
if(num==765398)
{
num=765432;
}
shiw=num/100000;
wan=num%100000/10000;
qia=num%100000%10000/1000;
bai=num%100000%10000%1000/100;
shi=num%100000%10000%1000%100/10;
ge=num%100000%10000%1000%100%10;
}
deplay(shiw,wan,qia,bai,shi,ge);
}
}
void deplay(uint shiw,uint wan,uint qia,uint bai,uint shi,uint ge)
{
dula=1;
P0=table[shiw];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(5);
dula=1;
P0=table[wan];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(5);
dula=1;
P0=table[qia];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay(5);
dula=1;
P0=table[bai];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
delay(5);
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xef;
wela=0;
delay(5);
dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xdf;
wela=0;
delay(5);
}
void delay(uint z)
{
uint i,j;
for(i=z;i>0;i--)
for(j=100;j>0;j--);
}
void init()
{
num=765432;
TMOD=0x01;
TH1=(65536-45872)/256;
TL1=(65536-45872)%256;
EA=1;
ET1=1;
TR1=1;
}
void t1_time() interrupt 3
{
TH1=(65536-45872)/256;
TL1=(65536-45872)%256;
aa++;
}
但是六段数码管显示的效果全是0 大神们看看哪里错了
|