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.
This project requires an AT91SAM7L evaluation kit to work properly.
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.
-- Basic Keyboard Matrix Project 1.1 --
-I- Configuring PIOs
-I- Configuring TC0
-I- Configuring keyboard matrix driver
-I- Press any key
0
.
-I- No activity, shutting down timer ...
-I- Activity detected, restarting timer ...
8
9