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

1602液晶屏驱动源程序3

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

<>如果您在学习中遇到任何问题清参加51测试网(深圳学林电子有限公司)论坛讨论, 让更多的朋友帮助你!

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



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



;lcd display program
RS BIT P2.6
R_W BIT P2.5
ENABLE BIT P2.7 
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
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:
MOV A,#00011000B ;
LCALL WRITE_INSTRUCTION
INC 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,#00011000B ;
;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