Page 83 - Making PIC Microcontroller Instruments and Controllers
P. 83
BEAD I(EYBOARD AIID DISFIAY KEY I{UIBEF ON THE LCD ?3
Read Keyboard and Display Key
Number on the LCD
Now that we understand how this works, we have to tum the binary infornation we have
gathered into a number from 1 to 16 and identify the key press on the LCD. (The sample
program to do this, which is prcvided on the Internet by microEngineering Labs, shows
another rvay of doing this and is worth srudying.)
The switch number is ihe row number plus (tbe column number _l *
) 4.
If we rcverse all the bits in the PORTB byte, the nibbles will give us the posi
tions of the rows and columns as the locations of t}le ls in the two nibbles. Make
sure you understand this before proceeding. Work it out on a piece of paper step
by step.
"Show
The Key Press" program must be modifed to appear as shown h program
S.15.
Reading the keyboard (Readtng the keyboard rows and cotumns
and show key numbeD
CLEJAR
DEFINE OSC 4
DEFINE I]CD_DREG PORTD define LCD conneccions
DEAINE LCD DBI!! 4
DEFINE IJCD RSREG PORTE
DEFINE I/CD_RSBIT O
DEFINE !CD_ER!G PORTE
DEFINE LCD EBIT 1
AtCONl = 7 nake PORTA and PORTE digital
IJO9I PORTE.2 LcD R/W low (wrile)
PAUSE 200 rvait for LCD to star!
define the variables
BUFFER VAR BYTE
AIJPITA V.It BYTE countei for rows
COI]UIIN VAR BYTE
ROW VAR BYTE
SWTTCq BY?E
set up PORTB pullups
OPIION_REG.7 = 0 enable PORTB pullups to nake B4-B? high
ERISB = %U110000 nake B? B4 inputs, 83 B0 oulputs
se! up lhe inilial LCD readinqs
l"cDout SFE, 1
LOOP:
PORlts =%00001110 set line B0 low so we ce read row 1 only