|
发表于 2010-1-23 19:33:35
|
显示全部楼层
回复【1楼】depaul123
-----------------------------------------------------------------------
********89C51引脚定义********
RS BIT P3.3
R_W BIT P3.4
E BIT P3.5
DB0_DB7 EQU P1
;*******程序开始******
ORG 0000H
LJMP MAIN
ORG 030H
MAIN: MOV SP,#60H
LCALL INITIAL
LCALL CLS
MOV R4,#64
LCALL SAVE_CGRAM
MOV A,#10000000B
LCALL WRITE_COM
MOV R1,#4
CLR A
LCALL DIS_MAP
MOV A,#11000000B
LCALL WRITE_COM
MOV R1,#4
MOV A,#4
LCALL DIS_MAP
MOV A,#10000100B
LCALL WRITE_COM
MOV DPTR,#LINE0
LCALL DISP
MOV A,#11000100B
LCALL WRITE_COM
MOV DPTR,#LINE1
LCALL DISP
SJMP $
;*******显示字符串到LCM子程序********
DISP: PUSH ACC
DISP_LOOP: CLR A
MOVC A,@A+DPTR
JZ END_DISP
LCALL WRITE_DATA
INC DPTR
SJMP DISP_LOOP
END_DISP: POP ACC
RET
;*******显示图形子程序*****
DIS_MAP:LCALL WRITE_DATA
INC A
DJNZ R1,DIS_MAP
RET
;****** 启动LCM子程序******
INITIAL:MOV A,#00111000B
LCALL WRITE_COM
MOV A,#00001100B
LCALL WRITE_COM
MOV A,#00000110B
LCALL WRITE_COM
RET
;******查询忙碌标志信号子程序******
CHECK_BUSY: PUSH ACC
BUSY_LOOP: CLR E
SETB R_W
CLR RS
SETB E
MOV A, DB0_DB7
CLR E
JB ACC.7,BUSY_LOOP
POP ACC
LCALL DEL
RET
;****** 写指令到LCM子程序******
WRITE_COM: LCALL CHECK_BUSY
CLR E
CLR RS
CLR R_W
SETB E
MOV DB0_DB7,A
CLR E
RET
;****** 写数据到LCM子程序******
WRITE_DATA: LCALL CHECK_BUSY
CLR E
SETB RS
CLR R_W
SETB E
MOV DB0_DB7,A
CLR E
RET
;*******清除LCM子程序*******
CLS: MOV A,#00000001B
LCALL WRITE_COM
RET
;****延时2.7mS子程序****
DEL: MOV R6,#5
L1: MOV R7,#248
DJNZ R7,$
DJNZ R6,L1
RET
;*******自定义图形写入CGRAM子程序********
SAVE_CGRAM: MOV A,#01000000B
LCALL WRITE_COM
MOV DPTR,#TAB
CGRAM_LOOP: CLR A
MOVC A,@A+DPTR
LCALL WRITE_DATA
INC DPTR
DJNZ R4, CGRAM_LOOP
RET
;*******字符串*****************************
TAB: DB 03H,04H,08H,10H,1FH,04H,04H,00H
DB 1FH,00H,00H,00H,1FH,00H,00H,00H
DB 1FH,00H,00H,00H,1FH,00H,00H,00H
DB 18H,04H,02H,01H,1FH,04H,04H,00H
DB 04H,04H,04H,04H,04H,07H,00H,00H
DB 0FH,14H,14H,14H,14H,1FH,10H,00H
DB 1EH,05H,05H,05H,05H,1FH,01H,00H
DB 04H,04H,04H,04H,04H,1CH,00H,00H
LINE0: DB " Welcome to ",00H
LINE1: DB " LCD Monitor",00H
END |
|