#include<reg52.h>
typedef unsigned char u8;
typedef unsigned int u16;
/********????*********/
#define DATA P0
sbit seg_sel = P1^4;
sbit bit_sel = P1^5;
sbit K0=P1^0;
sbit K1=P1^1;
sbit K2=P1^2;
/********????*********/
u8 s=0,min=0,h=0,ms=0;
u8 n=0;
u8 run_flag; //?run_flag?1,??????
u8 temp_buf[5][3];
u8 arr_pt;
u8 code seg_tab[]={ //¿ØÖÆêyÂë1üÏÔê¾
0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90};
u8 code bit_tab[]={ //¿ØÖÆμú¼¸Î»éá˸
0x10,0x20,0x40,0x80,
0x01,0x02,0x04,0x08
};
void delay(unsigned int y) //Ñóê±oˉêy
{
unsigned int x,z;
for(x=y; x>0; x--)
for(z=110; z>0; z--);
}
void display_led(u8 which_bit, u8 which_number)
{
bit_sel = 1;//Q[7..0]=D[7..0]
DATA = bit_tab[which_bit];
bit_sel = 0;//BIT[7..0]=0x80
seg_sel = 1;//Q[7..0]=D[7..0]
DATA = seg_tab[which_number];
seg_sel = 0;
}
void display(u8 which_bit, u8 which_number)
{
u8 x,y;
x = which_number/10; //·Öàëê®Î»
y = which_number%10; //·Öàë¸öλ
if (which_bit == 1)
{
display_led(1, x);
delay(2);
display_led(0, y);
delay(2);
}
if (which_bit == 2)
{
display_led(4, x);
delay(2);
display_led(3, y);
delay(2);
}
if (which_bit == 3)
{
display_led(7, x);
delay(2);
display_led(6, y);
delay(2);
}
}
void reflash (void)
{
display(1, s);
display(2, min);
display(3, h);
}
void main (void)
{
TMOD = 0x01; //¶¨ê±¼ÆêyÆ÷T01¤×÷·½ê½
TH0 = (65535-10000) / 256;
TL0 = (65535-10000) % 256;
EA = 1; //¿a·Å×üÖD¶Ï
ET0 = 1; //¶¨ê±Æ÷0μÄòç3öÖD¶Ï
TR0 = 1;
while (1)
{
reflash();
}
}
void t0_server(void) interrupt 1
{
TH0 = (65535-10000) / 256;
TL0 = (65535-10000) % 256;
ms++;
if (ms >= 100)
{
ms = 0;
s++;
if (s >= 59)
{
s = 0;
min++;
if (min >= 59)
min = 0;
h++;
if (h >= 24)
h=0;
}
}
}
|