Engineering Knowledge

Free software, projects, tutorials & more!
Home     Links     Site Map     Contact Us      

 You are here: Home > Projects > Microcontroller Interfacing & Decoding Matrix Keyboard

 Microcontroller Interfacing & Decoding Matrix Keyboard

By Engineering Knowledge administrator Rev1.0

Copyright©  Engineering Knowledge 2007. All rights reserved.

 

 

Once you add a keyboard for your system, you allow the user to input information to the microcontroller in real time. In this tutorial, you will learn how to connect a keyboard to your microcontroller and the basic principle to decode keyboard input.

In general, keyboards are organized as a matrix of rows and columns; two side of this matrix are connected to Vcc through resistors while the third side is connected to the microcontroller port and configured as an output; and the last side is connected to the microcontroller port and configured as an input as shown in fig. 1.

Microcontroller keep scanning the keyboard, when all inputs are high ("ones") that mean no key is pressed; if one bit is low ("zero") that mean there is a pressed key. System designer setup a Look-Up Table contain the ASCII code for each key, in this project we will use 16 keys to represent the hex number from 0 to F arranged according to keyboard arrangement.

To detect which key is pressed; microcontroller ground all rows, then reads all columns, if all the columns=1's no key is pressed, if one columns=0 it's indicate that a key is pressed. To identify the exact pressed key, microcontroller will starting with the top row by grounding it; then read the columns. If the data read is all ones, no key that row activated, and the process will move to the next row, until reach the row that has a pressed key. At this stage, microcontroller knows the row that

 Tip:

Before starting the process of finding the pressed key, microcontroller should sleep a certain time to insure that the signal is not due to spike noise and to reject the bounce. In the assembly code below it 20ms.

has a pressed key, and can setup the starting address in the look-up table for that row.

The last step is finding the column that has a pressed key by rotating the columns bits; one bit at a time to locate a low bit, the most efficient way is rotating column bits through the carry flag by using RRC instruction. When the 0 bit found, microcontroller pulls the corresponding code from the look-up table.

To be sure that no key is still down from the previous session, microcontroller send 0's to all rows at on time and check the columns, if all columns are high then the normal scanning start, otherwise, it will wait until all columns become high.

At the left, you will find the assembly code for scanning 4x4 keyboard, assuming that the input data will be a hex number form 0 to F, ports P1.0 to P1.3 of the 8051 microcontroller connected to rows, P2.0 to P2.3 connected to columns. The pressed key ASCII code will be stored in A. At the right is the flowchart that describes the code.

 

Light Control System               *Very Informative!

 

Power Supply Design              *Very Informative!

 

 

 

*Sponsored Link.

 Microcontroller Interfacing & Decoding Matrix Keyboard 

By Engineering Knowledge administrator Rev1.0

Copyright©  Engineering Knowledge 2007. All rights reserved.

 You are here: Home > Projects > Microcontroller Interfacing & Decoding Matrix Keyboard