📄 keitiaoshuzishizhong.c
字号:
#include <at89x52.h>
unsigned char code dispcode[]={0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90,0x00};
unsigned char dispbitcode[]={0x01,0x02,0x04,0x08,0x10,0x20};
unsigned char dispbuf[]={0,0,0,0,0,0} ;
unsigned char mstcnt;
unsigned int tcnt;
unsigned char second;
unsigned char minute;
unsigned char hour;
unsigned char dispbitcnt;
void delay(void)
{
unsigned char i,j;
for (i=0;i<20;i++)
for (j=0;j<248;j++);
}
void main (void)
{
TMOD=0X02;
TH0=0X06;
TL0=0X06;
TR0=1;
ET0=1;
EA=1;
while (1)
{
if (P2_0==0)
{
delay();
if (P2_0==0)
second++;
while(P2_0==0);
}
if (P2_1==0)
{
delay();
if (P2_1==0)
minute++;
while(P2_1==0);
}
if (P2_2==0)
{
delay();
if (P2_2==0)
hour++;
while(P2_2==0);
}
dispbuf[0]=hour/10;
dispbuf[1]=hour%10;
dispbuf[2]=minute/10;
dispbuf[3]=minute%10;
dispbuf[4]=second/10;
dispbuf[5]=second%10;
}
}
void t0() interrupt 1
{
mstcnt++;
if (mstcnt==4)
{
mstcnt=0;
P1=dispcode[dispbuf[dispbitcnt]];
P2=dispbitcode[dispbitcnt];
dispbitcnt++;
if (dispbitcnt==6)
dispbitcnt=0;
}
tcnt++;
if (tcnt==4000)
{
tcnt=0;
second++;
if (second==60)
{
second=0;
minute++;
if (minute==60)
{
minute=0;
hour++;
if (hour==24)
{
hour=0;
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -