新手刚看书看到数码管,想自己写个
电子钟,写完传到板子上都不亮。。。求各位老师帮看看那出问题了。。谢谢
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit wela=P2^7;
sbit dula=P2^6;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uchar LED[]={
0x00,0x00,0x00,
0x00,0x00,0x00
};
void main(){
uchar cnt=0;
uint i=0;
uint sec=0;
uint min=0;
uint hou=0;
TMOD=0x01;
TH0=0xfc;
TL0=0x67;
TR0=1;
while(1){
if(TF0==1){
TF0=0;
TH0=0xfc;
TL0=0x67;
cnt++;
if(cnt>=1000){
cnt=0;
sec++;
LED[0]=table[sec%10];
LED[1]=table[sec/10%10];
if(sec>=60){
sec=0;
min++;
LED[2]=table[min%10];
LED[3]=table[min/10%10];
if(min>=60){
min=0;
hou++;
LED[4]=table[hou%10];
LED[5]=table[hou/10%10];
if(hou>=24){
hou=0;
min=0;
sec=0;
}
}
}
}
switch(i){
case 0:
i++;
dula=1;
P0=LED[0];
dula=0;
P0=0xff;
wela=1;
P0=0x7f;
wela=0;
break;
case 1:
i++;
dula=1;
P0=LED[1];
dula=0;
P0=0xff;
wela=1;
P0=0xbf;
wela=0;
break;
case 2:
i++;
dula=1;
P0=LED[2];
dula=0;
P0=0xff;
wela=1;
P0=0xef;
wela=0;
break;
case 3:
i++;
dula=1;
P0=LED[3];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
break;
case 4:
i++;
dula=1;
P0=LED[4];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
break;
case 5:
i=0;
dula=1;
P0=LED[5];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
break;
}
}
}
}
一周热门 更多>