Hardware Reference
In-Depth Information
delayby50us(1);
}
void putsLCD (char *ptr)
{
while (*ptr) {
putcLCD(*ptr);
ptr 11 ;
}
}
The assembly and C language versions of the LCD functions have been grouped into files
to be included in the user's program and are provided on the complementary CD.
7.9 Interfacing Parallel Ports to a Keypad
A keypad is another commonly used input device. Like a keyboard, a keypad is arranged as an
array of switches, which can be mechanical, membrane, capacitive, or Hall effect in construction.
In mechanical switches, two metal contacts are brought together to complete an electric circuit.
In membrane switches, a plastic or rubber membrane presses one conductor onto another; this
type of switch can be made very thin. Capacitive switches comprise two plates of a parallel plate
capacitor; pressing the key cap effectively increases the capacitance between the two plates. Spe-
cial circuitry is needed to detect this change in capacitance. In Hall-effect key switches, the motion
of the magnetic flux lines of a permanent magnet perpendicular to a crystal is detected as voltage
appearing between the two faces of the crystal; it is this voltage that registers a switch closure.
Mechanical keypads and keyboards are most popular due to their low cost and strength of
construction. However, mechanical switches have a common problem called contact bounce .
Instead of producing a single, clean pulse output, pressing a mechanical switch generates a series
of pulses because the switch contacts do not come to rest immediately. This phenomenon is
illustrated in Figure 7.31.
When the key is not pressed, the voltage output to the computer is 5 V. In order to detect
which key has been pressed, the microcontroller needs to scan every key switch of the keypad.
A human being cannot press and release a key switch in less than 20 ms. During this interval,
the microprocessor can scan the same key switch closure tens or even hundreds of thousands of
times, interpreting each low signal as a new input when in fact only one input should be sent.
Because of the contact bounce and the disparity in speed between the microprocessor and
human key pressing, a debouncing process is needed. A keypad input program can be divided
into three stages.
V CC
5 to 20 ms
H
to microprocessor
L
Active low output
Figure 7.31 Key switch contact bounce
 
Search WWH ::




Custom Search