新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 我用單片機寫的電子時鐘

我用單片機寫的電子時鐘

作者: 時間:2016-11-29 來源:網(wǎng)絡(luò) 收藏
void Init(){uchar num;dula=0;wela=0;lcden=0;year=2010;mouth=4;day=11;week=7;write_com(0x38);write_com(0x0c);write_com(0x06);write_com(0x01);write_com(0x80);for(num=0;num<16;num++){write_date(year_table[num]);delay(5);}write_com(0x80+0x40);for(num=0;num<12;num++){write_date(time_table[num]);delay(5);}timer_Init();}void keyscan(){rd=0;if(key_set==0){delay(5);if(key_set==0){key_count++;while(!key_set);//等待鍵盤釋放if(key_count==1){TR0=0;write_com(0x80+0x40+10);write_com(0x0f);}if(key_count==2){write_com(0x80+0x40+7);}if(key_count==3){write_com(0x80+0x40+4);}if(key_count==4){write_com(0x80+13);}if(key_count==5){write_com(0x80+10);}if(key_count==6){write_com(0x80+7);}if(key_count==7){write_com(0x80+2);}if(key_count==8){key_count=0;write_com(0x0c);TR0=1;}}}if(key_count!=0){if(key_inc==0){delay(5);if(key_inc==0){while(!key_inc);if(key_count==1){second++;if(second==60){second=0;}write_time(10,second);write_com(0x80+0x40+10);}if(key_count==2){minute++;if(minute==60){minute=0;}write_time(7,minute);write_com(0x80+0x40+7);}if(key_count==3){hour++;if(hour==24){hour=0;}write_time(4,hour);write_com(0x80+0x40+4);}if(key_count==4){week++;if(week==8){week=1;}write_week(13,week);write_com(0x80+13);}if(key_count==5){day++;if(day==32){day=1;}write_day(10,day);write_com(0x80+10);}if(key_count==6){mouth++;if(mouth==13){mouth=1;}write_day(7,mouth);write_com(0x80+7);}if(key_count==7){year++;write_year(2,year);write_com(0x80+2);}}}if(key_dec==0){delay(5);if(key_dec==0){while(!key_dec);if(key_count==1){second--;if(second==-1){second=59;}write_time(10,second);write_com(0x80+0x40+10);}if(key_count==2){minute--;if(minute==-1)minute=59;write_time(7,minute);write_com(0x80+0x40+7);}if(key_count==3){hour--;if(hour==-1)hour=23;write_time(4,hour);write_com(0x80+0x40+4);}if(key_count==4){week--;if(week==0){week=7;}write_week(13,week);write_com(0x80+13);}if(key_count==5){day--;if(day==0){day=31;}write_day(10,day);write_com(0x80+10);}if(key_count==6){mouth--;if(mouth==0){mouth=12;}write_day(7,mouth);write_com(0x80+7);}if(key_count==7){year--;if(year==2009){year=2010;}write_year(2,year);write_com(0x80+2);}}}}}void main(){Init();while(1){keyscan(); }}void clock_timer() interrupt 1{TH0=(65536-50000)/256;TL0=(65536-50000)%256;time_count++;if(time_count==18){time_count=0;second++;if(second==60){second=0;minute++;if(minute==60){minute=0;hour++;if(hour==24){hour=0;}write_time(4,hour);}write_time(7,minute);}write_time(10,second);}}
上一頁 1 2 下一頁

關(guān)鍵詞: 單片機電子時

評論


技術(shù)專區(qū)

關(guān)閉