ECE 476: Keypad Library

© 2005 by Richard West

Published under GNU General Public License for ECE 476 students


Introduction

This library is a fully functioning keypad interpreter designed for the Atmel Mega32 microcontroller. Both the telephone and hexadecimal style keypads are supported. Keypad scanning, key debouncing, key string management, and key display management are handled automatically by the library. A simple user interface allows for complete customization of much of the functionality.

Version History


User interface

Standard user interface:

Extended user interface for operating the display:


Setting up the keypad library

The keypad library has been designed to be versatile, requiring very little user intervention to operate as intended. However, several preprocessor directives must be invoked before including the keypad header file (keypad.h). Failure to include these directives will cause compile-time errors, run-time errors, or both. In the second version of the keypad library, an effort has been made to generate compile-time errors for common mistakes and to eliminate possibly ambiguous compilation.

There are two types of keypad available for use in ECE 476 (see Figure 1), and the user must specify which keyboard layout to use when interpreting keycodes. The two types of keypad are either the telephone style keypad (right) or the hexadecimal style keypad (left). To use the telephone keypad either invoke #define KEYPAD_TELPAD or #define KEYPAD_KEYBOARD (see below) preprocessor directive. To use the hexadecimal keypad invoke the #define KEYPAD_HEXPAD preprocessor directive.

layout

Figure 1: the two keypads with differing layout

The keypad library is designed such that the keypad can be used on any of the Mega32's I/O ports. To specify which port to use, invoke the #define KEYPAD_USEPORTx preprocessor directive where x is replaced by the port letter (in uppercase). To use the display functionality of the keypad library, include the preprocessor directive #define KEYPAD_USEDISPLAY and #define DISPLAY_USEPORTx prior to including the keypad header file (keypad.h). A couple of advantages exist to not use the display functionality--smaller RAM usage and faster execution time--but displaying typed characters is an advantage for user interfaces. Play around with the provided test program to experiment with the various library setups.


Keypad keyboard

In addition to the standard keypad layouts, included in the keypad library is a fully defined 62-key keyboard layout (see Figure 2). The keypad keyboard works by holding down "shift" buttons (A, B, C, and D) and pressing one other button. For instance, pressing button '2' will display a '2' on the LCD, but pressing '2' while holding button 'A' will display an 'a' on the LCD. All alphanumeric keys and a vast punctuation set are available through sixty-two letter-number combinations. Caps-lock is available ('AB' or 'BA') to expand the alphabet to include both uppercase and lowercase, a delete key ('AC' or 'CA') is available, and a clear key ('AD' or 'DA') is available.

keyboard

Figure 2: the keypad keyboard with 62-key layout

The simplest way to become familiar with the keypad keyboard is to experiment with it using the provide test program. To use the keypad as a keyboard, invoke the #define KEYPAD_KEYBOARD preprocessor directive (use a telephone style keypad). No terminator needs to be defined for the keypad keyboard since the '#' button is already mapped to NULL and functions as the terminator.

"If cell phones worked like this, I may use mine more often." ~ Professor Bruce Land


Wiring notes

When wiring either style of keypad:

For either style of keypad, pin 1 is the leftmost pin when looking at the front of the keypad. The easiest way to verify that your wiring is correct is to run the keypad test program given at the end of this page.

When wiring the LCD:

Note that pin 1 of the LCD is the pin closest to the edge of the board. The easiest way to verify that your wiring is correct is to run the LCD test program.


Library files and test program

Download version 02 (latest) here:

Download version 01 here:


Copyright Cornell University Feb 2005