Basic Keyboard Matrix Project 1.4

Purpose

This project demonstrates how to handle the AT91SAM7L-EK on-board 5x7 keyboard matrix. It features multiple keypresses recognition with robust debouncing, automatic idle mode of the software logic after a time-out period and wake-up on a new keypress.

Hardware Requirements

This project requires an AT91SAM7L evaluation kit to work properly.

Description

Each key of the 5x7 keyboard does not have a single PIO associated with it; instead, five pins are connected to the rows and seven pins to the columns. Therefore, additional software is required to detect keypresses correctly.

Basically, the software uses a Timer Counter (TC) to check the state of each key at regular intervals. Each key is sampled by outputting a 0 on the appropriate row, putting the other rows in high-impedance and reading the level on the corresponding column. The debouncing is done by checking that the key state is stable during a fixed number of consecutive samples.

After a set amount of identical samples, the TC can be stopped to reduce power consumption. In that case, the column pins are configured to generate an interrupt and all the rows are set to output a 0. If any key is pressed, the interrupt handler if fired, re-enabling the TC; thus making it possible to resume the keypress detection system and correctly fetch the newly-pressed key.

In this software example, each pressed key is output on the DBGU. The 2ndF and 2ndF Lock keys can be used to toggle between the numeric and alphabetic keypads. After a short inactivity period, the timer is stopped; it is restarted as soon as a new key is pressed, as explained above.

Usage

  1. Build the program and download it inside the evaluation board. Please refer to the SAM-BA User Guide, the GNU-Based Software Development application note or to the IAR EWARM User Guide, depending on your chosen solution.
  2. On the computer, open the DBGU port with a terminal application (e.g. HyperTerminal on Microsoft Windows).
  3. Start the application.
  4. The program will output a startup message on the DBGU:
    -- Basic Keyboard Matrix Project 1.1 --
    -I- Configuring PIOs
    -I- Configuring TC0
    -I- Configuring keyboard matrix driver
    -I- Press any key
  5. Pressing any key outputs the corresponding character on the DBGU. After a set inactivity period, the program will output a message to notify it has disabled the TC. Pressing any key resumes the detection process. Here is an example output trace:
    0
    .
    -I- No activity, shutting down timer ...
    -I- Activity detected, restarting timer ...
    8
    9
Atmel Corporation ©2008