📄 ats51ctime.c
字号:
#include<REG51.H>
#define uint unsigned int
#define uchar unsigned char
uchar code SEG7[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar code ACT[4]={0xef,0xdf,0xbf,0x7f};
uint hour;
uchar min,sec,cnt;
uchar status;
void delay(uint k);
/*********************************************************************/
union deda
{
uint dhour;
uchar dmin;
uchar dsec;
};
union deda dis_buff;
/*********************************************************************/
void initial(void)
{
TMOD=0x01;
TH0=-(5000/256);
TL0=-(5000%256);
ET0=1;
TR0=1;
EA=1;
}
/*******************************************************************/
void time1(void)interrupt 1
{ TH0=-(5000/256);
TL0=-(5000%256);
cnt++;
if(cnt>=20){sec++;cnt=0;}
if(sec>=60){min++;sec=0;status++;}
if(min>=60){hour++;min=0;}
if(hour>9999){hour=0;}
if(status>2){status=0;}
switch(status)
{case 0:dis_buff.dhour=hour;break;
case 1:dis_buff.dmin=min;break;
case 2:dis_buff.dsec=sec;break;
default:break;
}
}
/**********************************************************************/
void main(void)
{
initial();
for(;;)
{
switch(status)
{
case 0:{P0=SEG7[dis_buff.dhour%10];
P2=ACT[0];
delay(2);
P0=SEG7[(dis_buff.dhour%100)/10];
P2=ACT[1];
delay(2);
P0=SEG7[(dis_buff.dhour%1000)/100];
P2=ACT[2];
delay(2);
P0=SEG7[dis_buff.dhour/1000];
P2=ACT[3];
delay(2);
} break;
case 1:{ P0=SEG7[dis_buff.dmin%10];
P2=ACT[2];
delay(2);
P0=SEG7[dis_buff.dmin/10];
P2=ACT[3];
delay(2);
} break;
case 2:{ P1=SEG7[dis_buff.dsec%10];
P2=ACT[0];
delay(2);
P1=SEG7[dis_buff.dsec/10];
P2=ACT[1];
delay(2);
} break;
default:break;}
}
}
/***************************************************/
void delay(uint k)
{
uint i,j;
for(i=0;i<k;i++)
{ for(j=0;j<121;j++)
{;}
}
}
/**********************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -