Keypad is an organized matrix of switches in rows and columns and it comes in the various form like numeric keypad, alphanumeric keypad . It also comes in different size like 4×3, 4×4 etc.

In real life keypad has a lot of application, it generally uses in the calculator, electronic lock, mobile phone and in many more electronic appliances.In this article we will learn the interfacing of keypad with 8051 micro-controller.

 

Note:  Numeric keypad contains mostly numeric numbers.

keypad

Connection of keypad with 8051 microcontroller

In below image, I have described the connection of keypad with 8051 microcontrollers. Here I have connected the column and rows of keypad corresponding to lower nibble of port-2 and the upper nibble of port-2.

interfacing of keypad



Algorithm to write a sample program for Keypad Interfacing

Here we will create an interface between 8051 microcontrollers and a 4×3 numeric keypad. Here I am not considering the switch debouncing.

There are following steps to write a program for keypad INTERFACING
  • Firstly you have to connect pin of rows and columns of the keypad with microcontroller pins and make the row pins as output and column pins as input.

NOTE: Whenever in keypad any of the keys pressed then corresponding row and column get connected and status of the row will be reflected in the corresponding column.

  • Make all row pins high except the row1 pin and check the status of col1,col2, and col3. If any one of them become low i.e. any one of them key pressed in row1. If there is no column low in row1 i.e. no key pressed on the keypad.

keypad

e.g.
Suppose in above scenario col1 become low when row1 is the low i.e. first key of col1 would be pressed on the keypad.

  • Just repeat the above scenario for row2, row3, and row4 and check the status of col1,col2, and col3.In below image, I have made the row2 pins low and check the status of col1,col2, and col3 pins.

 

In below image, I have made the row3 pins low and check the status of col1,col2, and col3 pins.

keypad

In below image, I have made the row4 pins low and check the status of col1,col2, and col3 pins.

keypad

Sample program to describe keypad interfacing with 8051

I have written a sample program to reads the user input and display it on the 16×2 LCD. You can find here more about the interfacing of LCD and 8051 micro-controller.

working of keypad