1 任务和设计要求首先要学会安装软件,要熟悉会使用。
2 系统设计系统框图3 硬件设计3.1 电路原理图3.2 主要单元电路3.3 元件清单4 软件设计4.1 程序流程图4.2程序清单TIME_WEEK DATA 52H TIME_YEAR DATA 5DH TIME_MONTH DATA 5EH TIME_DATA DATA 5FH YEARH DATA 36HYEAR DATA 35H MONTH DATA 34HDAY DATA 33HHOUR DATA 32H MINUTE DATA 31HSEC DATA 30HAAA BIT P3.0BBB BIT P3.1AA BIT P3.3BB BIT P3.4CC BIT P3.5BL BIT P3.2BZ1 BIT 21H.0 TIMES DATA 20H COM DATA P1 ORG 0000HLJMP START ORG 0003H RETIORG 000BH LJMP INTT0ORG 0013H RETIORG 001BH RETIORG 0023H RETISTART:MOV R0,#30H MOV R7,#9 CLEETE:MOV @R0,#00H INC R0DJNZ R7,CLEETE MOV TIMES,#00H MOV TMOD,#01H MOV TL0,#0C0H MOV TH0,#63H MOV SEC,#0MOV MINUTE,#0H MOV HOUR,#0H MOV DAY,#01H MOV MONTH,#01H MOV YEAR,#01H MOV YEARH,#20H SETB EASETB ET0SETB TR0MOV R4,#19 START1:CALL DISPJNB AA,SETMM1 JMP START1 SETMM1:CALL SETMMJMP START1 SETMM:CALL DISPCALL DISPJB AA,SETMM0 SETMM2:JNB AA,SETMM3CLR ET0CLR TR0MOV SEC,#0MOV TIMES,#01H MOV R0,#MINUTE SETMM4:NOPINC22:CALL OFFLCALL INC11CALL DISPJB AA,INC22CALL DISPJB AA,INC22INC R0MOV A,TIMESRL AMOV TIMES,AJNB TIMES. 5, SETMM4 SETMM12:JNB AA , SETMM11 SETMM0:SETB TR0SETB ET0RETSETMM11:CALL DISPJMP SETMM12 SETMM3:CALL DISPJMP SETMM2INC11:MOV R3,#40INC111:MOV A,@R0JB BB,INC17ADD A,#1DA ACALL INC000INC13:JNB BB , INC14INC17:MOV @R0,A CALL DISP DJNZ R3,INC111RETINC14:CALL DISP JMP INC13 OFFL:MOV 22H,@R0 MOV R6,#10 OFF1:MOV R7,#10OFF2:MOV @ R0, # 0AAH CALL DISPDJNZ R7 , OFF2DJNZ R6 , OFF1MOV @ R0 , 22H RETINC000:JB TIMES. 0, INC001 JB TIMES. 1, INC002 JB TIMES. 2, INC003 JB TIMES. 3, INC004 JB TIMES. 4, INC005 JMP INCOUTINC005:CJNE A, #99H, INCOUT MOV A,#00HJMP INCOUTINC004:CJNE A, # 13H, INCOUT MOV A,#01HJMP INCOUTINC003:CJNE A,# 32H ,INCOUT MOV A,#01H JMP INCOUT INC002:CJNE A,#24H,INCOUT MOV A,#00H JMP INCOUT INC001:CJNE A,# 60H , INCOUT MOV A,#00H INCOUT:RETINTT0:PUSH ACC PUSH PSWORL TL0,#0C0HMOV TH0,#63H DJNZ R4 , CLKE111 JMP LOOP11 CLKE111:JMP CLKELOOP11:MOV R4,#19H MOV A,SECADD A,#1DA AMOV SEC,A CJNE A, #60H , CLKE99 MOV SEC,#0 MOV A,MINUTE ADD A,#1DA AMOV MINUTE,A CLK0:CJNE A, # 60H, CLKE MOV MINUTE,#0 MOV A,HOURADD A,#1DA AMOV HOUR,ACJNE A, # 24H, CLKE MOV HOUR,#0 MOV A,DAYADD A,#1DA AMOV DAY,A MOV A,MONTH INC AMOVC A, @A + PC SJMP CLK1DB 31H,28H,31H DB 30H,31H,30H DB 31H,31H,30H DB 00H,00H,00H DB 00H,00H,00H DB 31H,30H,31H CLK1:CLR CSUBB A,DAYJNC CLKEMOV A,MONTH CJNE A,#2,CLK3MOV A,YEAR ANL A,#13HJNB ACC.4,CLK2ADD A,#2CLK2:ANL A,#3JNZ CLK3MOV A,DAY XRL A,#29HJZ CLKECLK3:MOV DAY,#1 MOV A,MONTH ADD A,#1DA AMOV MONTH,A CJNE A,#13H,CLKE MOV MONTH,#1 MOV A,YEAR ADD A,#1DA AMOV YEAR,A CLKE99:CALL CONVERT CLKE:POP PSW POP ACC RETIDISP:PUSH PSW PUSH ACC MOV 23H,R0 DISP99:MOV R1,#40H MOV R0,#30H MOV R2,#9 DISP1:MOV A,@R0ANL A,#0FHMOV @R1,AMOV A,@R0SWAP AANL A,#0FHINC R1MOV @R1,ADJNZ R2,DISP2 CALL DISPLAYMOV R0,23HPOP ACCPOP PSWRETDISP2:INC R1INC R0JMP DISP1 DISPLAY:MOV R1,#40HMOV R5,#19SETB AAAPLAY:SETB BBBNOPCLR BBBCLR AAAMOV A,@R1MOV DPTR,#TAB MOVC A,@A+DPTR MOV COM,ACALL DL1MSMOV COM,#0FFHDJNZ R5,PLAY1CLR BBBSETB AAARETPLAY1:INC R1JMP PLAYTAB:DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H,0FFH,0A3H,8EH,0ABH DL1MS:MOV 25H,R7MOV 24H,R6MOV R7,#20DS1:MOV R6,#10DJNZ R6,$DJNZ R7,DS1MOV R7,25HMOV R6,24HRETSTART_YEAR EQU 01 CONVERT_YEAR DATA 5CH CONVERT_MONTH DATA 38H CONVERT_DATE DATA 37H TEMP_BYTE1 DATA 57H TEMP_BYTE2 DATA 58H TEMP_BYTE3 DATA 59H TEMP_BYTE4 DATA 5AH TEMP_BYTE5 DATA 5BH CONVERT:MOV A, YEARMOV TIME_YEAR,AMOV A,MONTHMOV TIME_MONTH,AMOV A,DAYMOV TIME_DATA,AMOV A,TIME_YEARMOV B,#16DIV ABMOV CONVERT_YEAR,B MOV B,#10MUL ABADD A,CONVERT_YEARMOV CONVERT_YEAR,AMOV A,TIME_MONTHJNB ACC.4,CON_02CLR ACC.4ADD A,#10CON_02:MOV CONVERT_MONTH,A MOV A,TIME_DATAMOV B,#16DIV ABMOV CONVERT_DATE,BMOV B,#10MUL ABADD A,CONVERT_DATEMOV CONVERT_DATE,AMOV DPTR,#MONTH_DATAMOV A,CONVERT_YEARCON_06:CLR CSUBB A,#START_YEARMOV B,#3MUL ABADD A,DPLMOV DPL,AMOV A,BADDC A,DPHMOV DPH,AMOV A, #2MOVC A, @A+DPTRCLR ACC.7MOV B, #32DIV ABMOV TEMP_BYTE1,AMOV TEMP_BYTE2,BMOV TEMP_BYTE3,#0MOV A,CONVERT_MONTH CJNE A,#10,CON_08CON_08:JC CON_09MOV TEMP_BYTE3,#1CON_09:MOV A,CONVERT_YEAR ANL A,#03HJNZ CON_10MOV A,CONVERT_MONTH LCALL GET_RUN_DAYS_LOW SJMP CON_12CON_10:MOV A,CONVERT_MONTH LCALL GET_DAYS_LOWCON_12:MOV B,CONVERT_DATE DEC BADD A,BMOV TEMP_BYTE4,AJNC CON_14INC TEMP_BYTE3CON_14:MOV A,TEMP_BYTE1 LCALL GET_DAYS_LOWDEC AADD A,TEMP_BYTE2MOV TEMP_BYTE5,AMOV A,CONVERT_MONTHCJNE A,TEMP_BYTE1,CON_20 MOV A,CONVERT_DATECJNE A,TEMP_BYTE2,CON_20 CON_20:JC CON_22LJMP CON_60CON_22:MOV A,CONVERT_YEAR JNZ CON_24MOV A,#100CON_24:DEC AMOV CONVERT_YEAR,A MOV A,DPLCLR CSUBB A,#3MOV DPL,AJNC CON_26DEC DPHCON_26:MOV A,TEMP_BYTE5 CLR CSUBB A,TEMP_BYTE4MOV TEMP_BYTE3,AMOV CONVERT_MONTH,#12 CLR F0CLR AMOVC A,@A+DPTRANL A,#0F0HSWAP A;MOV TEMP_BYTE4,AJZ CON_30MOV A, #2MOVC A , @A+DPTRMOV C, ACC.7MOV A, #1MOVC A, @A+DPTRRLC ASJMP CON_34CON_30:MOV A, #1MOVC A, @A+DPTRCON_34:MOV TEMP_BYTE5, A CON_40:MOV A, TEMP_BYTE5 RRC AMOV TEMP_BYTE5, AJC CON_42MOV B, #29SJMP CON_44CON_42:MOV B, #30CON_44:MOV A, TEMP_BYTE3 CLR CSUBB A, BJZ CON_46JNC CON_50CPL AINC ACON_46: INC AMOV B, #10DIV ABSWAP AORL A, BMOV CONVERT_DATE, A MOV A, CONVERT_MONTH MOV B, #10DIV ABSWAP AORL A, BMOV CONVERT_MONTH, A MOV A, CONVERT_YEAR MOV B, #10DIV ABSWAP AORL A, BMOV CONVERT_YEAR, A CALL WEEKRETCON_50:MOV TEMP_BYTE3, A JB F0, CON_52DEC CONVERT_MONTHCON_52:MOV A, CONVERT_MONTH CJNE A, TEMP_BYTE4, CON_54CPL F0CON_54:SJMP CON_40CON_60:MOV A, TEMP_BYTE4CLR CSUBB A, TEMP_BYTE5MOV TEMP_BYTE4, AJNC CON_62DEC TEMP_BYTE3CON_62:MOV CONVERT_MONTH, #1 CLR AMOVC A, @A+DPTRMOV TEMP_BYTE5, AANL A, #0F0HSWAP AXCH A, TEMP_BYTE5CLR F0ANL A, #0FHMOV TEMP_BYTE1, AMOV A, #1MOVC A, @A+DPTRMOV TEMP_BYTE2, AANL A, #0F0HORL A, TEMP_BYTE1SWAP AMOV TEMP_BYTE1, AMOV A, #2MOVC A, @A+DPTRMOV C, ACC.7MOV A, TEMP_BYTE2ANL A, # 0FHSWAP AMOV ACC. 3, CMOV TEMP_BYTE2, ACON_70:MOV A, TEMP_BYTE2 RLC AMOV TEMP_BYTE2, AMOV A, TEMP_BYTE1RLC AMOV TEMP_BYTE1, AJC CON_72MOV B, #29SJMP CON_74CON_72:MOV B, #30CON_74:MOV A, TEMP_BYTE4CLR CSUBB A,BJNC CON_78MOV B, AMOV A, TEMP_BYTE3JZ CON_76DEC TEMP_BYTE3MOV TEMP_BYTE4, BSJMP CON_80CON_76:MOV A, TEMP_BYTE4 LJMP CON_46CON_78:MOV TEMP_BYTE4, ACON_80:MOV A, CONVERT_MONTH CJNE A, TEMP_BYTE5, CON_82 CPL F0JNB F0, CON_82SJMP CON_70CON_82:INC CONVERT_MONTH SJMP CON_70GET_DAYS_LOW:MOVC A, @A+PCRETDB 0,31,59,90,120,151,181,212,243,17,48,78 GET_RUN_DAYS_LOW:MOVC A, @A+PCRETDB 0,31,60,91,121,152,182,213,244,18,49,79 MONTH_DATA:DB 04DH,04AH,0B8H;2001DB 00DH,04AH,04CH;2002DB 00DH,0A5H,041H;2003DB 025H,0AAH,0B6H;2004DB 005H,06AH,049H;2005DB 07AH,0ADH,0BDH;2006DB 002H,05DH,052H;2007DB 009H,02DH,047H;2008DB 05CH,095H,0BAH;2009DB 00AH,095H,04EH;2010DB 00BH,04AH,043H;2011DB 04BH,055H,037H;2012 DB 00AH,0D5H,04AH;2013 DB 095H,05AH,0BFH;2014 DB 004H,0BAH,053H;2015 DB 00AH,05BH,048H;2016 DB 065H,02BH,0BCH;2017 DB 005H,02BH,050H;2018 DB 00AH,093H,045H;2019 DB 047H,04AH,0B9H;2020 DB 006H,0AAH,04CH;2021 DB 00AH,0D5H,041H;2022 DB 024H,0DAH,0B6H;2023 DB 004H,0B6H,04AH;2024 DB 069H,057H,03DH;2025 DB 00AH,04EH,051H;2026 DB 00DH,026H,046H;2027 DB 05EH,093H,03AH;2028 DB 00DH,053H,04DH;2029 DB 005H,0AAH,043H;2030 DB 036H,0B5H,037H;2031 DB 009H,06DH,04BH;2032 DB 0B4H,0AEH,0BFH;2033DB 004H,0ADH,053H;2034 DB 00AH,04DH,048H;2035 DB 06DH,025H,0BCH;2036 DB 00DH,025H,04FH;2037 DB 00DH,052H,044H;2038 DB 05DH,0AAH,038H;2039 DB 00BH,05AH,04CH;2040 DB 005H,06DH,041H;2041 DB 024H,0ADH,0B6H;2042 DB 004H,09BH,04AH;2043 DB 07AH,04BH,0BEH;2044 DB 00AH,04BH,051H;2045 DB 00AH,0A5H,046H;2046 DB 05BH,052H,0BAH;2047 DB 006H,0D2H,04EH;2048 DB 00AH,0DAH,042H;2049 DB 035H,05BH,037H;2050 DB 009H,037H,04BH;2051 DB 084H,097H,0C1H;2052 DB 004H,097H,053H;2053 DB 006H,04BH,048H;2054 DB 066H,0A5H,03CH;2055DB 00EH,0A5H,04FH;2056 DB 006H,0B2H,044H;2057 DB 04AH,0B6H,038H;2058 DB 00AH,0AEH,04CH;2059 DB 009H,02EH,042H;2060 DB 03CH,097H,035H;2061 DB 00CH,096H,049H;2062 DB 07DH,04AH,0BDH;2063 DB 00DH,04AH,051H;2064 DB 00DH,0A5H,045H;2065 DB 055H,0AAH,0BAH;2066 DB 005H,06AH,04EH;2067 DB 00AH,06DH,043H;2068 DB 045H,02EH,0B7H;2069 DB 005H ,02DH, 04BH; 2070 DB 08AH, 095H, 0BFH; 2071 DB 00AH, 095H, 053H; 2072 DB 00BH, 04AH, 047H; 2073 DB 06BH, 055H, 03BH; 2074 DB 00AH, 0D5H, 04FH; 2075 DB 005H, 05AH, 045H; 2076 DB 04AH, 05DH, 038H; 2077DB 00AH, 05BH, 04CH; 2078 DB 005H, 02BH, 042H; 2079 DB 03AH, 093H, 0B6H; 2080 DB 006H, 093H, 049H; 2081 DB 077H, 029H, 0BDH; 2082 DB 006H, 0AAH, 051H; 2083 DB 00AH, 0D5H, 046H; 2084 DB 054H, 0DAH, 0BAH; 2085 DB 004H, 0B6H, 04EH; 2086 DB 00AH, 057H, 043H; 2087 DB 045H, 027H, 038H; 2088 DB 00DH, 026H, 04AH; 2089 DB 08EH, 093H, 03EH; 2090 DB 00DH, 052H, 052H; 2091 DB 00DH, 0AAH, 047H; 2092 DB 066H, 0B5H, 03BH; 2093 DB 005H, 06DH, 04FH; 2094 DB 004H, 0AEH, 045H; 2095 DB 04AH, 04EH, 0B9H; 2096 DB 00AH, 04DH, 04CH; 2097 DB 00DH, 015H, 041H; 2098 DB 02DH, 092H, 0B5H; 2090DB 00DH, 053H, 049H; 2100 TIME_WEEK1 DATA 52H WEEK:MOV A, TIME_YEARMOV B, #16DIV ABMOV TEMP_BYTE1, BMOV B, #10MUL ABADD A, TEMP_BYTE1MOV TEMP_BYTE1, AMOV A, TIME_MONTHJB ACC.7, GETW02MOV A, #100ADD A, TEMP_BYTE1MOV TEMP_BYTE1, AMOV A, TIME_MONTHCLR ACC.7GETW02: JNB ACC.4, GETW04 ADD A , #10CLR ACC.4GETW04: MOV TEMP_BYTE2,AMOV A, TIME_DATAMOV B, #16DIV ABMOV TEMP_BYTE3, BMOV B, #10MUL ABADD A, TEMP_BYTE3MOV TEMP_BYTE3, AMOV A ,TEMP_BYTE1ANL A, #03HJNZ GETW10MOV A, TEMP_BYTE2CJNE A, #3,GETW06GETW06: JNC GETW10DEC TEMP_BYTE3GETW10: MOV A,TEMP_BYTE2 LCALL GET_CORRECTADD A, TEMP_BYTE1MOV B, #7DIV ABMOV A, TEMP_BYTE1ANL A, #0FCHRR ARR AADD A, BADD A, TEMP_BYTE3 MOV B, #7DIV ABMOV A, BCJNE A, #0,OUTOUT MOV B, #8 OUTOUT:MOV TIME_WEEK, B RETGET_CORRECT: MOVC A, @A+PC RETDB 0,3,3,6,1,4,6,2,5,0,3,5 END5 系统仿真及调试6 仿真结果及分析上图为运行时的显示,左边两个数码管显示器显示的是年、月、日,中间的显示的是时、分、秒,右边显示的是农历日期以及星期。