You are on page 1of 27

LCD and Keypad

LCD and Keypad Page 1


LCD

Liquid-Crystal Display (LCD)

• LCDs can add a lot to your application in


terms of providing a useful interface for
the user, debugging an application, or
just given it a professional look.

• LCD can be used to display characters


and graphics. The most common type of
LCD controller is the Hitachi 44780,
which provides a relatively simple
interface between a processor and an
LCD.

LCD and Keypad Page 2


LCD

LCD and Keypad Page 3


LCD

LCD Pin Descriptions

• In this class, we will use LCD from the


Optrex, DMC16207. which use Hitachi
44780 for LCD controller. The LCD pin
description and assignment for various
LCDs from Optrex are shown on the
next page.

• While Vcc and Vss provide +5V and


Ground, respectively, VEE is used for
controlling LCD contrast.

LCD and Keypad Page 4


LCD
Pin Description of DMC 16207 LCD

Pin Symbol I/O Description


1 Vss -- Ground
2 VCC -- +5V power supply
3 VEE -- Power supply source to control
contrast
4 RS I Register select: RS = 0 to select
instruction command register, RS
= 1 to select data register
5 R/W I Read/ write: R/W= 0 for write ,
R/E =1 for read
6 E I Enable
7 DB0 I/O The 8-bit data bus
8 DB1 I/O The 8-bit data bus
9 DB2 I/O The 8-bit data bus
10 DB3 I/O The 8-bit data bus
11 DB4 I/O The 8-bit data bus
12 DB5 I/O The 8-bit data bus
13 DB6 I/O The 8-bit data bus
14 DB7 I/O The 8-bit data bus

Pin Positions for Various LCDs from Optrex

14 13 2 1

DMC16106B
DMC16207
DMC16230
DMC20215

LCD and Keypad Page 5


LCD

• There are two very important registers


inside the LCD. The RS pin is used for
their selection as follows.

• If RS = 0, the instruction command code


register is selected, allowing the user to
send a command such as clear display,
cursor at home, etc.

• If RS = 1, the data register is selected,


allowed the user to send data to be
displayed on the LCD

• R/W input allows the user to write


information to the LCD or read
information from it. R/W = 0 when
writing, R/W = 1 when reading. For most
applications, there really is no reason to
read from the LCD. R/W is usually tied
to ground.

LCD and Keypad Page 6


LCD

• The enable pin, E, is used by the LCD to


latch information presented to its data
pins. When data is supplied to data
pins, a high-to-low pulse must be applied
to this pin in order for the LCD to latch in
the data present at the data pins. This
pulse must be a minimum of 450
nanosecond for data and 1.64 millisecond
for command.

• The 8-bit data pins, DB7-DB0, are used to


send information (data-ASCII code, or
LCD command) to the LCD. To display
letters or numbers, we send ASCII
codes for the letter s A-Z, a – z, and
numbers 0-9 to these pins while making
RS = 1.

• To send instruction command codes, the


following command codes can be sent to
LCD while making RS = 0.
LCD and Keypad Page 7
LCD

LCD Command Codes

Code Command to LCD Instruction


(hex) Register
01 Clear display screen
02 Return home
04 Decrement cursor (shift cursor to
left)
06 Increment cursor (shift cursor to
right)
05 Shift display right
07 Shift display left
08 Display off, cursor off
0A Display off, cursor on
0C Display on, cursor off
0E Display on, cursor on
0F Display on, cursor blinking
10 Shift cursor position to left
14 Shift cursor position to right
18 Shift the entire display to the left
1C Shift the entire display to the right
C0 Force cursor to beginning of 2nd line
38 2 lines and 5x7 matrix

LCD and Keypad Page 8


LCD

Send Commands to LCDs

• To send any of the commands to the LCD,


make RS = 0 and send a high-to-low pulse
to the E pin to enable the internal latch of
the LCD. According to the timing
diagram of the LCD, you have to do the
following procedure. Note that we will
send a command data before the high-to-
low pulse on the E pin.

1. Send a command via DB7-DB0.


2. Clear RS = 0 (command)
3. Set E = 1. (Do not send RS = 0 and E
=1 at the same time! Must be 2 steps.)
4. Delay 5 ms.
5. Clear E = 0.
6. Delay 5 ms.

LCD and Keypad Page 9


LCD

• The following timing will send command,


0x38, to LCD. This command will set the
LCD to 2 lines, 5 × 7 matrix.

DB7-0
c
command = 0x38

d
RS

e g
E 5 ms
f

LCD and Keypad Page 10


LCD

• Before sending data to LCD, you must


initialize the LCD with the following
commands:

1. Set the LCD to 2 lines, 5 × 7 matrix.


(LCD Command 0x38)

2. Clear LCD (LCD’s command 0x01)

3. Set LCD’s cursor to home position


(LCD’s command 0x02)

4. Turn LCD’s display on, and set cursor


to be on, off, or blinking (LCD’s
command 0x0C, or 0x0E, or 0x0F).
Pick one that you like,

LCD and Keypad Page 11


LCD

Send Data to LCDs

• After the LCD is initialized by series of


commands. In order to send data to the
LCD to be displayed, we must set RS = 1
(data) and send a high-to-low pulse to the
E pin to enable the internal latch of the
LCD. According to the timing diagram
of the LCD, you have to do the
following procedure. Note that we will
send a data to be displayed before the
high-to-low pulse on the E pin.

1. Send a data to be displayed via DB7-


DB0.
2. Set RS = 1 (data).
3. Set E = 1.
4. Delay 5 ms.
5. Clear E = 0.
6. Delay at least 10 ms.

LCD and Keypad Page 12


LCD

• The following timing diagram will send


ASCII character E (0x45) to LCD.

DB7-0
c
ASCII E = H’45’

d
RS

e g
E 5 ms
f

LCD and Keypad Page 13


Keypad

Key Pad

• Along with LCD, keypad is the most


widely used input/output devices of the
microcontroller, and a basic under-
standing of them is essential.

• Keypads come in a variety of sizes from


couple of keys to 32 keys or more. We
will use the 16-key keypad from Grayhill.

LCD and Keypad Page 14


Keypad

LCD and Keypad Page 15


Keypad

• At the lowest level, keypads are


organized in a matrix of rows and
columns.

• The keypad shown on the next page has


16 switches arrange in a 4-row by 4-
column matrix.

• Pressing a key closes a switch which


electrically connects one row to one
column.

• Each keypad switch in the matrix is


connected to the microcontroller as
shown.

LCD and Keypad Page 16


Keypad

COLUMNS

ROWS

COLUMN
+5 VDC

10K

Output Port ROW

220 Ω
If output port line is 0,
input Port switch closure will assert
input line low = 0

LCD and Keypad Page 17


Keypad

• Figure on the next page shows a 4 × 4


matrix switches connected to two ports.

• The rows are connected to Port A


(RA<3:0>) and the columns are
connected to Port B (RB <3:0>).

• If no key has been pressed, reading the


input port will yield 1s for all columns
since they are all connected to high
(Vcc).

• If all the rows are grounded and a key is


pressed one of the columns will have 0
since the key pressed provided the path
to ground.

• It is the function of the microcontroller to


scan the keypad continuously to detect
and identify the key pressed.

LCD and Keypad Page 18


Keypad

+5 VDC

10K

220 Ω

RA0

RA1
ROWS

RA2

RA3

RB3 RB2 RB1 RB0

COLUMNS

LCD and Keypad Page 19


Keypad

Grounding rows and reading the columns

• To detect the key pressed, the


microcontroller grounds all rows by
providing 0 to the output latch, and then
it reads the columns.

• If the data read from the column is


RB<3:0> = 1111, no key has been
pressed and the process continues until a
key press is detected.

• However, if one of the column bits has a


zero, this means that a key press is
occurred. For example, if RB<3:0> =
1101, this means that a key in RB1 column
has been pressed.

LCD and Keypad Page 20


Keypad

• After a key press is detected, the


microcontroller will go through the
process of identifying the key.

• Starting with the top row, the


microcontroller grounds it by providing a
low to row RA0 only; then it reads the
columns. If the data read is all 1s, no key
in that row is activated and the process is
moved to the next row.

• It grounds the next row, reads the


columns, and check for any zero. This
process continues until the row is
identified. After identification of the row
in which the key has been pressed the
next task is to find out which column the
press key belongs to. This should be easy
since the microcontroller knows at any
time which row and column is being
accessed.
LCD and Keypad Page 21
Keypad

• The flow chart for scan key is showed


on the next page.

• Note that after the key press detect, the


key must be debounced, which is
normally accomplished with a short time
delay from 10-20 ms. The 20 ms delay
will be used for the Grayhill’s keypad
since the contact bounce is about 12 ms.

• The delay time serves two functions: (a) it


ensures that the first key press detection
was not an erroneous one due to a spick
noise, and (b) the 20 ms delay prevents
the same key press from being interpreted
as multiple key press.

LCD and Keypad Page 22


Keypad

LCD and Keypad Page 23


Keypad

Grayhill Series 96 Keypad

• Grayhill Series 96 Keypad comes in


different sizes and options. It is available
in 3 × 4 and 4 × 4 matrix as shown on the
next page.

• The options are included Backlit/Non-


backlit, Shielded/Non-Shielded, Front
Panel Mount/Rear Panel Mount, Black
legends/white legends.

• The contact bounce is 12 milliseconds.

LCD and Keypad Page 24


Keypad

LCD and Keypad Page 25


Keypad

• Pin diagram and the matrix code of


Standard 4 × 4 keypad are shown on the
next page.

• Pin 1, 2, 3, and 4 can be used as rows and


pin 5, 6, 7, and 8 can be used as columns.

LCD and Keypad Page 26


Keypad

LCD and Keypad Page 27

You might also like