LCD Keypad Interfacing
LCD Keypad Interfacing
INTERFACE
1
LCD INTERFACE
Display units are the most important output devices
in embedded projects and electronics products.
4
LCD INTERFACE
❑
𝑾
5
LCD INTERFACE
6
LCD INTERFACE
7
LCD INTERFACE
The 216 LCD has two built in registers namely data
register and command register.
Command Register - stores the command
instructions given to the LCD. A command is an
instruction given to LCD to do a predefined task
like initializing, clearing the screen, setting the
cursor position, controlling display etc.
9
LCD INTERFACE
For programming LCD follow these steps:
• STEP1: Initialization of LCD.
• STEP2: Sending command to LCD.
• STEP3: Writing the data to LCD.
LCD
port 1
pulse
RET
16
LCD INTERFACE
becomes 0
RET
END
17
LCD INTERFACE
Write an 8051 assembly language program to display
the message “HELLO” on LCD display using DPTR.
; P1.0-P1.7=D0-D7, P2.0=RS, P2.1= , P2.2=E
ORG 0000H
MOV DPTR, #MYCOM
C1: CLR A
MOVC A,@A+DPTR
ACALL COMNWRT
ACALL DELAY
INC DPTR
JZ SEND_DAT
SJMP C1
18
LCD INTERFACE
SEND_DAT:
D1: CLR A
MOVC A,@A+DPTR
ACALL DATAWRT
ACALL DELAY
INC DPTR
JZ AGAIN
SJMP D1
19
LCD INTERFACE
COMNWRT: ; send command to
LCD
time
RET
21
LCD INTERFACE
DELAY: MOV R3, #250 ; 50 or higher for
fast CPUs
RET
ORG 300H
23
KEYPAD INTERFACE
Keyboards are organized in a matrix of rows and
columns
The CPU accesses both rows and columns through
ports
When a key is pressed, a row and a column make
contact
25
KEYPAD INTERFACE
25
KEYPAD INTERFACE
It is the function of the microcontroller to scan the
keyboard continuously to detect and identify the key
pressed
31
KEYPAD INTERFACE
32
KEYPAD INTERFACE
32
HAPPENS IN FOUR STEPS
First, when no buttons are pressed, all of the column pins
are held HIGH
32
KEYPAD INTERFACE
When a button is pressed, the column pin is pulled LOW since the current
from the HIGH column flows to the LOW row pin
32
KEYPAD INTERFACE
The microcontroller now knows which column the button is in, so now it
just needs to find the row the button is in
It does this by switching each one of the row pins LOW, and at the same
time reading all of the column pins to detect which column pin goes to
LOW
32
KEYPAD INTERFACE
When the column pin goes LOW again, the microcontroller has found the
row pin that is connected to the button
32
2x2 Keypad Program
Write an ASM program to send the ASCII code for pressed
key to P0
P1.0-P1.1 connected to rows, P2.0-P2.1 to column
2x2 Keypad Program
ORG 0030H
MOV P2,#0FFH ;Make P2 an input port
MATCH: CLR A
MOVC A, @A+DPTR
MOV P0, A
LJMP K1 ;Loop
2x2 Keypad Program
ORG 300H
KCODE0: DB ‘1',‘0' ;ROW 0
KCODE1: DB ‘3',‘2' ;ROW 1
END
KEYPAD INTERFACE
Keyboard Program
;keyboard subroutine. This program sends the ASCII code for
pressed key to P0
;P1.0-P1.3 connected to rows, P2.0-P2.3 to column
MOV P2,#0FFH ;make P2 an input port
K1: MOV P1,#0 ;ground all rows at once
MOV A,P2 ;read all col(ensure keys open)
ANL A,00001111B ;masked unused bits
CJNE A,#00001111B,K1 ;till all keys release
KEYPAD INTERFACE
MOV A,P2 ;check key closure
ANL A,00001111B ;mask unused bits
CJNE A,#00001111B,OVER1 ;key pressed,
find row
SJMP K2 ;if none, keep polling
KEYPAD INTERFACE
OVER1: MOV P1, #11111110B ;ground row 0
MOV A,P2 ;read all columns
ANL A,#00001111B ;mask unused bits
CJNE A,#00001111B,ROW_0 ;key row 0, find col.
MOV P1,#11111101B ;ground row 1
MOV A,P2 ;read all columns
ANL A,#00001111B ;mask unused bits
CJNE A,#00001111B,ROW_1 ;key row 1, find col.
MOV P1,#11111011B ;ground row 2
KEYPAD INTERFACE
MOV A,P2 ;read all columns
ANL A,#00001111B ;mask unused bits
CJNE A,#00001111B,ROW_2 ;key row 2, find col.
MOV P1,#11110111B ;ground row 3
MOV A,P2 ;read all columns
ANL A,#00001111B ;mask unused bits
CJNE A,#00001111B,ROW_3 ;key row 3, find col.
LJMP K2 ;if none, false input,
repeat
KEYPAD INTERFACE
ROW_0: MOV DPTR,#KCODE0 ;set
DPTR=start of row 0
SJMP FIND ;find col. Key belongs to
ROW_1: MOV DPTR,#KCODE1 ;set
DPTR=start of row
SJMP FIND ;find col. Key belongs to
ROW_2: MOV DPTR,#KCODE2 ;set
DPTR=start of row 2
SJMP FIND ;find col. Key belongs to
KEYPAD INTERFACE
INC DPTR ;point to next col. addr
SJMP FIND ;keep searching
MATCH: CLR A ;set A=0 (match is found)
MOVC A,@A+DPTR ;get ASCII from table
MOV P0,A ;display pressed key
LJMP K1