PIC16F877APIC16F877APIC16F877APIC16F877A万年历程序万年历程序万年历程序万年历程序一、说明:1.本数字始时钟可以显示日期,时间,并具有农历与星期查询功能2.具有环境温度检测功能。3.三组闹钟设置。二、使用方法:1.使用设置键可以方便切换要设置的对象,并配合+、-键使之设置成你要的数值。2.当设置闹钟时,当调到想要设置的时间时,按存储键即可存入第一组闹钟,以此类推共可以设置三组。三、原理图见附录1:四、源程序/****************************************************标题:万年历**作者:**日期:2008年1月13日**说明:包含文件ziku.h,lcd_init.h****************************************************/#includepic.h#includeziku.h#includelcd_init.h#includeds1302.h#includeds18b20.h#includekeyscan.h#includeyinli.huchjj,ii;//子程序//LCD显示空白边框子程序voidLCDShowTable(){uchi;SlectScreen(1);//写左半屏SetLine(0);//起使页SetColumn(0);//起使列for(i=0;i64;i++){if((i==0)||(i==63))WriteData(0xff);//第1、63列竖线elseWriteData(0x01);//最上面一行线}for(i=1;i7;i++){SetLine(i);SetColumn(0);WriteData(0xff);//竖线SetColumn(63);WriteData(0xff);//竖线}SetLine(7);SetColumn(0);for(i=0;i64;i++){if((i==0)||(i==63))WriteData(0xff);elseWriteData(0x80);//最下面的横线}SlectScreen(2);//写右半屏SetLine(0);SetColumn(0);for(i=0;i64;i++){if(i==63)WriteData(0xff);elseWriteData(0x01);}SetLine(4);SetColumn(0);for(i=0;i64;i++){if(i==63)WriteData(0xff);elseWriteData(0x01);}for(i=1;i7;i++){SetLine(i);SetColumn(63);WriteData(0xff);}SetLine(7);SetColumn(0);for(i=0;i64;i++){if(i==63)WriteData(0xff);elseWriteData(0x80);}}/*----------------------------------------------------------*///显示固定字符子程序voidLCDShowGudingWord(){Show8X16(0,80,maohao,1);Show8X16(0,104,maohao,1);Show16X16(6,80,yue,2);Show16X16(0,40,nian,1);Show16X16(4,2,yue,0);Show16X16(6,8,xing,2);Show16X16(6,24,qi,2);Show16X16(2,96,danwei1,0);Show8X16(0,8,s2,1);Show8X16(0,16,s0,1);}/*----------------------------------------------------------*/voidTMR0init(){T0CS=0;PSA=0;PS2=1;PS1=1;PS0=1;TMR0=0x80;T0IE=1;T0IF=0;}//冒号闪烁子程序voidFlashMaohao(){staticuchtimecount1;staticinttimecount2;if(TMR0IF==1){TMR0=0x80;TMR0IF=0;timecount1++;timecount2++;if(timecount1==10){flag++;flag=flag%2;//闪烁标志在0-1间翻转timecount1=0;}if(timecount2==1200)//1分钟采样一次温度{timecount2=0;get_temp();//温度转换子程序}}if(flag==0){Show8X16(0,80,maohao,1);Show8X16(0,104,maohao,1);}if(flag==1){Show8X16(0,80,noshu,1);//清除Show8X16(0,104,noshu,1);}}voidNaoling(){if(kk==1){if(RD3==0){jj++;jj=jj%4;while(1){if(RD3==1)break;}}if(jj==1){Naoling_hour_1=Naoling_hour;Naoling_minute_1=Naoling_minute;RC4=1;RC6=0;RC7=0;}if(jj==2){Naoling_hour_2=Naoling_hour;Naoling_minute_2=Naoling_minute;RC4=0;RC6=1;RC7=0;}if(jj==3){Naoling_hour_3=Naoling_hour;Naoling_minute_3=Naoling_minute;RC4=0;RC6=0;RC7=1;}}}voidNaolingXiang(){inti;if((kk==1)&&(Naoling_hour_1==clock[2])&&(Naoling_minute_1==clock[1])){RC5=1;for(i=0;i100;i++);RC5=0;for(i=0;i500;i++);}if((kk==1)&&(Naoling_hour_2==clock[2])&&(Naoling_minute_2==clock[1])){RC5=1;for(i=0;i100;i++);RC5=0;for(i=0;i200;i++);}if((kk==1)&&(Naoling_hour_3==clock[2])&&(Naoling_minute_3==clock[1])){RC5=1;for(i=0;i200;i++);RC5=0;for(i=0;i500;i++);}}//查询子程序voidchaxun(){if(RD3==0){ii++;ii=ii%2;}while(1){if(RD3==1)break;}if(ii==1){KeyScan();}}//主程序voidmain(){keyinit();//键盘初始化LCDinit();//LCD操作初始化LCDShowTable();//显示空白表格LCDShowGudingWord();//显示固定字符get_temp();//读取温度TMR0init();while(1){v_Get1302(clock);//读取时间、日历display();FlashMaohao();//冒号闪烁KeyScan();//键盘扫描GetWeek(clock[6]+2000,clock[4],clock[3]);GetChinaCalendar(clock[6]+2000,clock[4],clock[3]);//Naoling();//NaolingXiang();chaxun();}}附录附录附录附录1111::::