LCD Keyboard Interfacing: Unit-V
LCD Keyboard Interfacing: Unit-V
LCD Keyboard Interfacing: Unit-V
Unit-V
LCD
KEYBOARD INTERFACING
VSS
VEE
VD
RS
D
R
D
3
1
5
3
6
1
2
4
5
9
7
8
1
1
0
1
1
2
1
3
1
VSS
VDD
VEE
INTERFACING
RS
R
W
E LCD
D0
D1
D2
D3
D4
D5
D6
D7
LCD Operation
LCD Pin Description
LCD Command Codes
LM016L
1
LCD
1
VSS
2
VDD
3
VEE
4
5 RS
RW
6
E
7
8 D0
9 D1
10 D2
11 D3
12 D4
13 D5
14 D6
D7
-
To send any commands to the LCD, make pin RS=0, for data, make RS=1. then
send a high-to-low pulse to the pin to enable the internal latch of theLCD.
; CALLS A TIME DELAY BEFORE SENDING NEXT DATA/COMMAND
; P1.0-P1.7 ARE CONNECTED TO LCD DATA PINS D0-D7
; P2.0 IS CONNECTED TO RS PIN OF LCD
; P2.1 IS CONNECTED TO R/W PIN OF LCD
; P2.2 IS CONNECTED TO E PIN OF LCD
ORG 000H
MOV A, #38H ; init LCD 2 lines, 5 x 7 matrix
ACALL COMNWRT ; call command subroutine
ACALL DELAY ; give LCD some time
MOV A, #0EH ; display on, cursor on
ACALL COMNWRT ; call command subroutine
ACALL DELAY ; give LCD some time
MOV A, #01 ; clear LCD
ACALL COMNWRT ; call command subroutine
ACALL DELAY ; give LCD some time
MOV A, #06H ; shift cursor right
ACALL COMNWRT ; call command subroutine
ACALL DELAY ; give LCD some time
MOV A, #84H ; Cursor at line 1, pos.4
ACALL COMNWRT ; call command subroutine
ACALL DELAY ; give LCD some time
MOV A, #'H'
-
; display letter "N"
ACALL DATAWRT ; call display subroutine
ACALL DELAY ; give LCD some time
MOV A, #'I' ; display letter "O"
ACALL DATAWRT ; call display subroutine
AGAIN: SJMP AGAIN ; stay here
DATA_DISPLAY:
ACALL READY ; is LCD ready
MOV P1, A ; issue data
SETB P2.0 ; RS=1 for data
CLR P2.1 ; R/W=0 to write to LCD
SETB P2.2 ; E=1 for H-to-L pulse
ACALL DELAY ; give LCD some time
CLR P2.2 ; E=0, latch in
RET
READY:
SETB P1.7 ; make P1.7 input port
CLR P2.0 ; RS=0 access command reg
SETB P2.1 ; R/W=1 read command reg
DELAY:
MOV R3, #50 ; 50 or higher for fast CPU,s
HERE2: MOV R4, #255 ; R4=255
HERE1: DJNZ R4, HERE1 ; stay until R4 becomes 0
DJNZ R3, HERE2
RET
BACK:
CLR P2.2 ; E=0 for L-to-H pulse
ACALL DELAY ; give LCD some time
SETB P2.2 ; E=1, L-to-H pulse
JB P1.7, BACK ; stay until busy flag=0
RET
END
LCD Timing for Read
LCD Timing for Write
-
The program shows how to use the MOVC instruction to send data and
commands to an LCD.
; calls a time delay before sending next data/command
; P1.0-P1.7=D0-D7, P2.0=RS, P2.1=R/W, P2.2=E pins
ORG 0
MOV DPTR, #MYCOM
C1: CLR A
MOVC A, @A+DPTR
ACALL COMNWRT ; Call command subroutine
ACALL DELAY ; give LCD sometime
JZ SEND_DAT
INC DPTR
SJMP C1
SEND_DAT:
MOV DPTR, #MYCOM
D1: CLR A
MOVC A, @A+DPTR
ACALL DATAWRT ; Call command subroutine
ACALL DELAY ; give LCD sometime
JZ AGAIN
INC DPTR
SJMP D1
AGAIN: SJMP AGAIN
COMNWRT: -
;send command to LCD
MOV P1, A ; copy register A to port1
CLR P2.0 ; RS=0 for command
CLR P2.1 ; R/W=0 for write
SETB P2.2 ; E=1 for high pulse
ACALL DELAY ; give LCD some time
CLR P2.2 ; E=0 for H-to-L pulse
RET
3
A 1 2 3
B 4 5 6
KEYBOARD C
D
7 8
0
9
#
INTERFACING
1
A 1 2 3
B 4 5 6
C 7 8 9
D
0 #
Keyboard Interfacing
To send any commands to the LCD, make pin RS=0, for data, make RS=1. then
send a high-to-low pulse to the pin to enable the internal latch of theLCD.
; CALLS A TIME DELAY BEFORE SENDING NEXT DATA/COMMAND
; P1.0-P1.7 ARE CONNECTED TO LCD DATA PINS D0-D7
; P2.0 IS CONNECTED TO RS PIN OF LCD
; P2.1 IS CONNECTED TO R/W PIN OF LCD
; P2.2 IS CONNECTED TO E PIN OF LCD