You are on page 1of 4

SVKM’S NMIMS

Mukesh Patel School of Technology Management & Engineering


Department of Mechatronics Engineering

Course: - Advanced Microcontroller and Embedded Systems (Semester-VIII)

EXP. 2 Hex Matrix Keyboard Interfacing with 8051

Aim: - To implement and design programming model for the matrix keyboard.

Objective: To understand and design interface of keyboard to detect key press.

Equipment Needed:

1. Keil uvision 5 Software


2. Proteus Design Suite 8.6 Software

Theory of matrix keypad:

The predominant interface between humans and hardware is the keyboard. The matrix
keypad allows a designer to implement a large number of inputs with a small number of port
pins. For examples a 16 keys arranged as a 4 x 4 matrix can be implemented with only eight
port pins. These keypads were evolved originally for telephonic applications involving touch
—tone signaling.
Keypad Interface:

The following table shows how the rows and columns of 4 x 4 matrix keypad are connected.

LPC2294 Pins Description


(P2.0) ROW0
(P2.1) ROW1
(P2.2) ROW2
(P2.3) ROW3
(P1.0) COL0
(P1.1) COL1
(P1.2) COL2
(P1.3) COL3

How it works:

The keypad can be decoded to find out which key was pressed. When a key is pressed on the
keypad, a row and column make a contact; otherwise, there is no connection between rows
and columns.

The keypad columns are connected to the four pins and rows are connected to the four pins.
If no key has been pressed, reading the columns will yield '1s' and rows give '0s'.

If all the rows are grounded and a key is pressed, one of the columns will have '0' since the
key pressed provides the path to ground. It is the function of the microcontroller to scan the
keyboard continuously to detect and identify the key pressed. To detect a pressed key, the
microcontroller grounds all rows by providing '0s', then read the columns. If the data read
from the column is '1111', no key has been pressed and the process continues until a key
press is detected.

However, if one of the column bit has a zero, this means that a key press has occurred. After
a key press is detected, the microcontroller will go through the process of identifying the
key. Starting with the top row, the microcontroller grounds it by providing a low to row D0
only; then it reads the columns. If the data read is all 'Is', no key in that row is activated and
the process is moved to the next row.

It grounds the next row, reads the columns and checks for any zero. This process continues
until the row is identified. After identification of the row in which the key has been pressed,
the next task is to find out which column the pressed key belongs to.

For detecting the column, rotate columns bits and find which column has pressed. This is the
complete process of detection of keys.
Flowchart:

Interfacing Diagram: -

Program:-

Output:-
Conclusion:

Faculty Sign:

Date:

You might also like