我用單片機(jī)寫的電子時(shí)鐘 作者: 時(shí)間:2016-11-29 來(lái)源:網(wǎng)絡(luò) 加入技術(shù)交流群 掃碼加入和技術(shù)大咖面對(duì)面交流海量資料庫(kù)查詢 收藏 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);}} 上一頁(yè) 1 2 下一頁(yè)
評(píng)論