►Introduction

Keypads are a part of HMI or Human Machine Interface and play really important role in a small embedded system where human interaction or human input is needed. Martix keypads are well known for their simple architecture and ease of interfacing with any microcontroller. In this part of tutorial we will learn how to interface a 4x4 matrix keypad with AVR and 8051 microcontroller. Also we will see how to program then in Assembly and C.


►Constructing a Matrix Keypad

Constuction of a keypad is really simple. As per the outline shown in the figure below we have four rows and four columns. In between each overlapping row and column line there is a key.


4x4 matrix Keypad outline

So keeping this outline we can constuct a keypad using simple SPST Switches as shown below:


4x4 matrix Keypad schematic

Now our keypad is ready, all we have to do is connect the rows and columns to a port of microcontroller and program the controller to read the input.


►Scanning a Matrix Keypad

There are many methods depending on how you connect your keypad with your controller, but the basic logic is same. We make the coloums as i/p and we drive the rows making them o/p, this whole procedure of reading the keyboard is called scanning.


In order to detect which key is pressed from the matrix, we make row lines low one by one and read the coloums. Lets say we first make Row1 low, then read the columns. If any of the key in row1 is pressed will make the corrosponding column as low i.e if second key is pressed in Row1, then column2 will give low. So we come to know that key 2 of Row1 is pressed. This is how scanning is done.


So to scan the keypad completely, we need to make rows low one by one and read the columns. If any of the button is pressed in a row, it will take the corrosponding column to a low state which tells us that a key is pressed in that row. If button 1 of a row is pressed then Column 1 will become low, if button 2 then column2 and so on...


Now lets move on to the programming part of keypad in our next section.

◄ Back to Index  |  Connecting a Keypad ►

Conversation

hiast
Thu Jun 16 2016, 03:03 PM
help please how do i initiate port 3 as an input port in assembly? acutely there is push switch connecting to p3.2 push switch connecting to p3. 3 push switch connecting to p3.4 push switch connecting to p3.5 and i need to call function when the user pressed the push switch for the previous pins (not used as counter and not as timer… just call a function ( do special thing) when any push switch is pressed ???????
Mon Jun 06 2016, 12:02 PM
nida hussain
hi.. i need some help with keypad interfacing code.like i want to write a code in c language that takes an input of 2 digit numbers from a keypad interfaced with 8051 mc and stores the entered values in some array
Sat May 28 2016, 04:34 PM
kibrom berhe
c code for locker security system based on rfid and gsm
ExperimenterUK
Wed May 25 2016, 05:05 AM
@ Ramanjaneyulu, post in forum,explain your problem
Mon May 23 2016, 11:34 PM
Ramanjaneyulu
Hi, I Am using at89c4051 for my application, I want 5u sec dely.. Up to 1milli sec iam able to producing delay. Beyond the 1milli second, I am unable to produce the acceurate dely. Plz any one help me
Sat May 21 2016, 09:51 PM
A K
i want to mak an auto dialer using gsm and atmega 16. please helpe me how to write a code to auto dial a number saved in sim
Sat May 21 2016, 10:42 AM
Alec
Hi im trying to program my 89s51 with a usbasp so any ideas on the circuit?
Wed May 18 2016, 10:08 AM
Tashu joshi
anyone know how to develop
Wed May 18 2016, 10:07 AM
Tashu joshi
i'm working for resporatry system using 8051,
Wed May 18 2016, 10:06 AM
Tashu joshi
i'm developing a respiratory system using Arduino

Downloads

Comments

Bonolai
Fri Jun 24 2016, 06:02 AM
hiast
Sat Jun 11 2016, 02:30 PM
alex1311
Thu Jun 09 2016, 06:57 AM
zaft93
Sun May 15 2016, 01:52 AM
CELEBI
Thu May 12 2016, 08:28 AM
Suro1996
Wed May 11 2016, 06:07 PM
yigithan
Sat May 07 2016, 09:09 PM
jaque
Fri May 06 2016, 07:51 PM

Online

Guests: 49, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 37768
Newest member: Bonolai
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Wed Jun 22 2016, 07:54 PM
I can't see why it should work sometimes and not o...
ExperimenterUK Avatar
Posted By ExperimenterUK
Wed Jun 22 2016, 12:58 AM
You could use T0 and T1 to trigger interrupts but ...
Karan123 Avatar
Posted By Karan123
Tue Jun 21 2016, 04:40 AM
I am not Getting you . the project is to interfac...
Karan123 Avatar
Posted By Karan123
Tue Jun 21 2016, 04:34 AM
Hello,Thanks , It Works . Master-Slave address Ma...
alex1311 Avatar
Posted By alex1311
Mon Jun 20 2016, 11:38 AM
Football is my passion and I have dreamt of becomi...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Jun 17 2016, 11:00 PM
>But Can't modify code at Receiver End for Differe...
hiast Avatar
Posted By hiast
Fri Jun 17 2016, 03:25 PM
thanks for help,i wanted to write this code as you...
Karan123 Avatar
Posted By Karan123
Fri Jun 17 2016, 12:19 PM
I don't your applications . But below should help ...
Karan123 Avatar
Posted By Karan123
Fri Jun 17 2016, 12:07 PM
I know i have to use below code at Transmitter End...
hiast Avatar
Posted By hiast
Thu Jun 16 2016, 02:58 PM
help pleasehow do i initiate port 3 as an input po...