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

1602液晶屏驱动源程序12

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

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


;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,#00H
MOV TL0,#00H
MOV TH0,#00H
SETB EA
SETB ET0
CLR TR0
MOV R7,#250
CLR 0FH ;if 2s time reach,setb 0fh.


MOV SP,#70H
START: 
LCALL INITIAL
MOV R0,#08FH
MOV A,R0
LCALL WRITE_INSTRUCTION
MOV DPTR,#TAB1
LCALL KEY
TT:
MOV 50H,A 
MOVC A,@A+DPTR
LCALL WRITELCDDATA

DEC R0
MOV A,R0
LCALL WRITE_INSTRUCTION
LCALL KEY
JBC 0FH,TT
CLR TR0
MOV TL0,#00H
MOV TH0,#00H
MOV R7,#250

CJNE A,50H,TT 
MOV DPTR,#TAB2
MOVC A,@A+DPTR 
LCALL WRITELCDDATA
AJMP START

INSERS:
MOV TL0,#00H
MOV TH0,#00H
DJNZ R7,L0
MOV R7,#250
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:
MOV A,#00111000B
LCALL WRITE_INSTRUCTION
MOV A,#00001100B
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
SETB TR0 ;begin count time.

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