128X64 LCD接口51汇编程序
; 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
;2005年9月 马良 测试通过 欢迎大家讨论 QQ:8297327 13087664858
;*****************************************************
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
MOV A,#55H
CALL LCDFILL
MOV DPTR,#STRING1
CALL PUTSTR
CALL PUTSTR
JMP MAIN
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:
MOV R6,#2
DLY_PA: MOV R5,#0
DLY_PB: MOV R4,#0
DJNZ R4,$
DJNZ R5,DLY_PB
DJNZ R6,DLY_PA
RET
GETSTRCHAR:
GSC_PA:
CLR A
MOVC A,@A+DPTR
INC DPTR
MOV B,A
INC A
CLR C
JZ GSC_LAX
CLR A
MOVC A,@A+DPTR
INC DPTR
SETB C
GSC_LAX:
RET
PUTSTR:
CALL DELAY
CALL GETSTRCHAR
PUSH DPL
PUSH DPH
JNC PSR_LAX
JNB B.7,PSR_LBY
;CHINESE:
CALL HZKPOS
CALL PUTCHARDOT
CALL PUTCHARDOT
JMP PSR_LBX
PSR_LBY:
;ENGLISH:
CALL HZKPOS
CALL PUTCHARDOT
PSR_LBX:
POP DPH
POP DPL
JMP PUTSTR
PSR_LAX:POP DPH
POP DPL
RET
PUTCHARDOT:
MOV R7,#8
PAC_PA:
CLR A
MOVC A,@A+DPTR
CALL LCDWRITE
INC YPOS
INC DPTR
CLR A
MOVC A,@A+DPTR
CALL LCDWRITE
DEC YPOS
INC DPTR
CALL CUSORNEXT
MOV A,XPOS
JNZ PAC_LAX
INC YPOS
PAC_LAX:
DJNZ R7,PAC_PA
RET
HZKPOS:
MOV R2,#5
HTP_PA:
CLR C
RLC A
XCH A,B
RLC A
XCH A,B
DJNZ R2,HTP_PA
MOV DPTR,#HZKDOT
ADD A,DPL
MOV DPL,A
MOV A,B
ADDC A,DPH
MOV DPH,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 ;XPOS128则循环(128列)
MOV A,YPOS
JNZ LFL_PB ;YPOS8则循环(8页)
RET
LCDWRITE: ;定位并写数据子程序
CALL LCDPOS ;内部写数指针定位
CALL LCDWD ;写数据
RET
CUSORNEXT:
ANL YPOS,#7
INC XPOS
MOV A,XPOS
JNB ACC.7,CNT_LAX
MOV XPOS,#0
INC YPOS
MOV A,YPOS
ANL A,#0F8H
JZ CNT_LAX
MOV YPOS,#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
DB 0e4H,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
DB 0daH, 08H, 06H, 07H, 00H, 00H,0feH,0ffH
DB 92H, 42H, 92H, 24H, 92H, 08H, 92H, 14H
DB 0ffH, 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
DB 0d2H, 3fH, 9aH, 00H, 12H, 40H, 02H, 80H
DB 0ffH, 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
- 利用FPGA实现外设通信接口之: 典型实例-字符LCD接口的设计与实现(06-05)
- 51单片机和图形LCD接口技术的实现(01-16)
- PWM控制LED渐亮渐灭的51汇编程序(10-16)
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)