Introduction
A keypad is commonly found on telephone, ATM machine, fax machine, etc. It's arranged in matrix form, 3x4, 4x4, etc. The advantage of matrix arrangement of this digital input is saving the number of controller digital I/O. As an instance, a 4x4 keypad matrix requires only 8 pins of micro-controller, but it yields 16 difference keys.
Simulation of this example program |
Programming
Using 8-bit of a micro-controller's digital I/O port, this single port is divided into two nibbles. Lower nibble (column) is an output while higher nibble (row) is an input.
We use C loop of four repetition to generate key scanning routine. Whenever any key is pressed, the program determines which column and row are logic low that lead to key founding.
Circuit diagram |
As show in picture above, Port C connects to a 4x4 keypad matrix. These keypad gives key values of 0 to 9, and A to F, which is a hexadecimal representation.
Port D connects to a single seven segments display showing pressed key value. ATMega32 here uses its internal 8MHz oscillator.
I divide this program into C main file, and its keypad library I wrote for my own use.
C main file:
C library header file:
C library file:
If you want a standard PCB for ATMega32 micro-controller, you can order my AVR Microcontroller project from PCBWay with a reasonable price. Click here to get a free $5 credit for new account.
Click here to download this example.
See Also,
No comments:
Post a Comment