#include < reg51.h >
sbit test = P1^0;
unsigned char code Disp_Tab[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};
unsigned char code dispbit[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char Interrupt_CNT;
void system_Ini()
{
TMOD = 0x01;
TH0 = 0xd8;
TL0 = 0xf0;
IE = 0X82;
TR0 = 1;
}
void delay(unsigned int i) //ÑÓʱº¯Êý
{
char j;
for(i; i > 0; i--)
for(j = 200; j > 0; j--);
}
void main()
{
unsigned int Second_Num;
unsigned int Minute_Num;
unsigned int Hour_Num;
unsigned char Led_Out[8]={0};
unsigned char y;
system_Ini() ;
while(1)
{
if(Interrupt_CNT>=100)
{
Interrupt_CNT = 0;
Second_Num++;
if(Second_Num==60)
{
Second_Num = 0;
Minute_Num++;
if(Minute_Num==60)
{
Minute_Num= 0;
Hour_Num++;
if(Hour_Num==24)
{
Hour_Num= 0;
}
}
}
}
Led_Out[0]=Disp_Tab[Hour_Num%100/10];
Led_Out[1]=Disp_Tab[Hour_Num/10];
Led_Out[2]=0x40;
Led_Out[3]=Disp_Tab[Minute_Num%100/10];
Led_Out[4]=Disp_Tab[Minute_Num%10];
Led_Out[5]=0x40;
Led_Out[6]=Disp_Tab[Second_Num%100/10];
Led_Out[7]=Disp_Tab[Second_Num%10];
for( y=0; y<8; y++)
{
P0 = Led_Out[y];
P2 = dispbit[y];
delay(10);
}
}
}
void
timer0(void) interrupt 1
{
TH0 = 0xd8;
TL0 = 0xf0;
test = ~test;
Interrupt_CNT++;
}
一周热门 更多>