Specifications

Chapter 6 - Samples
Previous page Table of contents Chapter overview Next page
Keyboard
Keyboards are mechanical devices used to execute a break or make connection between two
points. They come in different sizes and with different purposes. Keys that are used here are also
called "dip-keys". They are soldered directly onto a printed board and are often found in
electronics. They have four pins (two for each contact) which give them mechanical stability.
Example of connecting keys to microcontroller pins.
Key function is simple. When we press a key, two contacts are joined together and connection is
made. Still, it isn't all that simple. The problem lies in the nature of voltage as an electrical
dimension, and in the imperfection of mechanical contacts. That is to say, before contact is made
or cut off, there is a short time period when vibration (oscillation) can occur as a result of
unevenness of mechanical contacts, or as a result of the different speed in pressing a key (this
depends on person who presses the key). The term given to this phenomena is called SWITCH
(CONTACT) DEBOUNCE. If this is overlooked when program is written, an error can occur, or the
program can produce more than one output pulse for a single key press. In order to avoid this, we
can introduce a small delay when we detect the closing of a contact. This will ensure that the
press of a key is interpreted as a single pulse. The debounce delay is produced in software and the
length of the delay depends on the key, and the purpose of the key. The problem can be partially
solved by adding a capacitor across the key, but a well-designed program is a much-better
answer. The program can be adjusted until false detection is completely eliminated.
In some case a simple delay will be adequate but if you want the program to be attending to a
number of things at the same time, a simple delay will mean the processor is "doing-nothing" for a
long period of time and may miss other inputs or be taken away from outputting to a display.
The solution is to have a program that looks for the press of a key and also the release of a key.
The macro below can be used for keypress debounce.
http://www.mikroelektronika.co.yu/english/product/books/PICbook/6_04Poglavlje.htm (1 of 3) [4/2/2003 16:18:47]