/*
八位时钟
*/
#include
#include
#define uchar unsigned char
#define uint unsigned int
uchar code duanca[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
uchar code weica[8] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
int i,j,z;
uint hour = 0,minute = 0,second = 0,t50ms = 0;//所有参数从零开始
//含参数延时
void delays(int d)
{
while(d--);
}
//主函数
void main(void)
{
uchar i;
while(1)//大循环
{
for(i = 0;i<= 7;i++)//for循环
{
P3 = ~weica[i];//以此选择数码管显示,一个循环一次
switch(i)//switch开关 i = 0 1 2 3 4 5 6 7
{
//时,分,秒,分别看作一个两位数,在通过这个两位数分别除以10和取余10,得到十位和各位
case 0:P2 = duanca[hour/10];break;//读取选择十位
case 1:P2 = duanca[hour%10];break;//读取选择个位
case 2:P2 = ~0xbf;break;//显示那个横杠
case 3:P2 = duanca[minute/10];break;//同理
case 4:P2 = duanca[minute%10];break;
case 5:P2 = ~0xbf;break;
case 6:P2 = duanca[second/10];break;
case 7:P2 = duanca[second%10];break;
default:break;
}
delays(100);
//这里是的秒分时分别进一,59秒后分就进一,59分后时就进一,23时后重新循环
t50ms++;
if(t50ms == 800)
{
t50ms = 0;
second++;
if(second == 60)
{
second = 0;
minute++;
if(minute==60)
{
minute = 0;
hour++;
if(hour==24)
hour = 0;
}
}
}
}
}
}