1;山东科技大学信电通信07-1lfj作品lifaji@yahoo.cn方案一:2方案二:3采用方案二。模块图4;-------------------------按键说明-------------------------;--------------------------1键——进入可调状态-------------------------;-------------------------2键——结束返回-------------------------;-------------------------3键——秒加1/日加1-------------------------;-------------------------4键——分加1/月加1-------------------------;-------------------------5键——显示24小时制/时加1/年加1-------------------------;-------------------------6键——显示12小时制-------------------------;-------------------------7键——可调时间-------------------------;-------------------------8键——可调日期-------------------------CLKBITP1.6;时钟信号端DISPBITP1.7;串出锁存端DBUFEQU30H;秒的最低位地址LEDBITP1.1CHANGE2BIT21H;加12的标志位AD1EQU40H;秒AD2EQU41H;分AD3EQU42H;时AD4EQU43H;天AD5EQU44H;月AD6EQU45H;年;初始化存储单元结束ORG0000HLJMPMAINORG000BH;T0中断入口LJMPINTORG0030HMAIN:MOVR0,#AD1MOVR7,#06HLOOP0:MOVA,#00HMOV@R0,AINCR0DJNZR7,LOOP0;R0~R7清零MOVAD1,#37HMOVAD2,#22HMOVAD3,#0CHMOVAD4,#08HMOVAD5,#08HMOVAD6,#08H;初始化时间为12:34:56,日期为08年08月08日MOVIE,#82H;允许T0中断5MOVTMOD,#01H;T0允许工作MOVTH0,#4CHMOVTL0,#00H;送入计数初值0.05sMOVR5,#00H;初始化结束SETBTR0;T0使能LOOP:LCALLTEST;扫描键盘CJNEA,#0FEH,NEXTD;0FEH为1键LCALLDY1MSLCALLKEYDONENEXTD:SJMPLOOP;扫描键盘看是否需要调整日历DISPLAY:LCALLTEST;扫描键盘CJNEA,#0DFH,ERSHISI1;0DFH为6键SETBPSW.1;显示十二小时LJMPTIMEZHUANERSHISI1:CJNEA,#0EFH,ERSHISI2;0EFH为5键CLRPSW.1;显示二十四小时CLRCHANGE2LJMPTIMEZHUANERSHISI2:CJNEA,#0CFH,CHANGE;0CFH为5+6键CLRPSW.1SETBCHANGE2;CHANGE2=1表示把十二表示法转换成二十四小时LJMPTIMEZHUANCHANGE:CLRCHANGE2TIMEZHUAN:LCALLTESTCJNEA,#7FH,NEXTL;7FH为8键SETBPSW.5LJMPZHUAN1NEXTL:CJNEA,#0BFH,ZHUAN1;0BFH为7键CLRPSW.5ZHUAN1:JBPSW.5,DAY;PSW.5=0调整时间,为1则调整日期MOVA,AD1;调整时间键码分离MOVB,#0AHDIVABMOVR0,#DBUFMOV@R0,BINCR0MOV@R0,A6MOVA,AD2MOVB,#0AHDIVABINCR0MOV@R0,BINCR0MOV@R0,AJBPSW.1,TIMEZHUAN1LJMPTIMEZHUAN2TIMEZHUAN1:;判断时间是否大于12MOVA,AD3MOVB,#0CHSUBBA,BJCNORMALTMOVAD3,ALJMPNORMALTTIMEZHUAN2:JNBCHANGE2,NORMALT;判断是否加12MOVA,AD3ADDA,#MOVAD3,ACLRCHANGE2NORMALT:MOVA,AD3MOVB,#0AHDIVABINCR0MOV@R0,BINCR0MOV@R0,ASJMPDDISPDAY:;调整日期键码分离MOVA,AD4MOVB,#0AHDIVABMOVR0,#DBUFMOV@R0,BINCR0MOV@R0,AMOVA,AD57MOVB,#0AHDIVABINCR0MOV@R0,BINCR0MOV@R0,AMOVA,AD6MOVB,#0AHDIVABINCR0MOV@R0,BINCR0MOV@R0,ADDISP:;显示,串入并处的方式,上升沿写入MOVR0,#DBUFMOVR7,#06HLOOP2:MOVR6,#08HMOVA,@R0MOVDPTR,#TABMOVCA,@A+DPTR;显示秒CLRCLOOP3:RRCACLRCLKMOVDISP,CSETBCLKDJNZR6,LOOP3INCR0DJNZR7,LOOP2RETKEYDONE:;人工手动调整日历AGAINB:LCALLDY250MS;防抖250msLCALLTESTCJNEA,#7FH,NEXTL1;7FH为8键SETBPSW.5LJMPZHUAN12NEXTL1:CJNEA,#0BFH,ZHUAN12CLRPSW.5;以上为扫描键盘并设置PSW.5ZHUAN12:JBPSW.5,NEXT6B;判断调整日期还是时间8CJNEA,#0FDH,NEXTA;0FDH为2键,如果按键值为FDH则结束LJMPBACKNEXTA:CJNEA,#0FBH,NEXTB;0FBH为3键INCAD1;秒加1MOVA,AD1CJNEA,#3CH,AGAINAMOVAD1,#00HSJMPAGAINANEXTB:CJNEA,#0F7H,NEXTC;0F7H为4键INCAD2;分加1MOVA,AD2CJNEA,#3CH,AGAINAMOVAD2,#00HSJMPAGAINANEXTC:CJNEA,#0EFH,AGAINA;0EFH为5键INCAD3;时加1MOVA,AD3CJNEA,#18H,AGAINAMOVAD3,#00HNEXTT:SJMPAGAINANEXT6B:CJNEA,#0FDH,NEXTAB;JIESHUJIAN;0FDH为2键LJMPBACKNEXTAB:CJNEA,#0FBH,NEXTBB;0FBH为3键INCAD4;日加1MOVA,AD4CJNEA,#20H,AGAINAMOVAD4,#01HSJMPAGAINANEXTBB:CJNEA,#0F7H,NEXTCB;0F7H为4键INCAD5;月加1MOVA,AD5CJNEA,#0DH,AGAINAMOVAD5,#01HSJMPAGAINANEXTCB:CJNEA,#0EFH,AGAINA;0EFH为5键INCAD6;年加1MOVA,AD6CJNEA,#64H,AGAINAMOVAD6,#00HAGAINA:LCALLDISPLAYLJMPAGAINBBACK:RET9INT:INCR5CJNER5,#20,NEXTS1;循环20次,每次循环为0.05秒,共0.05*20=1秒MOVR5,#00HLCALLDISPLAY;满一秒后的显示LJMPMENDNEXTS1:LJMPNEXTS;满一秒后的显示MEND:MOVA,AD1CJNEA,#0AH,LAREMENDSETBLED;满十秒关灯,否则继续LAREMEND:INCAD1MOVA,AD1CJNEA,#3CH,NEXTS2LJMPMEND1NEXTS2:LJMPNEXTS;以上为看是否修改秒,满60,分加一否则跳转继续MEND1:MOVAD1,#00HINCAD2MOVA,AD2CJNEA,#3CH,NEXTS3LJMPMEND2NEXTS3:LJMPNEXTS;以上为看是否修改分,满60,时加一否则跳转继续MEND2:MOVAD2,#00HINCAD3MOVA,AD3CJNEA,#0Ah,ZAIJIANCHAAJMPBAOSHIZAIJIANCHA:CJNEA,#0Bh,ZHENGCHANGBAOSHI:CLRLED;以上为两个报时开灯ZHENGCHANG:MOVA,AD3CJNEA,#18H,NEXTS4;不满二十四小时跳出LJMPMEND3;满二十四后跳到清零小时继续加天NEXTS4:LJMPNEXTSMEND3:MOVAD3,#00HINCAD4MOVA,AD5CJNEA,#02H,JIXUTIAN;判断是否为二月份MOVA,AD6MOVB,#4H10DIVABMOVA,BJZRUNNIAN;判断是否为闰年PINGNIAN:MOVA,AD4;平年CJNEA,#1DH,NEXTSMOVAD4,#01HAJMPJIXUYUERUNNIAN:MOVA,AD4;闰年CJNEA,#1EH,NEXTSMOVAD4,#01HAJMPJIXUYUEJIXUTIAN:;不为二月,再查看是那个月MOVA,AD5CJNEA,#01H,PAN1LJMPSANSHIYIPAN1:CJNEA,#03H,PAN3LJMPSANSHIYIPAN3:CJNEA,#04H,PAN4LJMPSANSHIPAN4:CJNEA,#05H,PAN5LJMPSANSHIYIPAN5:CJNEA,#06H,PAN6LJMPSANSHIPAN6:CJNEA,#07H,PAN7LJMPSANSHIYIPAN7:CJNEA,#08H,PAN8LJMPSANSHIYIPAN8:CJNEA,#09H,PAN9LJMPSANSHIPAN9:CJNEA,#10H,PAN10LJMPSANSHIYIPAN10:CJNEA,#11H,SANSHIYILJMPSANSHISANSHIYI:MOVA,AD4;月份:1,3,5,7,8,10,12CJNEA,#20H,NEXTSMOVAD4,#01HAJMPJIXUYUESANSHI:MOVA,AD4;月份:2,4,6,8,11CJNEA,#1FH,NEXTSMOVAD4,#01H11JIXUYUE:INCAD5;满月后加年CJNEA,#0DH,NEXTSMOVAD5,#01HINCAD6MOVA,AD6CJNEA,#64H,NEXTS;年满100后清零MOVAD6,#00HNEXTS:;再赋初值MOVTH0,#4CHMOVTL0,#00HRETIDY250MS:;延迟防抖250msMOVR4,#0FAHLOOP8:LCALLDY1MSDJNZR4,LOOP8RETDY1MS:;延迟防抖1msMOVR5,#0B0HLOOP7:MOVR7,#2AHDJNZR7,$DJNZR5,LOOP7RET;键盘扫描子程序TEST:MOVR7,#08HSETBP1.7CLRP1.7;低电平锁存NOPNOPSETBP1.7;高电平输出MOVA,#0FFHAGAIN3:CLRP2.3NOPNOPMOVC,P3.5;把p3.5的状态存入CSETBP2.3RLCA;键盘状态存入ADJNZR7,AGAIN3;扫描八个按键RETTAB:DB88H,0EBH,4CH,49H,2BH,19H,18H,0CBH,08H,09H;子程序功能索引:;TEST——扫描键盘;DDISP——显示12;NEXTS——重新赋初值;DY1MS——延迟防抖1msEND