一.功能简介 1.电子时钟显示格式为: XX XX XX,由左向右分别为: 时、分、秒,比如:23 20 40表示23时20分40秒,刚开始工作时应该显示为:12 00 00; 2.实现对时、分、秒进行校准; 二.程序清单 ORG 0000H AJMP MAIN ORG 0003H LJMP SET_M ORG 000BH LJMP T_0 ORG 0013H LJMP MOD_M ORG 0100H ;-------主程序变量初始化-------------- MAIN: MOV SP,#60H MOV DPTR,#TAB S EQU R2 MODE EQU R3 TEMP EQU R4 H2 EQU 20H ;H为小时值 H1 EQU 21H M2 EQU 22H ;M为分钟 M1 EQU 23H S2 EQU 24H ;S为秒 S1 EQU 25H ** BIT P1.0 MOV S,#00H ;初始时间为12:00:00 MOV TEMP,#12 MOV MODE,#00H MOV H2,#1 MOV H1,#2 MOV M2,#0 MOV M1,#0 MOV S2,#0 MOV S1,#0 ;------------中断初始化------------------- MOV TMOD,#11H ;两个定时器都是方式1 MOV TL0,#78H ;定时器0 MOV TH0,#0ECH SETB EA ;开总中断 CLR PT0 ;定时器中断高优先级 SETB ET0 ;开定时器中断0 SETB TR0 ;开定时器 SETB IT1 ;边沿触发方式 SETB IT0 SETB EX1 ;开外部中断1 SETB EX0 ;开外部中断0 CLR ** ;----------主程序员------------ LOOP: ACALL DISP SJMP LOOP ;---------定时器中断程序------------- T_0: CLR EA MOV TH0,#0ECH MOV TL0,#78H INC S CJNE S,#200,STOPT MOV S,#0 ACALL COUN STOPT: SETB EA RETI ;-----------计算显示值--------------- COUN: INC S1 MOV A,S1 CJNE A,#0AH,STOP MOV S1,#00H INC S2 MOV A,S2 CJNE A,#06H,STOP MOV S2,#00H INC M1 MOV A,M1 CJNE A,#0AH,STOP MOV M1,#00H INC M2 MOV A,M2 CJNE A,#06H,STOP MOV M2,#00H INC TEMP CJNE TEMP,#24,NEXT MOV TEMP,#00H NEXT: MOV H1,TEMP MOV A,H1 MOV B,#10 DIV AB MOV H1,B MOV H2,A STOP: NOP RET ;-------显示子程序----------- DISP: MOV R0,#20H MOV R1,#0DFH LOOPD: MOV A,@R0 MOVC A,@A+DPTR MOV P0,A MOV A,R1 CJNE A,#0EFH,NEXTL1 CJNE MODE,#03H,GONO CLR P0.7 SJMP GONO NEXTL1: CJNE A,#0FBH,NEXTL2 CJNE MODE,#02H,GONO CLR P0.7 SJMP GONO NEXTL2: CJNE A,#0FEH,GONO CJNE MODE,#01H,GONO CLR P0.7 GONO: MOV P2,A RR A MOV R1,A ACALL DEALY MOV P2,#0FFH MOV P0,#0FFH INC R0 CJNE R0,#26H,LOOPD MOV R1,#0DFH RET ;---------延时子程序,5MS------------ DEALY: MOV TH1,#0ECH MOV TL1,#78H SETB TR1 JNB TF1,$ CLR TR1 CLR TF1 RET ;---------设置------------- MOD_M: CLR EA INC MODE CJNE MODE,#04H,STOP1 MOV MODE,#00H STOP1: SETB EA RETI ;--------设时-------- SET_M: CLR EA CJNE MODE,#01H,NEXT_M ;SET_=1时,将秒改成0,为2时改分,每按一次SET,分钟值就加1 MOV S1,#00H ;SET_=3时 改时,每按一次SET,小时值值就加1 MOV S2,#00H SJMP STOP_ NEXT_M: CJNE MODE,#02H,NEXT_H INC M1 MOV A,M1 CJNE A,#0AH,STOP_ MOV M1,#00H INC M2 MOV A,M2 CJNE A,#06H,STOP_ MOV M2,#00H SJMP NEXTH NEXT_H: CJNE MODE,#03H,STOP_ INC TEMP CJNE TEMP,#24,NEXTH MOV TEMP,#00H NEXTH: MOV H1,TEMP MOV A,H1 MOV B,#10 DIV AB MOV H1,B MOV H2,A STOP_: SETB EA RETI ;--------共阳极LED_7字形码------------ TAB: DB 0c0H,0f9H,0a4H,0b0H,99H,92H,82H,0f8H DB 80H,90H END
|