;R0-------ADDRESS
;R1-------DATA
;R2,R4----KEY SCAN
;R3
;R5,R6----DELAY
;R7-------TIMER INTERRUPT COUNTER
;LCD display program
RS BIT P2.7
R_W BIT P2.6
ENABLE BIT P2.5
LCDDATA DATA P1
;******************************************
ORG 0000H
AJMP MAIN
ORG 000BH
AJMP INSERS
ORG 0060H
MAIN:
MOV TMOD,#01H
MOV TL0,#0B0H
MOV TH0,#3CH
SETB EA
SETB ET0
CLR TR0
MOV R7,#40 ;2S COUNTER
CLR 0FH ;if 2s time reach,setb 0fh.
CLR 10H ;
MOV SP,#70H
START:
LCALL INITIAL
MOV R0,#8FH
MOV A,R0
LCALL WRITE_INSTRUCTION
LCALL KEY
MOV R1,A
;TT:
JBC 0FH,TTL1
TT01:
MOV DPTR,#TAB1
TT02:
MOV A,R0
LCALL WRITE_INSTRUCTION
MOV A,50H
TTL2:
MOVC A,@A+DPTR
LCALL WRITELCDDATA
MOV TL0,#0B0H
MOV TH0,#3CH
MOV R7,#40
SETB TR0
LCALL KEY
CJNE A,50H,TTL3
JBC 0FH,TTL3
CPL 10H
JNB 10H,TT01
MOV 50H,A
MOV DPTR,#TAB2
AJMP TT02
TTL3: MOV 50H,A
CLR 10H
AJMP TTL1
TTL1:
DEC R0
MOV DPTR,#TAB1
MOV A,50H
AJMP TTL2
INSERS:
MOV TL0,#0B0H
MOV TH0,#3CH
DJNZ R7,L0
MOV R7,#40
SETB 0FH
CLR TR0 ;2S time reach,stop count time.
L0:
RETI
CLS:
PUSH ACC
MOV A,#01H
LCALL WRITE_INSTRUCTION
POP ACC
RET
;**********************************************
;initial
;Set some parameters.
;please reference the techonology material.
;**********************************************
INITIAL:
MOV A,#00111000B ;8BIT,2LINE,5*7
LCALL WRITE_INSTRUCTION
MOV A,#00001100B ;DISPLAY ON,CURSOR OFF,NO BLINK
LCALL WRITE_INSTRUCTION
MOV A,#00000100B ;
LCALL WRITE_INSTRUCTION
RET
CHECKBUSY:
PUSH ACC
CHECKBUSYLOOP:
CLR ENABLE
SETB R_W
CLR RS
SETB ENABLE
MOV A,LCDDATA
CLR ENABLE
JB ACC.7,CHECKBUSYLOOP
POP ACC
LCALL DELAY1
RET
WRITE_INSTRUCTION:
LCALL CHECKBUSY
CLR ENABLE
CLR R_W
CLR RS
SETB ENABLE
MOV LCDDATA,A
CLR ENABLE
RET
WRITELCDDATA:
LCALL CHECKBUSY
CLR ENABLE
CLR R_W
SETB RS
SETB ENABLE
MOV LCDDATA,A
CLR ENABLE
RET
DELAY1:
MOV R5,#08H
L4:
MOV R6,#0F8H
L5:
DJNZ R6,L5
DJNZ R5,L4
RET
KEY: LCALL KS
JNZ K1
LCALL DELAY2
AJMP KEY
K1: LCALL DELAY2
LCALL DELAY2
LCALL KS
JNZ K2
AJMP KEY
K2: MOV R2,#0DFH
MOV R4,#00H
K3: MOV P3,R2
L6: JB P3.0,L1
MOV A,#00H
AJMP LK
L1: JB P3.1,L2
MOV A,#03H
AJMP LK
L2: JB P3.2,L3
MOV A,#06H
AJMP LK
L3: JB P3.3,NEXT
MOV A,#09H
LK: ADD A,R4
PUSH ACC
K4: LCALL DELAY2
LCALL KS
JNZ K4
POP ACC
RET
NEXT:
INC R4
MOV A,R2
JNB ACC.7,KEY
RL A
MOV R2,A
AJMP K3
KS: MOV P3,#0FH
MOV A,P3
XRL A,#0FH
RET
DELAY2:
MOV R5,#08H
L7: MOV R6,#0FAH
L8: DJNZ R6,L8
DJNZ R5,L7
RET
TAB1:DB 31H,32H,33H,34H,35H,36H,37H,38H,39H
DB 41H,30H,42H
TAB2:DB 43H,44H,45H,46H,47H,48H,49H,4AH,4BH
DB 4CH,4DH,4EH
END
『本文转载自网络,版权归原作者所有,如有侵权请联系删除』