谁能帮我分析下,数码管单独显示时分秒可以得,但按键按下切换到年月日时就只能显示1个1了,哪位老师帮忙指导下
#include <reg52.h>
#include <intrins.h>
#define DATA P0
typedef unsigned char u8;
typedef unsigned int u16;
sbit seg_sel = P1^4;
sbit bit_sel = P1^5;
sbit key = P3^2;
u8 count ;
u8 shi,fen,miao;
u8 code seg_tab[]={
0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,
0xc6,0xa1,0x86,0x8e,0xbf
};
u8 code bit_tab[]={
0x10,0x20,0x40,0x80,
0x01,0x02,0x04,0x08
};
void delay(u16 num)
{
u16 x,y;
for(x=num;x>0;x--)
for(y=110;y>0;y--);
}
void led_display(u8 which_bit,u8 which_num)
{
bit_sel = 1;
DATA = bit_tab[which_bit];
bit_sel = 0;
seg_sel = 1;
DATA = seg_tab[which_num];
seg_sel = 0;
delay(2);
}
void display_shi(u8 which_bit,u8 num)
{
u8 x,y;
x = num/10;
y = num%10;
if(which_bit == 1)
{
led_display(0,y);
delay(1);
led_display(1,x);
delay(2);
led_display(2,seg_tab[17]) ;
}
if(which_bit == 2)
{
led_display(3,y);
delay(1);
led_display(4,x);
delay(2);
led_display(5,seg_tab[17]);
}
if(which_bit == 3)
{
led_display(6,y);
delay(1);
led_display(7,x);
delay(2);
}
}
void display_nian(u8 which_bit)
{
if(which_bit == 1)
{
led_display(0,6);
delay(1);
led_display(1,2);
delay(2);
led_display(2,seg_tab[17]) ;
}
if(which_bit == 2)
{
led_display(3,2);
delay(1);
led_display(4,1);
delay(2);
led_display(5,seg_tab[17]) ;
}
if(which_bit == 3)
{
led_display(6,8);
delay(1);
led_display(7,1);
delay(2);
}
}
void main ()
{
TMOD = 0X01;
TH0 =(65536-50000)/256;
TL0 = (65536-50000)%256;
EA = 1;
ET0 = 1;
TR0 = 1;
DATA = 0xff;
display_shi(1,miao);
display_shi(2,fen);
display_shi(3,shi);
while(1)
{
if(key==1)
{
display_shi(1,miao);
display_shi(2,fen);
display_shi(3,shi);
}
if(key==0)
{
delay(10);
if(key==0)
{
display_nian(1);
display_nian(2);
display_nian(3);
} while(!key);
}
}
}
void LED_0() interrupt 1
{
TH0 =(65536-50000)/256;
TL0 = (65536-50000)%256;
count++;
if(count==20)
{
count=0;
miao++;
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
fen=0;
shi++;
if(shi==23)
{
shi=0;
}
}
}
}
} |