Computer Peripherals 431
15.2.1 Keyboard Basics
If we consider only one key as an input device, its working mechanism would be considered as a simple
one. To make it functional, attach it with one input port pin of any I/O port (like 8255, we have discussed
in chapter 8) and connect the port pin with an external pull-up resistor, as shown in Figure 15.1 (a). Now
you need a simple software for reading or sensing this key. Assuming it is done by polling, the processor
has to continuously read the input pin of the port. If the key is not pressed, the input would be logic high.
Whenever the key is pressed, it would generate a logic low input [Figure 15.1 (b)].
Now the reader has to do some eldwork. If an oscilloscope is used to trace the input signal during
pressing and releasing of the key, the signal would appear as in Figure 15.1 (c) and not as Figure 15.1 (b).
The reason behind these oscillations, known as bouncing, is the mechanical property of the key.
Figure 15.1 Schematic of interfacing one key with a processor (a) Hardware details
(b) Ideal input signal and (c) Observed input signal
This bouncing is a phenomenon, which does not last for more than 40 milliseconds in any case. To
sense any key closure or key release correctly, this bouncing phase must be avoided. It is a standard prac-
tice, known as debouncing, to continue sensing any closed or released key for more than 40 milliseconds
and then accept its input signal logic as a valid one.
15.2.2 Multiple Key Scanning and Two-dimensional Matrix
The technique of interfacing any key as described above would be acceptable for a lesser number of keys.
For a larger number of keys this arrangement, one input port pin for each key, would not be economical. In
that case, to optimize the requirement of I/O pins of the I/O device, keys are arranged in the form of a two-
dimensional matrix with several rows and columns. Generally, these rows are interfaced with an input port,
the columns are interfaced with an output port ( Figure 15.2 ) or vice versa. Note that each key is placed at
the intersection of a row-line and a column-line. There is no interconnection between any row and column
line unless the corresponding key is pressed.
To sense all keys, repeated key scanning must be performed through software by activating only one col-
umn at a time, by outputting logic low through it. All remaining inactive columns are subjected to logic high
output. All row inputs are checked one by one after activating one column, about any eventual key closure.
If any key is sensed in this phase, its code is stored and the same process is continued for the remaining rows.
The process is repeated for all columns, making the next column as an active one, which ensures all keys are
sensed once. To ensure proper debouncing, any change of key status is observed for more than 40 millisec-
onds to ensure a steady state. The result is a fully-debounced key code for a unique key, pressed or released
by the user. If more than one key is pressed, this technique would yield the last sensed key code. The key
scanning software may be suitably modi ed to sense more than one key in pressed or released conditions,
which are generally encountered during the usage of SHIFT or CONTROL keys.
M15_GHOS1557_01_SE_C15.indd 431M15_GHOS1557_01_SE_C15.indd 431 4/29/11 5:37 PM4/29/11 5:37 PM