此代码让LCD1602第一行显示时分秒,第二行显示年月日,且能够加一减一,但LCD中年的高位和时的高位总是不显示?我解决不了啊
LCD_CMD_WR EQU 0 ; LCD ¸÷¼Ä′æÆ÷μØÖ·
LCD_DATA_WR EQU 1
LCD_BUSY_RD EQU 2
LCD_DATA_RD EQU 3
LCD_CLS EQU 1 ;LCD Ãüáî
LCD_HOME EQU 2
LCD_SETMODE EQU 4
LCD_SETVISIBLE EQU 8
LCD_SHIFT EQU 16
LCD_SETFUNCTION EQU 32
LCD_SETCGADDR EQU 64
LCD_SETDDADDR EQU 128
DS1302_ADDR DATA 32H
DS1302_DATA DATA 31H
SECOND EQU 60H
WORK BIT P1.4 ;??
MOVE BIT P1.0 ;??
ADD_ BIT P1.1 ;?
DEC_ BIT P1.2 ;?
ENTER BIT P1.3
T_CLK BIT P1.6
T_IO BIT P1.7
T_RST BIT P1.5
ORG 0000H
LJMP MAIN ; ìøÏòÖ÷3ìDò
ORG 001BH
ORG 0100H
MAIN:
MOV A,#038H
LCALL WRCMD
MOV SP,#30H
LOOP : MOV A,#LCD_SETVISIBLE+4
LCALL WRCMD
MOV A,#00H
MOV R0,#60H
MOV R2,#32
CLR_BUF :MOV @R0,A ;ƬÄúê×μØÖ·Îa60H μÄ32 ¸öRAM ÏÔê¾»o3åμ¥ÔaÇå0
DJNZ R2,CLR_BUF
LCALL SET1302 ;μ÷óÃéèÖÃDS1302 μÄ×ó3ìDò
MOV DPTR,#200
LCALL WTMS
LOOP2: NOP
LCALL GET1302
MOV A,#LCD_CLS ;ÇåLCD ÏÔê¾Æá
LCALL WRCMD ;μ÷óÃÏòLCD D′èëÃüáî(01H) ×ó3ìDò
LCALL WRTIME ;μ÷óÃÏòLCD D′èëê±¼ä×ó3ìDò
MOV DPTR,#800
MOV A,#1
LCALL WTSEC
JB P1.4,LOOP2 ;ÏÔê¾×′ì¬Ôòìø×a
LCALL DELAY ;μ÷óÃÑóê±×ó3ìDò
JB P1.4,LOOP2 ;Ôù′ÎÅD¶Ï
LCALL SW_CE
JMP LOOP2
SW_CE:
PUSH 60H ;
PUSH 61H
PUSH 62H
PUSH 63H
PUSH 64H
PUSH 65H
PUSH 66H
MOV A,#60H
PUSH ACC
SW_C1:
JB MOVE,SW_C2 ;ÅD¶ÏêÇ·ñÎaòÆλ
LCALL DELAY
JB MOVE,SW_C2 ;Ôù′ÎÅD¶Ï
POP ACC
CJNE A,#64H,SW_C11
INC A
INC 20H
SW_C11:
INC A
INC 20H
CJNE A,#67H,SW_C12
MOV A,#60H
MOV 20H,#0
SW_C12:
PUSH ACC
JNB move,$
SW_C2: ;ÅD¶ÏêÇ·ñ¼ó°′¼ü°′ÏÂ
JB ADD_,SW_C3
LCALL DELAY
JB ADD_,SW_C3
POP ACC
MOV R0,A
PUSH ACC
LCALL ADD_1 ;μ÷óð′¼ü¼óò»×ó3ìDò
LCALL WRTIME
JNB ADD_,$
SW_C3: ;ÅD¶ÏêÇ·ñ¼õ°′¼ü°′ÏÂ
JB DEC_,SW_C4
LCALL DELAY
JB DEC_,SW_C4
POP ACC
MOV R0,A
PUSH ACC
LCALL DEC_1 ;μ÷óüõò»×ó3ìDò
LCALL WRTIME
JNB DEC_,$
SW_C4: ;ÅD¶ÏêÇ·ñè·¶¨°′¼ü°′ÏÂ
JB ENTER,SW_C5
LCALL DELAY
JB ENTER,SW_C5
POP ACC
MOV R0,A
POP ACC
POP ACC
POP ACC
POP ACC
POP ACC
POP ACC
POP ACC
PUSH 60H
PUSH 61H
PUSH 62H
PUSH 63H
PUSH 64H
PUSH 65H
PUSH 66H
MOV A,R0
PUSH ACC
JNB ENTER,$
SW_C5: ;ÅD¶ÏêÇéèÖû1êÇÏÔê¾
JNB WORK,SW_C52
LCALL DELAY
JB WORK,SW_C51
SW_C52:
LJMP SW_C1
SW_C51:
POP ACC
POP 66H
POP 65H
POP 64H
POP 63H
POP 62H
POP 61H
POP 60H
MOV 20H,#0
MOV 21H,#10
LCALL SET1302 ;μ÷óÃDS1302D¾Æ¬×ó3ìDò
LCALL DELAY
LCALL GET1302 ;μ÷óÃ′óDS1302D¾Æ¬¶á
RET
ADD_1: ;°′¼ü¼ó·×ó3ìDò¨
NOP
ADD_MIAO:
CJNE R0,#60H,ADD_FEN
MOV A,@R0
MOV B,#1
ADD A,B
DA A
MOV @R0,A
CJNE A,#60H,RETURN
MOV @R0,#0
LJMP RETURN
ADD_FEN:
CJNE R0,#61H,ADD_SHI
MOV A,@R0
MOV B,#1
ADD A,B
DA A
MOV @R0,A
CJNE A,#60H,RETURN
MOV @R0,#0
LJMP RETURN
ADD_SHI:
CJNE R0,#62H,ADD_RI
MOV A,@R0
MOV B,#1
ADD A,B
DA A
MOV @R0,A
CJNE A,#24H,RETURN
MOV @R0,#0
LJMP RETURN
ADD_RI:
CJNE R0,#63H,ADD_YUE
MOV A,@R0
MOV B,#1
ADD A,B
DA A
MOV @R0,A
CJNE A,#32H,RETURN
MOV @R0,#1
LJMP RETURN
ADD_YUE:
CJNE R0,#64H,ADD_NIAN
MOV A,@R0
MOV B,#1
ADD A,B
DA A
MOV @R0,A
CJNE A,#13H,RETURN
MOV @R0,#1
LJMP RETURN
ADD_NIAN:
CJNE R0,#66H,RETURN
MOV A,@R0
MOV B,#1
ADD A,B
DA A
MOV @R0,A
LJMP RETURN
RETURN:
NOP
RET
DEC_1: ;°′¼ü¼õ
NOP
DEC_MIAO: ;Ãëλ¼õ
CJNE R0,#60H,DEC_FEN
MOV A,@R0
MOV B,#10H
DEC A
DIV AB
MOV A,B
CJNE A,#0FH,DEC_M1
MOV A,@R0
MOV B,#10H
DEC A
DIV AB
CJNE A,#0FH,DEC_M2
MOV @R0,#59H
LJMP DEC_RETURN
DEC_M1:
MOV A,@R0
DEC A
MOV @R0,A
LJMP DEC_RETURN
DEC_M2:
MOV A,@R0
SUBB A,#06H
MOV @R0,A
LJMP DEC_RETURN
DEC_FEN:
CJNE R0,#61H,DEC_SHI
MOV A,@R0
MOV B,#10H
DEC A
DIV AB
MOV A,B
CJNE A,#0FH,DEC_F1
MOV A,@R0
MOV B,#10H
DEC A
DIV AB
CJNE A,#0FH,DEC_F2
MOV @R0,#59H
LJMP DEC_RETURN
DEC_F1:
MOV A,@R0
DEC A
MOV @R0,A
LJMP DEC_RETURN
DEC_F2:
MOV A,@R0
SUBB A,#06H
MOV @R0,A
LJMP DEC_RETURN
DEC_SHI:
CJNE R0,#62H,DEC_RI
MOV A,@R0
MOV B,#10H
DEC A
DIV AB
MOV A,B
CJNE A,#0FH,DEC_S1
MOV A,@R0
MOV B,#10H
DEC A
DIV AB
CJNE A,#0FH,DEC_S2
MOV @R0,#23H
LJMP DEC_RETURN
DEC_S1:
MOV A,@R0
DEC A
MOV @R0,A
LJMP DEC_RETURN
DEC_S2:
MOV A,@R0
SUBB A,#06H
MOV @R0,A
LJMP DEC_RETURN
DEC_RI:
CJNE R0,#63H,DEC_YUE
MOV A,@R0
MOV B,#10H
DEC A
DIV AB
MOV A,B
CJNE A,#0FH,DEC_R1
MOV A,@R0
SUBB A,#07H
MOV @R0,A
LJMP DEC_RETURN
DEC_R1:
MOV A,@R0
DEC A
JZ DEC_R2
MOV @R0,A
LJMP DEC_RETURN
DEC_R2:
MOV @R0,#31H
LJMP DEC_RETURN
DEC_YUE:
CJNE R0,#64H,DEC_NIAN
MOV A,@R0
MOV B,#10H
DEC A
DIV AB
MOV A,B
CJNE A,#0FH,DEC_Y1
MOV A,@R0
SUBB A,#07H
MOV @R0,A
LJMP DEC_RETURN
DEC_Y1:
MOV A,@R0
DEC A
JZ DEC_Y2
MOV @R0,A
LJMP DEC_RETURN
DEC_Y2:
MOV @R0,#12H
LJMP DEC_RETURN
DEC_NIAN:
CJNE R0,#66H,DEC_RETURN
MOV A,@R0
MOV B,#10H
DEC A
DIV AB
MOV A,B
CJNE A,#0FH,DEC_N1
MOV A,@R0
MOV B,#10H
DEC A
DIV AB
CJNE A,#0FH,DEC_N2
MOV @R0,#99H
LJMP DEC_RETURN
DEC_N1:
MOV A,@R0
DEC A
MOV @R0,A
LJMP DEC_RETURN
DEC_N2:
MOV A,@R0
SUBB A,#06H
MOV @R0,A
LJMP DEC_RETURN
DEC_RETURN:
NOP
RET
WRTIME: MOV R0,#LCD_CMD_WR ;LCD ê±¼äÏÔê¾
MOV A,#086H ;LCD μúò»DDÏÔ꾶¨Î»Îa06H,¼′86H=80H+06H
MOVX @R0,A
MOV R0,#LCD_DATA_WR
WRSTR1: CLR A
MOV A,SECOND+2
PUSH ACC
SWAP A
ANL A,#0FH
ORL A,#30H
INC A
MOVX @R0,A ;D¡ê±¸ßλ
LCALL WTBUSY
POP ACC
ANL A,#0FH
ORL A,#30H
MOVX @R0,A ;D¡ê±μíλ
LCALL WTBUSY
MOV A,#2DH ; ÏÔê¾×Ö·û"-"
MOVX @R0,A
LCALL WTBUSY
MOV A,SECOND+1
PUSH ACC
SWAP A
ANL A,#0FH
ORL A,#30H
MOVX @R0,A ;·ÖÖó¸ßλ
LCALL WTBUSY
POP ACC
ANL A,#0FH
ORL A,#30H
MOVX @R0,A ;·ÖÖóμíλ
LCALL WTBUSY
MOV A,#2DH
MOVX @R0,A ;×Ö·û¡±-¡±
LCALL WTBUSY
MOV A,SECOND
PUSH ACC
SWAP A
ANL A,#0FH
ORL A,#30H
MOVX @R0,A ;Ãë¸ßλ
LCALL WTBUSY
POP ACC
ANL A,#0FH
ORL A,#30H
MOVX @R0,A ;Ãëμíλ
LCALL WTBUSY
MOV R0,#LCD_CMD_WR
MOV A,#0C6H ;μú¶tDD¶¨Î»
MOVX @R0,A
MOV R0,#LCD_DATA_WR
MOV A,SECOND+6
PUSH ACC
SWAP A
ANL A,#0FH
ORL A,#30H
MOVX @R0,A
LCALL WTBUSY
POP ACC
ANL A,#0FH
ORL A,#30H
MOVX @R0,A ;Äêμíλ
LCALL WTBUSY
MOV A,#2DH
MOVX @R0,A
LCALL WTBUSY
MOV A,SECOND+4
PUSH ACC
SWAP A
ANL A,#0FH
ORL A,#30H
MOVX @R0,A ;Ô¸ßλ
LCALL WTBUSY
POP ACC
ANL A,#0FH
ORL A,#30H
MOVX @R0,A ;ÔÂμíλ
LCALL WTBUSY
MOV A,#2DH
MOVX @R0,A ;×Ö·û"-"
LCALL WTBUSY
MOV A,SECOND+3
PUSH ACC
SWAP A
ANL A,#0FH
ORL A,#30H
MOVX @R0,A ;èÕ¸ßλ
LCALL WTBUSY
POP ACC
ANL A,#0FH
ORL A,#30H
MOVX @R0,A ;èÕμíλ
LCALL WTBUSY
WRSTR2: RET
WRCMD : MOV R0,#LCD_CMD_WR
MOVX @R0,A
JMP WTBUSY
WTBUSY: MOV R1,#LCD_BUSY_RD
MOVX A,@R1
JB ACC.7,WTBUSY
RET
WTSEC : PUSH ACC ; μè′y(A)Ãë
LCALL WTMS
POP ACC
DEC A
JNZ WTSEC
RET
; Ñóê±μè′y(DPTR) oáÃë
WTMS : XRL DPL,#0FFH
XRL DPH,#0FFH
INC DPTR
WTMS1: MOV TL0,#09CH
MOV TH0,#0FFH
MOV TMOD,# 1
SETB TCON.4
WTMS2 : JNB TCON.5,WTMS2
CLR TCON.4
CLR TCON.5
INC DPTR
MOV A,DPL
ORL A,DPH
JNZ WTMS1
RET
DELAY: MOV R7,#4 ;1msÑóê±×ó3ìDò
DELAY1: MOV R6,#125
DJNZ R6,$
DJNZ R7,DELAY1
RET
SET1302:CLR T_RST
CLR T_CLK
SETB T_RST
MOV B,#8EH
LCALL RTINPUTBYTE
MOV B,#00H
LCALL RTINPUTBYTE
SETB T_CLK
CLR T_RST
MOV R0,#SECOND
MOV R7,#7
MOV R1,#80H
S13021: CLR T_RST
CLR T_CLK
SETB T_RST
MOV B,R1
LCALL RTINPUTBYTE
MOV A,@R0
MOV B,A
LCALL RTINPUTBYTE
INC R0
INC R1
INC R1
SETB T_CLK
CLR T_RST
DJNZ R7,S13021
CLR T_RST
CLR T_CLK
SETB T_RST
MOV B,#8EH
LCALL RTINPUTBYTE
MOV B,#80H
LCALL RTINPUTBYTE
SETB T_CLK
CLR T_RST
RET
GET1302: MOV R0,#SECOND
MOV R7,#7
MOV R1,#81H
G13021: CLR T_RST
CLR T_CLK
SETB T_RST
MOV B,R1
LCALL RTINPUTBYTE
LCALL RTOUTPUTBYTE
MOV @R0,A
INC R0
INC R1
INC R1
SETB T_CLK
CLR T_RST
DJNZ R7,G13021
RET
RTINPUTBYTE: MOV R4,#8
INBIT1: MOV A,B
RRC A
MOV B,A
MOV T_IO,C
SETB T_CLK
CLR T_CLK
DJNZ R4,INBIT1
RET
RTOUTPUTBYTE :MOV R4,#8
OUTBIT1: MOV C,T_IO
RRC A
SETB T_CLK
CLR T_CLK
DJNZ R4,OUTBIT1
RET
END
|