51测试网 单片机教程XL2000开发板 单片机学习 自制编程器 单片机资料 软件下载 电子技术产品介绍如何购买 进入论坛

1602液晶屏驱动源程序5

察看本站的产品全家福和网站介绍      本站产品正式流水线工艺生产情况        

<>12232驱动程序   <>12832驱动程序   <>12864驱动源程序   <>1602 驱动程序   <>0802 液晶驱动程序  <>回液晶主页


;LCD 16KEY FIND 


;R0-------ADDRESS 
;R1-------DATA
;R2,R4----KEY SCAN
;R3
;R5,R6----DELAY
;R7-------TIMER INTERRUPT COUNTER



;lcd display program
RS BIT P3.0
R_W BIT P3.1
ENABLE BIT P3.2 
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
MOV 12H,#16 ;

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

LOOP:
LCALL INITIAL
LCALL KEY
MOV 50H,A 
CJNE A,#0BH,TT16
AJMP TT04
TT16:
CJNE A,#0AH,TT05
AJMP TT15
TT05: 
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 A,#00010000B

LCALL WRITE_INSTRUCTION

MOV TL0,#0B0H
MOV TH0,#3CH
MOV R7,#40

SETB TR0

LCALL KEY
CJNE A,#0BH,TT17 ;
AJMP TT04
TT17: 
CJNE A,#0AH,TT06
AJMP TT15
TT06: CJNE A,50H,TTL3

JBC 0FH,TTL3

CPL 10H
JNB 10H,TT03
MOV 50H,A
MOV DPTR,#TAB2
AJMP TT02
TT03: MOV DPTR,#TAB1
MOV 50H,A
AJMP TT02
TTL3: MOV 50H,A
CLR 10H
AJMP TTL1

TTL1:
MOV A,#00011000B
LCALL WRITE_INSTRUCTION
INC R0
;MOV A,#00010100B
MOV DPTR,#TAB1
AJMP TT02

TT04: 


MOV A,#00010000B
LCALL WRITE_INSTRUCTION
DEC 12H
MOV A,12H
JNZ TT07
MOV 12H,#16
MOV R1,#16
TT13: MOV A,#00010100B
LCALL WRITE_INSTRUCTION
DJNZ R1,TT13 
MOV R1,#16
AJMP LOOP


TT07: LCALL KEY
CJNE A,#0BH,TT18
AJMP TT04
TT18: 
CJNE A,#0AH,TT11
AJMP TT15 
TT11: MOV 0FH,#00H
MOV 11H,#00H
;CLR TR0

MOV 51H,A
MOV DPTR,#TAB1
TT10: MOV A,51H
MOVC A,@A+DPTR
LCALL WRITELCDDATA
MOV A,#00010000B
LCALL WRITE_INSTRUCTION
MOV TL0,#0B0H
MOV TH0,#3CH
MOV R7,#40 
SETB TR0
LCALL KEY
CJNE A,#0BH,TT19
AJMP TT04
TT19:
CJNE A,#0AH,TT12
AJMP TT15
TT12: CJNE A,51H,TT09
JBC 0FH,TT09
CPL 11H
JNB 11H,TT08
MOV DPTR,#TAB2
MOV 51H,A
AJMP TT10
TT09: MOV 11H,#00H
MOV DPTR,#TAB1
MOV 51H,A
AJMP TT10
TT08: MOV DPTR,#TAB1
MOV 51H,A
AJMP TT10
TT15:
MOV A,#00000101B
LCALL WRITE_INSTRUCTION 

MOV A,#20H
LCALL WRITELCDDATA

; MOV A,#00011100B
; LCALL WRITE_INSTRUCTION 
; MOV A,#10H
;LCALL WRITE_INSTRUCTION
AJMP LOOP
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,#00001111B ;DISPLAY ON,CURSOR OFF,NO BLINK
LCALL WRITE_INSTRUCTION
;MOV A,#00000111B ;
;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,#0EFH
MOV R4,#00H
K3: MOV P0,R2
L6: JB P0.0,L1 
MOV A,#00H
AJMP LK
L1: JB P0.1,L2
MOV A,#04H
AJMP LK
L2: JB P0.2,L3 
MOV A,#08H
AJMP LK
L3: JB P0.3,NEXT
MOV A,#0CH
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 P0,#0FH
MOV A,P0
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 30H
TAB2:DB 41H 42H 43H,44H,45H,46H,47H,48H,49H,4AH,4BH
DB 4CH,4DH,4EH

END