單片機(jī)數(shù)字鐘程序
/*void display(void)
{
P1=0x7f;P2=0xff;SBUF=0x00;
P1=_crol_(P1,1);SBUF=disdata[date%10];delayX1ms(1);SBUF=0x00;
P1=_crol_(P1,1);if(date/10) SBUF=disdata[date/10]; else SBUF=0x00;delayX1ms(1);SBUF=0x00;
P1=_crol_(P1,1);SBUF=disdata[month%10];delayX1ms(1);SBUF=0x00;
P1=_crol_(P1,1);if(month/10) SBUF=disdata[month/10]; else SBUF=0x00;delayX1ms(1);SBUF=0x00;
P1=_crol_(P1,1);SBUF=disdata[year%10];delayX1ms(1);SBUF=0x00;
P1=_crol_(P1,1);SBUF=disdata[year/10%10];delayX1ms(1);SBUF=0x00;
P1=_crol_(P1,1);SBUF=disdata[year/100%10];delayX1ms(1);SBUF=0x00;
P1=_crol_(P1,1);SBUF=disdata[year/1000];delayX1ms(1);SBUF=0x00;
P1=0xff;P2=0x7f;
P2=_crol_(P2,1);SBUF=disdata[sec%10];delayX1ms(1);SBUF=0x00;
P2=_crol_(P2,1);SBUF=disdata[sec/10];delayX1ms(1);SBUF=0x00;
P2=_crol_(P2,1);SBUF=disdata[min%10];delayX1ms(1);SBUF=0x00;
P2=_crol_(P2,1);SBUF=disdata[min/10];delayX1ms(1);SBUF=0x00;
P2=_crol_(P2,1);SBUF=disdata[hour%10];delayX1ms(1);SBUF=0x00;
P2=_crol_(P2,1);if(hour/10) SBUF=disdata[hour/10]; else SBUF=0x00;delayX1ms(1);SBUF=0x00;
P2=_crol_(P2,1);SBUF=disdata[weekday()];delayX1ms(1);SBUF=0x00;
}
void display2(uchar a)
{
P1=0x7f;P2=0xff;SBUF=0x00;
P1=_crol_(P1,1);if(a=='d') SBUF=0x00;else SBUF=disdata[date%10];delayX1ms(1);SBUF=0x00;
P1=_crol_(P1,1);if(a=='d') SBUF=0x00;else{if(date/10) SBUF=disdata[date/10];else SBUF=0x00;}delayX1ms(1);SBUF=0x00;
P1=_crol_(P1,1);if(a=='m') SBUF=0x00;else SBUF=disdata[month%10];delayX1ms(1);SBUF=0x00;
P1=_crol_(P1,1);if(a=='m') SBUF=0x00;else{if(month/10) SBUF=disdata[month/10]; else SBUF=0x00;}delayX1ms(1);SBUF=0x00;
P1=_crol_(P1,1);if(a=='y') SBUF=0x00;else SBUF=disdata[year%10];delayX1ms(1);SBUF=0x00;
P1=_crol_(P1,1);if(a=='y') SBUF=0x00;else SBUF=disdata[year/10%10];delayX1ms(1);SBUF=0x00;
P1=_crol_(P1,1);if(a=='y') SBUF=0x00;else SBUF=disdata[year/100%10];delayX1ms(1);SBUF=0x00;
P1=_crol_(P1,1);if(a=='y') SBUF=0x00;else SBUF=disdata[year/1000];delayX1ms(1);SBUF=0x00;
P1=0xff;P2=0x7f;
P2=_crol_(P2,1);if(a=='S') SBUF=0x00;else SBUF=disdata[sec%10];delayX1ms(1);SBUF=0x00;
P2=_crol_(P2,1);if(a=='S') SBUF=0x00;else SBUF=disdata[sec/10];delayX1ms(1);SBUF=0x00;
P2=_crol_(P2,1);if(a=='M') SBUF=0x00;else SBUF=disdata[min%10];delayX1ms(1);SBUF=0x00;
P2=_crol_(P2,1);if(a=='M') SBUF=0x00;else SBUF=disdata[min/10];delayX1ms(1);SBUF=0x00;
P2=_crol_(P2,1);if(a=='H') SBUF=0x00;else SBUF=disdata[hour%10];delayX1ms(1);SBUF=0x00;
P2=_crol_(P2,1);if(a=='H') SBUF=0x00;else {if(hour/10) SBUF=disdata[hour/10]; else SBUF=0x00;}delayX1ms(1);SBUF=0x00;
P2=_crol_(P2,1);SBUF=disdata[weekday()];delayX1ms(1);SBUF=0x00;
}*/
void change(void)//這個(gè)程序?qū)懙暮軄y,其實(shí)應(yīng)該有更簡(jiǎn)單的方法
{
bit a=0;
uint b=0,c=0;
while(!P3_2);
while(1)
{if(!P3_3)
{delayX1ms(10);
if(!P3_3)
{while(!P3_3)
{if(++c>=1000)
{c=0;
display();
while(!P3_3)
{display();if(++c>=10)
{c=0;
if(++min>=60)min=0;
display();
}
}
}
}
if(++min>=60)min=0;
c=0;
}
a=1;
b=0;
}
else
{if(!P3_2){delayX1ms(10);if(!P3_2){while(!P3_2); break;}}
if(a)display();
else display2('M');
if(++b>=20)
{b=0;
a=!a;
}
}
if(!P3_2){delayX1ms(10);if(!P3_2){while(!P3_2); break;}}
}
while(1)
{if(!P3_3)
{delayX1ms(10);
if(!P3_3)
{while(!P3_3)
{if(++c>=1000)
{c=0;
display();
while(!P3_3)
{display();if(++c>=10)
{c=0;
if(++hour>=24)hour=0;
display();
}
}
}
}
if(++hour>=24)hour=0;
c=0;
}
a=1;
b=0;
}
else
{if(!P3_2){delayX1ms(10);if(!P3_2){while(!P3_2); break;}}
if(a)display();
else display2('H');
if(++b>=20)
{b=0;
a=!a;
}
}
if(!P3_2){delayX1ms(10);if(!P3_2){while(!P3_2); break;}}
}
while(1)
{if(!P3_3)
{delayX1ms(10);
if(!P3_3)
{while(!P3_3)
{if(++c>=1000)
{c=0;
display();
while(!P3_3)
{display();if(++c>=10)
{c=0;
if(++date>daysofmonth())date=1;
display();
}
}
}
}
if(++date>daysofmonth())date=1;
c=0;
}
a=1;
b=0;
}
else
{if(!P3_2){delayX1ms(10);if(!P3_2){while(!P3_2); break;}}
if(a)display();
else display2('d');
if(++b>=20)
{b=0;
a=!a;
}
}
if(!P3_2){delayX1ms(10);if(!P3_2){while(!P3_2); break;}}
}
while(1)
{if(!P3_3)
{delayX1ms(10);
if(!P3_3)
{while(!P3_3)
{if(++c>=1000)
{c=0;
display();
while(!P3_3)
{display();if(++c>=10)
{c=0;
if(++month>12)month=1;
display();
}
}
}
}
if(++month>12)month=1;
c=0;
}
a=1;
b=0;
}
else
{if(!P3_2){delayX1ms(10);if(!P3_2){while(!P3_2); break;}}
if(a)display();
else display2('m');
if(++b>=20)
{b=0;
a=!a;
}
}
if(!P3_2){delayX1ms(10);if(!P3_2){while(!P3_2); break;}}
}
while(1)
{if(!P3_3)
{delayX1ms(10);
if(!P3_3)
{while(!P3_3)
{if(++c>=1000)
{c=0;
display();
while(!P3_3)
{display();if(++c>=10)
{c=0;
if(++year>=2100)year=2000;
display();
}
}
}
}
if(++year>=2100)year=2000;
c=0;
}
a=1;
b=0;
}
else
{if(!P3_2){delayX1ms(10);if(!P3_2){while(!P3_2); break;}}
if(a)display();
else display2('y');
if(++b>=20)
{b=0;
a=!a;
}
}
if(!P3_2){delayX1ms(10);if(!P3_2){while(!P3_2); break;}}
}
while(1)
{if(!P3_2){delayX1ms(10);if(!P3_2){while(!P3_2); break;}}
if(a)display();
else display2('S');
if(++b>=20)
{b=0;
a=!a;
}
if(!P3_3)
{delayX1ms(10);
if(!P3_3)
sec=0;
}
if(!P3_2){delayX1ms(10);if(!P3_2){while(!P3_2); break;}}
}
}
uchar weekday(void)
{uint a=year-1;
uint b=0;
uchar i;
for(i=1;imonth;i++)
b+=monthdata[i-1];
b+=date;
if(month>2isleap())
b++;
i=(a+a/4-a/100+a/400+b)%7;
if(i)return i;
else return 8;
}
uchar daysofmonth(void) reentrant
{if(month!=2) return monthdata[month-1];
else if(isleap()) return 29;
else return 28;
}
bit isleap(void) reentrant
{return (year%4==0year%100!=0||year%400==0);
}
到這里這個(gè)單片機(jī)數(shù)字鐘c程序就完畢了程序很長(zhǎng)而且沒(méi)什么注釋,希望大家慢慢搞定。有什么問(wèn)題可在本站論壇提出,馬上為您解決。
單片機(jī)相關(guān)文章:單片機(jī)教程
單片機(jī)相關(guān)文章:單片機(jī)視頻教程
單片機(jī)相關(guān)文章:單片機(jī)工作原理
評(píng)論