Professional Documents
Culture Documents
Keyboard Interfacing
Keyboard Interfacing
KEYBOARD INTERFACING
Keyboard and LCDs are most widely used input/output devices of the 8051.
The CPU accesses
Keyboards are organized in a matrix of rows and columns.
both rows and columns through ports. Therefore with two 8-bit ports,
an 8 x 8
matrix ofkeys can be connected to the microprocessor.
When a key is pressed, a row and a column make a contact; otherwise there is
The following figure 5.2 shows the 4 x 4 matrix connected to two ports. The
rows are connected to an output port and the columns are connected to an input
port. If no key has been pressed, reading the input port will yield 1s for all
w
Do
to scan the keyboard D
microcontroller
continuously to detect and identify the key
pressed.
Connection to Ports
reads the columns. If the data read from
the columns is D3- DO = 1111,no key has been pressed and the process continues
a key press is detected. However, if one of the has a zero,
until
means a key press has occurred. For example,
that
column bits
if D3 -D0=
1101, this
this
means
that a key in the DI column has been pressed. After a key press is
detected,the
microcontrollerwill go through the process of identifying the key. Starting with the
top row, the microcontrollergrounds it by providing a low to row D0 only; then it
reads the columns. Ifthe 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
checks for any zero.This process continues until the row is identified.
Example 5.1|From the above figure 5.2, identify the row and column of the
(a) D3-DO
= 1110for the row, D3 -DO =1011for the column
(b) D3-D0 1101 forthe row, D3- DO 0111 for the column
Solution
From the above figure 5.2 the row and column can be used to identify the key.
(a) The row belongs to DO and the column belongs to D2; therefore,
TOWcNart
Start
Read all
columns
Read all
columns
No Key
press in
All
No thisrow?
keys
Open?
Yes
Yes
Find which key
is pressed
Read allcolumns
scan
Get code
from table
No Any
key down? Return
Yes
No
All
keys
pen?
Yes
5.8
Microprocessorsand Microcontrollers-EER
keys open.
o
MOV
MOV
Pl,#11111110B
A, P2
ground row
;read
0 loRc o
TOw
all columns ckeck oF
ANL A,#00001111B mask unused (Or)
bits
ta othuthcINE A, #00001111B, ROw_0 ;key row 0,findthecol.
ce ko) MOV PI,#11111101B ground row 1
ohowist
repeat
ROW_0: MOV DPTR,#KCODE 0 =
set DPTR start of row 0
SJMP FIND
:find col. key belongs to
ROW 1: MOV DPTR, # KCODE 1 =start of row
set DPTR 1
SJMP FIND
find col. key belongs to
ROW_2: MCV DPTR,#KCODE2 set DPTR= start of row 2
SJMP FIND ;find coi, key belongs to
ROW_3: MCV DPTR,#KCODE 3 set DPTR =start of row 3
FIND: RRC A seeif any CY bit is low
e
chep NC
UNC MATCH ifzero,get the ASCII code
CoTuO INC DPTR
point to next col. address
MATCH: SJMP FIND keep searching
CLR A
set A =O (match is found)
MOVC A,@A+DPTR get ASCII code from table
and Microcontrollers -
5.10 Microprocessors EE
mechanical movements. The following figure 5.3 shows the typical 2 phase motor
interfaced using 8255.
Motor shown in the circuit has two phases, with center-tap winding. The center
taps of these windings are connected to the 12V supply. Due to this, motor can be
excited by grounding four terminals of the two windings. Motor can be rotated in
steps by giving proper excitation sequence of these windings. The lower nibble of
port A of the 8255 is used to generate excitation signals in the proper sequence.
The stepper motor has been explained in the interfacing of stepper motor using
8085 section. Some important terms related to the stepper motor are given below.
Rotor
surrounded by stator.
Step Angle
+12 V
Stepper
motor
X2
Y1 Y2
PA2
rpmxStepsper revoltuon
Steps per second 60
The following table shows the typical excitation sequence. The given excitation
-x
Fig. 5.4. Digital Locking Systenm
Excitation Table
Step X Y1 Y2
1 0 1 0 1
2 0 0
3 0 1 0
4 0 1 1 0
0 1
The excitation sequence given in the above table is called a full step excitation
sequence. In which excitation ends of the phase are changed in one step. The
excitation sequence given in the following table takes two steps to change the
excitation ends of the phase. Such a sequence is called half step sequence and in
Step Y1 Y2
1 0 1
2 0 0 0 1
0 0
4 1 0 0 0
5
6 0 1 0
0 0
& Applications 5.13
Microcontroller Programming
Step X Y Y2 360
7 0 1
8 0 1
0
0 0
windings. There is a power loss across series resistor, but designer has to
compromise between power and speed.
+12 V
Free Motor
wheeling
diode
A Winding
RB
Series
resistance