Vous êtes sur la page 1sur 4

LCD Keypad : How to use an lcd

and keypadon one 8 bit


microcontroller port.
This LCD keypad project saves you lots of valuable port pins by giving
you twelve input keys and one LCD display on a single 8-bit port.
Normally you need a single port pin for each input key but this method
multiplexes the keys onto 7 pins and shares the port with the LCD.

Bonus 2:
Here are the download links.(One for the schematic files and one for
the schematic tool).
Schematic project files click to download.
ProSchematic tool click to download.

The LCD is a standard HD44780 type and the keypad is a 12 key


keypad arranged as four rows by three columns.
It works if you keep the LCD strobe line (E) low while controling the
keypad. This stops the LCD from reacting to the other port pins (the
strobe line when strobed high starts a read or write action).
Since you only need seven port lines to access the keypad the eighth
is used for the LCD strobe line (RB2).
Note: If you use LVP and the 16F877A (PGM on RB3) then you can still
use this system - the LCD is fully controllable but you lose a column of
keys - but you still have 8 useable keys left - (note untested).
LCD Keypad : Circuit of LCD and keypad on one 8 bit port
(Click the diagram to open a pdf version)

LCD Keypad project details.


LCD Keypad Project
Compiler

Mikroelectronika
C compiler
V5.0.0.3 Free!

Target

16F877A
(retargetable to
other PICs that
have an 8 bit
port!).

Software level

Easy.

Software notes

Switching
between keypad
and LCD.

Hardware level

Easy.

Hardware notes

Use internal
pullups on portB
(you must add
pullups to row
inputs when
using a different
port).

Project version 1.00

Initial Release

Project version 1.01

Mod to operate
fully at 20Mhz
(0,# lost). Allow
settling time

after set col


outputs.
Project files

Download here

You can program the PIC in circuit through the ICSP connector.

LCD Keypad Port Directions


When using the LCD you need to set all LCD pins as outputs and for
the keypad you need to set rows as inputs and columns as outputs.
To make it work all row inputs must be pulled up to 5V (either by
internal port pullups or by external 10k resistors).
Note : During keypad access the LCD strobe signal (E) must be kept at
zero so that the LCD is not activated.

How the lcd keypad works


Reading the keypad
The software generates a walking 0 through the columns. Whenever
you press a key the keypad shorts column to the row so the zero from
the column output appears at the row input pulling the voltage to
ground. When there are no keys pressed the pullup resistors pull the
row inputs to 5V.
The routine exits with the first key detected. This key is derived from
the returned row value and the current mask value and you can
decode it using the definitions found in lcd_keypad.h e.g. KEY_2 has
the value 226 which is the value returned by read_KEYPAD when key 2
is hit.

Column shorts
Pressing two keys in different columns and rows shorts together two
columns that are at different voltages (one at 0V and one at
5V). The column drivers are isolated by the three 10k resistors to
prevent damage. They also allow the LCD to operate correctly even
when keys are pressed.

Kepad wiring
The following diagram shows the keypad wiring which is a little
awkward - probably to allow a simple pcb routing path.

Software operation
The software consists of three files:
16F887A_lcd_keypad.c
lcd_keypad.c
lcd_keypad.h
The most important routines are
KEYPAD_access() and LCD_access() which set the port up to let it control the
keypad and lcd respectively. The
interesting point about the code is that
the standard LCD routines (provided by
compiler manufacturer) are used after
lcd_access() is executed.
Pressing a key displays the result on the
lower right of the 2 row LCD.
Note that key debouncing has not been
done as it does not affect the demonstration but you must use it for a
'real' application.

Vous aimerez peut-être aussi