📄 时钟.c
字号:
#include <REGX51.H>
unsigned char code table[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
bit d_05s=0;
unsigned char num=0;
unsigned char sec=0,minuter=0,hour=0;
void delay(unsigned char);
display(unsigned char a,unsigned b,unsigned char shi,unsigned char ge);
void main()
{
EA=1;
ET1=1;
TMOD=0x10;
TH1=0x3C;
TL1=0xAF;
TR1=1;
while(1)
{
if(num<=10)
d_05s=0;
else
d_05s=1;
if(num==20)
{
num=0;
if(sec>=59)
{
sec=0;
minuter++;
if(minuter>=59)
{
minuter=0;
if(hour>=23)
hour=0;
else
hour++;
}
}
else
sec++;
}
display(hour/10,hour%10, minuter/10, minuter%10);
}
}
void delay(unsigned char x)
{
unsigned char m,n;
for(m=x;m>0;m--)
for(n=500;n>0;n--);
}
display(unsigned char a,unsigned b,unsigned char shi,unsigned char ge)
{
P1=0xfb;
P0=table[shi];
delay(10);
P1=0xf7;
P0=table[ge];
delay(10);
P1=0xfe;
P0=table[a];
delay(10);
P1=0xfd;
P0=table[b];
delay(10);
if( d_05s==1)
{if(P1_2==0Xfd)
P0_7=0;
else
P0_7=1;
}
delay(10);
}
void tim1(void) interrupt 3
{
TH1=0x3C;
TL1=0xAF;
num++;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -