Friday, August 28, 2009

microcontroller programming keypad decode techniques


In the design of electronics project, it is very common to use a keypad matrix as a means for user to interface
to the product. In order to minimize the number of pins used in the microcontroller, the keys should be arranged in as square a matrix as possible. One example is the use of 4 X 4 matrix arrangement in a 16 keys keypad. This arrangement require only 8 pins. If it is arrange in a 2 X 8 matrix, 10 pins will be needed instead of 8.

The microcontroller programming keypad decoding method is as shown in the figure above. There are 4 inputs pins designated as row 1 to row 4 and 4 output pins designated as column 1 to column 4. The 4 input ports need to have a pulldowns resistor to ensure that they are always at a deterministic state either login "0" or login "1". This is achieved by having an internal pulldown resistor in the MCU itself or by having 4 external resisors connected to each of the input pin and ground.

At the start of the scanning, column 1 will be turned ON(login "1") and column 2, 3, and 4 turn OFF (logic "0"). When this happen, the input ports row 1 to row 4 are scanned for its status. If key 7 is pressed, the pin PA2 at row 3 will return as logic "1" and the rest of the rows will return logic "0". By having a debouncing routine as a means of confirmation that the particular key has been pressed, the MCU will know which key is pressed and thus is able to proceed to determine the next action to take.

Low Power Consumption Consideration

In the design of key interface, it is also important to choose a MCU that is able to go into power down mode after a certain time has elapsed. This will ensure that the batteries that are used to power up the MCU will last longer. It will only wake up when a key is pressed. Power down mode typically takes a fraction of current compared to when it is in active mode.

The PDF article below is an example of Motorola MC68HC705J1A Keypad decoding techniques that can be studied and used for any other MCU. The flow chart
and examples of the assembly code are also given.

No comments:

Post a Comment