#2
小月亮哎呀丶2020-11-30 16:21
|
遇到的问题是P0.0 + A0 + 数码管A口不通以及数码管显示不全
求大佬看看,实在是看不出来了。
附上代码↓
程序代码:
#include <AT89X52.H>
//电子时钟
#define unit unsigned int
#define uchar unsigned char
unit time_t;
uchar hour,min,sec;
uchar code led[10]={0XFC,0X60,0XDA,0XF2,0X66,0XB6,0XBE,0XE0,0XFE,0XF6};
void delay_1ms(unit x)
{
TMOD=0X01;
TR0=1;
while(x--)
{
TH0=0XFC;
TL0=0X18;
while(!TF0);
TF0=0;
time_t++;
}
TR0=0;
}
void display_num(uchar num,dis_W)
{
uchar j;
for(j=0;j<2;j++)
{
P0=0XFF;
P2=~dis_W;
if(j>0)
P0=~led[num/10];
else
P0=~led[num%10];
dis_W=dis_W<<1;
delay_1ms(5);
}
}
void display_char()
{
P0=0XFF;
P2=~0X24;
P0=~0X02;
delay_1ms(5);
}
void time_take()
{
if(time_t>=1000)
{
time_t=0;
sec++;
if(sec==60)
{
sec=0;
min++;
if(min==60)
{
min=0;
hour++;
if(hour==24)
{
hour=0;
}
}
}
}
}
void main()
{
sec=56;
min=59;
hour=23;
while(1)
{
display_num(sec,0X01);
display_num(min,0X08);
display_num(hour,0X40);
display_char();
time_take();
}
}
//电子时钟
#define unit unsigned int
#define uchar unsigned char
unit time_t;
uchar hour,min,sec;
uchar code led[10]={0XFC,0X60,0XDA,0XF2,0X66,0XB6,0XBE,0XE0,0XFE,0XF6};
void delay_1ms(unit x)
{
TMOD=0X01;
TR0=1;
while(x--)
{
TH0=0XFC;
TL0=0X18;
while(!TF0);
TF0=0;
time_t++;
}
TR0=0;
}
void display_num(uchar num,dis_W)
{
uchar j;
for(j=0;j<2;j++)
{
P0=0XFF;
P2=~dis_W;
if(j>0)
P0=~led[num/10];
else
P0=~led[num%10];
dis_W=dis_W<<1;
delay_1ms(5);
}
}
void display_char()
{
P0=0XFF;
P2=~0X24;
P0=~0X02;
delay_1ms(5);
}
void time_take()
{
if(time_t>=1000)
{
time_t=0;
sec++;
if(sec==60)
{
sec=0;
min++;
if(min==60)
{
min=0;
hour++;
if(hour==24)
{
hour=0;
}
}
}
}
}
void main()
{
sec=56;
min=59;
hour=23;
while(1)
{
display_num(sec,0X01);
display_num(min,0X08);
display_num(hour,0X40);
display_char();
time_take();
}
}