LCD12864汇编语言程序例子
扫描二维码
随时随地手机看文章
12864接口程序(MCS51模拟口线方式)
;***************************************************************************
;连线图: *LCM---8031* *LCM---8031* *LCM------------8031* *LCM----------8031*
; *DB0---P1.0* *DB4---P1.4* *RS-------------P3.0* *CS1----------P3.4*
; *DB1---P1.1* *DB5---P1.5* *RW-------------P3.1* *CS2----------P3.5*
; *DB2---P1.2* *DB6---P1.6* *E--------------P3.3
; *DB3---P1.3* *DB7---P1.7* */RST-----------VDD (详见说明书)
;注:8031的晶振频率为12MHz
;
;**************************************************************************
XPOS EQU 20H ;列方向地址指针(用于LCDPOS子程序)
YPOS EQU 21H ;行方向地址指针(用于LCDPOS子程序)
RSPIN EQU P3.0
RWPIN EQU P3.1 ;
EPIN EQU P3.3 ;
CS1PIN EQU P3.4 ;
CS2PIN EQU P3.5 ;
ORG 0000H
JMP START
START: MOV SP,#60H
MAIN:
CALL LCDRESET
MOVA,#55H
CALLLCDFILL
MOVDPTR,#STRING1
CALLPUTSTR
CALLPUTSTR
JMPMAIN
DELAY400MS:
MOV R0,#20 ;延时子程序(400MS)
DL4_PA: MOV R1,#100
DL4_PB: MOV R2,#100
DJNZ R2,$
DJNZ R1,DL4_PB
DJNZ R0,DL4_PA
RET
DELAY:
MOVR6,#2
DLY_PA:MOVR5,#0
DLY_PB:MOVR4,#0
DJNZR4,$
DJNZR5,DLY_PB
DJNZR6,DLY_PA
RET
GETSTRCHAR:
GSC_PA:
CLRA
MOVCA,@A+DPTR
INCDPTR
MOVB,A
INCA
CLRC
JZGSC_LAX
CLRA
MOVCA,@A+DPTR
INCDPTR
SETBC
GSC_LAX:
RET
PUTSTR:
CALLDELAY
CALLGETSTRCHAR
PUSHDPL
PUSHDPH
JNCPSR_LAX
JNBB.7,PSR_LBY
;CHINESE:
CALLHZKPOS
CALLPUTCHARDOT
CALLPUTCHARDOT
JMPPSR_LBX
PSR_LBY:
;ENGLISH:
CALLHZKPOS
CALLPUTCHARDOT
PSR_LBX:
POPDPH
POPDPL
JMPPUTSTR
PSR_LAX:POPDPH
POPDPL
RET
PUTCHARDOT:
MOVR7,#8
PAC_PA:
CLRA
MOVCA,@A+DPTR
CALLLCDWRITE
INCYPOS
INCDPTR
CLRA
MOVCA,@A+DPTR
CALLLCDWRITE
DECYPOS
INCDPTR
CALLCUSORNEXT
MOVA,XPOS
JNZPAC_LAX
INCYPOS
PAC_LAX:
DJNZR7,PAC_PA
RET
HZKPOS:
MOVR2,#5
HTP_PA:
CLRC
RLCA
XCHA,B
RLCA
XCHA,B
DJNZR2,HTP_PA
MOVDPTR,#HZKDOT
ADDA,DPL
MOVDPL,A
MOVA,B
ADDCA,DPH
MOVDPH,A
RET
LCDFILL: ;LCD整屏显示A的内容
MOV R7,A
MOV YPOS,#0
LFL_PB: MOV XPOS,#0
LFL_PA: MOV A,R7
CALL LCDWRITE ;定位并写数据
CALL CUSORNEXT
MOV A,XPOS
JNZ LFL_PA ;XPOS<128则循环(128列)
MOV A,YPOS
JNZ LFL_PB ;YPOS<8则循环(8页)
RET
LCDWRITE: ;定位并写数据子程序
CALL LCDPOS ;内部写数指针定位
CALL LCDWD ;写数据
RET
CUSORNEXT:
ANLYPOS,#7
INCXPOS
MOVA,XPOS
JNBACC.7,CNT_LAX
MOVXPOS,#0
INCYPOS
MOVA,YPOS
ANLA,#0F8H
JZCNT_LAX
MOVYPOS,#0
CNT_LAX:
RET
LCDPOS: ;内部写数指针定位子程序
PUSH ACC
MOV A,XPOS
JB ACC.6,LPS_LAY
MOV A,YPOS ;XPOS列方向小于64则对CS1操作
ANL A,#07H
ADD A,#0B8H
CALL LCDWC1 ;设页码
MOV A,XPOS
ANL A,#3FH
ORL A,#40H
CALL LCDWC1 ;设列码
JMP LPS_LAX
LPS_LAY:MOV A,YPOS ;XPOS列方向大于等于64则对CS2操作
ANL A,#07H
ADD A,#0B8H
CALL LCDWC2 ;设页码
MOV A,XPOS
ANL A,#3FH
ORL A,#40H
CALL LCDWC2 ;设列码
LPS_LAX:POP ACC
RET
LCDWD: ;送数据子程序
MOV B,A
MOV A,XPOS
JB ACC.6,LWD_LAY
MOV A,B ;XPOS列方向小于64则对CS1操作
CALL LCDWD1
JMP LWD_LAX
LWD_LAY:MOV A,B ;XPOS列方向大于等于64则对CS2操作
CALL LCDWD2
LWD_LAX:
RET
LCDRESET: ;LCD控制器复位
MOV A,#3FH ;打开LCD显示
CALL LCDWC1
CALL LCDWC2
MOV A,#0C0H ;设显示起始行
CALL LCDWC1
CALL LCDWC2
RET
LCDWC1: ;送片1控制字子程序
CALL WAITIDLE1
MOV P1,A
CLR RSPIN ;RS=0 RW=0 CS1=1 E=高脉冲
CLR RWPIN
SETB CS1PIN
SETB EPIN
NOP
CLR EPIN
CLR CS1PIN
RET
LCDWC2: ;送片2控制字子程序
CALL WAITIDLE2
MOV P1,A
CLR RSPIN ;RS=0 RW=0 CS2=1 E=高脉冲
CLR RWPIN
SETB CS2PIN
SETB EPIN
NOP
CLR EPIN
CLR CS2PIN
RET
LCDWD1: ;片1写数据子程序
CALL WAITIDLE1
MOV P1,A
SETB RSPIN ;RS=1 RW=0 CS1=1 E=高脉冲
CLR RWPIN
SETB CS1PIN
SETB EPIN
NOP
CLR EPIN
CLR CS1PIN
RET
LCDWD2: ;片2写数据子程序
CALL WAITIDLE2
MOV P1,A
SETB RSPIN ;RS=1 RW=0 CS2=1 E=高脉冲
CLR RWPIN
SETB CS2PIN
SETB EPIN
NOP
CLR EPIN
CLR CS2PIN
RET
LCDRD1: ;片1读数据子程序
CALL WAITIDLE1
MOV P1,#0FFH
SETB RSPIN ;RS=1 RW=1 CS1=1 E=高电平
SETB RWPIN
SETB CS1PIN
SETB EPIN
NOP
MOV A,P1
CLR EPIN
CLR CS1PIN
RET
LCDRD2: ;片2读数据子程序
CALL WAITIDLE2
MOV P1,#0FFH
SETB RSPIN ;RS=1 RW=1 CS1=2 E=高电平
SETB RWPIN
SETB CS2PIN
SETB EPIN
NOP
MOV A,P1
CLR EPIN
CLR CS2PIN
RET
WAITIDLE1:
MOV P1,#0FFH
CLR RSPIN ;RS=0 RW=1 CS1=1 E=高电平
SETB RWPIN
SETB CS1PIN
SETB EPIN
WT1_PA: NOP
JB P1.7,WT1_PA
CLR EPIN
CLR CS1PIN
RET
WAITIDLE2:
CLR RSPIN ;RS=0 RW=1 CS2=1 E=高电平
SETB RWPIN
SETB CS2PIN
SETB EPIN
WT2_PA: NOP
JB P1.7,WT2_PA
CLR EPIN
CLR CS2PIN
RET
HZKDOT:
;(d3d0H)(有)(8000)
DB 04H, 04H, 04H, 02H, 04H, 01H, 84H, 00H
DB0e4H,0ffH, 3cH, 09H, 27H, 09H, 24H, 09H
DB 24H, 09H, 24H, 49H, 24H, 89H,0f4H, 7fH
DB 24H, 00H, 06H, 00H, 04H, 00H, 00H, 00H
;(cfdeH)(限)(8001)
DB 00H, 00H,0feH,0ffH, 02H, 08H, 22H, 10H
DB0daH, 08H, 06H, 07H, 00H, 00H,0feH,0ffH
DB 92H, 42H, 92H, 24H, 92H, 08H, 92H, 14H
DB0ffH, 22H, 02H, 61H, 00H, 20H, 00H, 00H
;(b9abH)(公)(8002)
DB 00H, 01H, 00H, 01H, 80H, 00H, 40H, 30H
DB 30H, 28H, 0cH, 24H, 00H, 23H,0c0H, 20H
DB 06H, 20H, 18H, 28H, 20H, 30H, 40H, 60H
DB 80H, 00H, 80H, 01H, 80H, 00H, 00H, 00H
;(cbbeH)(司)(8003)
DB 10H, 00H, 10H, 00H, 92H, 3fH, 92H, 10H
DB 92H, 10H, 92H, 10H, 92H, 10H, 92H, 10H
DB0d2H, 3fH, 9aH, 00H, 12H, 40H, 02H, 80H
DB0ffH, 7fH, 02H, 00H, 00H, 00H, 00H, 00H
STRING1:DB 80H, 00H, 80H, 01H, 80H, 02H, 80H, 03H,80H, 00H, 80H, 01H, 80H, 02H, 80H, 03H,80H, 00H, 80H, 01H, 80H, 02H, 80H, 03H,80H, 00H, 80H, 01H, 80H, 02H, 80H, 03H,80H, 00H, 80H, 01H, 80H, 02H, 80H, 03H,80H, 00H, 80H, 01H, 80H, 02H, 80H, 03H,0ffH
STRING2:DB 80H, 00H, 80H, 01H, 80H, 02H, 80H, 03H,80H, 00H, 80H, 01H, 80H, 02H, 80H, 03H,80H, 00H, 80H, 01H, 80H, 02H, 80H, 03H,80H, 00H, 80H, 01H, 80H, 02H, 80H, 03H,80H, 00H, 80H, 01H, 80H, 02H, 80H, 03H,80H, 00H, 80H, 01H, 80H, 02H, 80H, 03H,0ffH
END