LED数字钟的设计(电子数字时钟的设计)电子数字时钟的设计采用单片机(如:AT89C2051)、LED 数码管等设计数字时钟,系统设有5个按键,能实现时间的调整、定时时间的设定,输出等功能
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/24 18:34:21
LED数字钟的设计(电子数字时钟的设计)电子数字时钟的设计采用单片机(如:AT89C2051)、LED 数码管等设计数字时钟,系统设有5个按键,能实现时间的调整、定时时间的设定,输出等功能
LED数字钟的设计(电子数字时钟的设计)
电子数字时钟的设计
采用单片机(如:AT89C2051)、LED 数码管等设计数字时钟,系统设有5个按键,能实现时间的调整、定时时间的设定,输出等功能
LED数字钟的设计(电子数字时钟的设计)电子数字时钟的设计采用单片机(如:AT89C2051)、LED 数码管等设计数字时钟,系统设有5个按键,能实现时间的调整、定时时间的设定,输出等功能
LED0 EQU 3AH
LED1 EQU 3BH
LED2 EQU 3CH
LED3 EQU 3DH
LED4 EQU 3EH
LED5 EQU 3FH
CSEC EQU 30H
SEC EQU 31H
MINI EQU 32H
HOUR EQU 33H
SETV BIT 01H
SJH EQU 0C5H
SJL EQU 68H
BCDCODE EQU 35H
CURSHIF EQU 36H
CURTIME EQU 37H
DELms1 EQU 38H
DELms2 EQU 39H
ORG 0000H
LJMP MAIN
ORG 000BH
LJMP TIMECOUNT
ORG 0050H
MAIN:MOV SP,#60H
MOV CSEC,#00H
MOV SEC,#58H
MOV MINI,#59H
MOV HOUR,#23H
MOV BCDCODE,#00H
MOV CURTIME,#00H
MOV DELms1,#00H
MOV DELms2,#00H
CLR SETV
MOV DPTR,#0FF24H ;#7FFFH
MOV A,#80H
MOVX @DPTR,A
MOV TMOD,#01H
MOV TH0,#SJH
MOV TL0,#SJL
SETB EA
SETB ET0
SETB TR0
LOOP0:LCALL CZ
LCALL DISPLAY
LCALL KEYSCAN
JNZ LOOP1
LJMP LOOP0
LOOP1:LCALL KEYRES
LJMP LOOP0
TIMECOUNT:CLR EA
PUSH ACC
PUSH PSW
SETB EA
MOV TH0,#SJH
MOV TL0,#SJL
MOV A,CSEC
ADD A,#1
MOV CSEC,A
CJNE A,#64H,TIMERET
MOV CSEC,#00H
MOV A,SEC
ADD A,#1
DA A
MOV SEC,A
CJNE A,#60H,TIMERET
MOV SEC,#00H
MOV A,MINI
ADD A,#1
DA A
MOV MINI,A
CJNE A,#60H,TIMERET
MOV MINI,#00H
MOV A,HOUR
ADD A,#1
DA A
MOV HOUR,A
CJNE A,#24H,TIMERET
MOV HOUR,#00H
TIMERET:CLR EA
POP PSW
POP ACC
SETB EA
RETI
CZ:SETB RS1
MOV R7,#03H
MOV R0,#SEC
MOV R1,#LED0
LOOP2:MOV A,@R0
ANL A,#0FH
MOV @R1,A
INC R1
MOV A,@R0
ANL A,#0F0H
SWAP A
MOV @R1,A
INC R0
INC R1
DJNZ R7,LOOP2
CLR RS1
RET
DISPLAY:SETB RS0
MOV R4,#00100000B
MOV R5,#06H
MOV R0,#LED5
LOOP3:MOV DPTR,#TAB0
MOV A,@R0
MOVC A,@A+DPTR
MOV DPTR,#0FF22H ; #7FFCH
MOVX @DPTR,A
MOV DPTR,#0FF21H ;#7FFDH
MOV A,R4
MOVX @DPTR,A
MOV DELms1,#1
LCALL DELAY
DEC R0
MOV A,R4
RR A
MOV R4,A
DJNZ R5,LOOP3
CLR RS0
RET
TAB0:DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H,0FFH
DELAY:MOV DELms2,#250
DEL_HERE:DJNZ DELms2,DEL_HERE
DJNZ DELms1,DELAY
RET
KEYSCAN:MOV A,#7FH
MOV P1,A
MOV A,P1
CPL A
ANL A,#7FH
RET
KEYRES :LCALL CZ
LCALL DISPLAY
LCALL CZ
LCALL DISPLAY
LCALL KEYSCAN
JNZ LOOP4
KEY_RET:RET
LOOP4:PUSH ACC
LOOP4E:LCALL CZ
LCALL DISPLAY
LCALL KEYSCAN
JNZ LOOP4E
POP ACC
JB ACC.0 ,LOOP40
JB ACC.1,LOOP41
JB ACC.2,LOOP42
JB ACC.3 ,LOOP43
JB ACC.6,LOOP46
LJMP KEY_RET
LOOP40:LJMP KEY_SET
LOOP41:LJMP KEY_SHIFT
LOOP42:LJMP KEY_UP
LOOP43:LJMP KEY_DOWN
LOOP46:LJMP KEY_ENTER
KEY_SET:JB SETV,KEY_SET_RET
SETB SETV
CLR TR0
MOV CURSHIF,#HOUR
MOV R0,CURSHIF ;;
MOV CURTIME,@R0
MOV @R0,#0AAH
KEY_SET_RET:LJMP KEY_RET
KEY_SHIFT:JNB SETV,KEY_SHIFT_RET
MOV R0,CURSHIF
CJNE @R0,#0AAH,KEY_SHIFT0
MOV @R0,CURTIME
KEY_SHIFT0:CJNE R0,#SEC,KEY_SHIFT2
KEY_SHIFT1:MOV R0,#HOUR
MOV CURSHIF,R0
MOV CURTIME,@R0
MOV @R0,#0AAH
LJMP KEY_SHIFT_RET
KEY_SHIFT2:DEC R0
MOV CURSHIF,R0
MOV CURTIME,@R0
MOV @R0,#0AAH
KEY_SHIFT_RET:LJMP KEY_RET
KEY_UP:JNB SETV,KEY_UP_RET
MOV R0,CURSHIF
CJNE @R0,#0AAH,KEY_UP0
MOV @R0,CURTIME
KEY_UP0:CJNE R0,#HOUR,KEY_UP2
KEY_UP1:CJNE @R0,#23H,KEY_UP11
KEY_UP11:JC KEY_UP12
MOV @R0,#0
MOV CURTIME,@R0
LJMP KEY_UP_RET
KEY_UP12:MOV A,#1
ADD A,@R0
DA A
MOV @R0,A
;INC @R0
;MOV BCDCODE,@R0
;LCALL CONV_TO_BCD
;MOV @R0,BCDCODE
MOV CURTIME,@R0
LJMP KEY_UP_RET
KEY_UP2:CJNE @R0,#59H,KEY_UP21
KEY_UP21:JC KEY_UP22
MOV @R0,#0
MOV CURTIME,@R0
LJMP KEY_UP_RET
KEY_UP22:MOV A,#1
ADD A,@R0
DA A
MOV @R0,A
;INC @R0
;MOV BCDCODE,@R0
;LCALL CONV_TO_BCD
;MOV @R0,BCDCODE
MOV CURTIME,@R0
KEY_UP_RET:LJMP KEY_RET
KEY_DOWN:JNB SETV,KEY_DOWN_RET
NOP
; MOV R0,CURSHIF
; CJNE @R0,#0AAH,KEY_DOWN0
; MOV @R0,CURTIME
;KEY_DOWN0:CJNE R0,#HOUR,KEY_DOWN2
;KEY_DOWN1:CJNE @R0,#01H,KEY_DOWN11
;KEY_DOWN11:JNC KEY_DOWN12
; MOV @R0,#23H
; LJMP KEY_DOWN_RET
;KEY_DOWN12:;DEC @R0
; MOV BCDCODE,@R0
; LCALL CONV_TO_BCD
; MOV @R0,BCDCODE
; LJMP KEY_DOWN_RET
;KEY_DOWN2:CJNE @R0,#01H,KEY_DOWN21
;KEY_DOWN21:JNC KEY_DOWN22
; MOV @R0,#59H
; LJMP KEY_DOWN_RET
;KEY_DOWN22:;DEC @R0
; MOV BCDCODE,@R0
; LCALL CONV_TO_BCD
; MOV @R0,BCDCODE
KEY_DOWN_RET:LJMP KEY_RET
KEY_ENTER:JNB SETV,KEY_ENTER_RET
MOV R0,CURSHIF
CJNE @R0,#0AAH,KEY_ENTER0
MOV @R0,CURTIME
KEY_ENTER0:CLR SETV
SETB TR0
KEY_ENTER_RET:LJMP KEY_RET
CONV_TO_BCD:PUSH ACC
PUSH B
MOV A,BCDCODE
ANL A,#0F0H
MOV B,#10
MUL AB
ORL BCDCODE,#0FH
ADD A,BCDCODE
DEC A
MOV BCDCODE,A
;
MOV B,#10
DIV AB
ANL A,#0FH
SWAP A
MOV BCDCODE,A
MOV A,B
ANL A,#0FH
ORL BCDCODE,A
; MOV A,BCDCODE
;MOV B,#10
; DIV AB
; ANL A,#0FH
; SWAP A
; MOV BCDCODE,A
;MOV A,B
; ANL A,#0FH
; ORL BCDCODE,A
POP B
POP ACC
RET
END