Embedded Systems Building Blocks, Second Edition

A large number of embedded products, such as microwave ovens, FAX machines, copiers, laser printers, Point Of Sale (POS) terminals, Programmable Logic Controls (PLCs), and so on, rely on a keyboard or keypad interface for user input. The keyboard might be used to input numerical data as well as to select the operating mode of the controlling device. As an embedded system designer, you are always concerned with the cost of your products. Chips are currently available to perform keyboard scanning, but a software approach to keyboard scanning has the benefit of reducing the recurring cost of a system and requires very little CPU overhead.
In this chapter, I will describe how a microprocessor can scan a keyboard, and I will also provide you with a complete, portable m x n matrix keyboard scanning module. The module can scan any keyboard matrix arrangement up to an 8x8 matrix, but can easily be modified to handle a larger number of keys. The matrix keyboard module code is an important building block for embedded systems. The keyboard module presented in this chapter has the following features:
Scans any keyboard arrangement from a 3x3 to an 8x8 key matrix.
Provides buffering (user configurable buffer size).
Supports auto-repeat.
Keeps track of how long a key has been pressed.
Allows up to three Shift keys.
All you need to do to use this module is to write three simple hardware interface functions and set the value of 17 #define constants. The keyboard...