0% found this document useful (0 votes)
16 views11 pages

MC Edited

This report details the interfacing of a 4x4 matrix keypad with the 8051 microcontroller as part of an engineering project. It outlines the components required, circuit design, and programming code necessary to detect key presses and display the output on an LCD or via serial communication. The expected outcomes include visual feedback on an LCD and potential audio/visual indicators when keys are pressed.

Uploaded by

rajeshrajysh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views11 pages

MC Edited

This report details the interfacing of a 4x4 matrix keypad with the 8051 microcontroller as part of an engineering project. It outlines the components required, circuit design, and programming code necessary to detect key presses and display the output on an LCD or via serial communication. The expected outcomes include visual feedback on an LCD and potential audio/visual indicators when keys are pressed.

Uploaded by

rajeshrajysh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

VISVESVARAYA TECHNOLOGICAL UNIVERSITY

BELAGAVI-590018, KARNATAKA

ACTIVITY BASED LEARNING REPORT

ON

“4x4 MATRIX KEYPAD INTERFACING WITH 8051 MICROCONTROLLE”


Submitted in partial fulfillment of the requirements for the academic year 2024-2025

BACHELOR OF ENGINEERING IN

ELECTRONICS AND COMMUNICATION ENGINEERING

SUBMITTED BY

BOYA Rajesh
1SJ23EC020
Under the Guidance of

SWAPANA BAADKAR

Assistant Professor

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

SJC INSTITUTE OF TECHNOLOGY


CHICKABALLAPUR-562101

2024 - 25
4x4 MATRIX KEYPAD INTERFACING WITH 8051
MICROCONTROLLER
INTRODUCTION:
Keypads are widely used input devices being used in various electronics and
embedded projects. They are used to take inputs in the form of numbers and
albhabets, and feed the same into system for further processing. In this tutorial

we are going to interface a 4x4 matrix keypad with 8051 microcontroller .


4X4 Matrix Keypad:
Before we interface the keypad with microcontroller, first we need to
understand how it works. Matrix keypad consists of set of Push buttons, which
are interconnected. Like in our case we are using 4X4 matrix keypad, in which
there are 4 push buttons in each of four rows. And the terminals of the push
buttons are connected according to diagram. In first row, one terminal of all the
4 push buttons are connected together and another terminal of 4 push buttons
are representing each of 4 columns, same goes for each row. So we are getting
8 terminals to connect with a microcontroller.
COMPONENTS REQUIRED:
1.4X4 Matrix Keypad:
 A 16-key keypad arranged in 4 rows and 4 columns.
2.8051 Microcontroller:
 Any variant (e.g., AT89C51, AT89S52) with I/O ports for interfacing.
3.Pull-up Resistors (Optional but Recommended):
 Typically 10kΩ resistors for the port lines if internal pull-ups are not
used.
4.Connecting Wires:
 To connect keypad rows and columns to the microcontroller’s I/O pins.
5.Power Supply:
 5V regulated supply for the 8051 and keypad.
6.Capacitors and Crystal Oscillator (for 8051 setup):
 Example: 11.0592 MHz crystal with 2 x 33pF capacitors.

OPTIONAL COMPONENTS:
1. Pull-up Resistors (e.g., 10kΩ)
Used if the microcontroller ports don’t have internal pull-ups (most 8051 ports
do, except Port 0).
Ensures defined logic levels and avoids floating inputs.
2. Debouncing Circuit (RC Filter or Schmitt Trigger)
To smooth out noise caused by mechanical key presses.
Software debouncing is often sufficient, but hardware can improve reliability.
3. Diodes (e.g., 1N4148)
Prevents ghosting in complex keypad scenarios (mainly needed in more
complex keyboard matrices).
4. Capacitors
For decoupling (e.g., 100nF near Vcc and GND) to suppress noise and stabilize
power. Can also be used in debounce filtering.
5. Level Shifter / Voltage Regulator
If using a microcontroller with different voltage levels.
6. LCD or Display Module
To display the key press output in a user-friendly way.
CIRCUIT DIAGRAM AND WORKING EXPLANATION:
First we need to interface a LCD module to display the data which will be feed
through KEYPAD, so please go through “LCD Interfacing with 8051
Microcontroller” article before interfacing KEYPAD.
As shown in above circuit diagram, to interface Keypad, we need to connect 8
terminals of the keypad to any port (8 pins) of the microcontroller. Like we have
connected keypad terminals to Port 1 of 8051. Whenever any button is pressed
we need to get the location of the button, means the corresponding ROW an
COLUMN no. Once we get the location of the button, we can print the
character accordingly.
Now the question is how to get the location of the pressed button? I am going
to explain this in below steps and also want you to look at the code:
1. First we have made all the Rows to Logic level 0 and all the columns to Logic
level 1.
2. Whenever we press a button, column and row corresponding to that button
gets shorted and makes the corresponding column to logic level 0. Because
that column becomes connected (shorted) to the row, which is at Logic level 0.
So we get the column no. See main() function.

3. Now we need to find the Row no., so we have created four functions
corresponding to each column. Like if any button of column one is pressed, we
call function row_finder1(), to find the row no.
4. In row_finder1() function, we reversed the logic levels, means now all the
Rows are 1 and columns are 0. Now Row of the pressed button should be 0
because it has become connected (shorted) to the column whose button is
pressed, and all the columns are at 0 logic. So we have scanned all rows for 0.

5. So whenever we find the Row at logic 0, means that is the row of pressed
button. So now we have column no (got in step 2) and row no., and we can print
no. of that button using lcd_data function.
Same procedure follows for every button press, and we are using while(1), to
continuously check, whether button is pressed or not.

CODE:
#include<reg51.h>
#define display_port P2 //Data pins connected to port 2 on microcontroller
sbit rs = P3^2; //RS pin connected to pin 2 of port 3
sbit rw = P3^3; // RW pin connected to pin 3 of port 3
sbit e = P3^4; //E pin connected to pin 4 of port 3
sbit C4 = P1^0; // Connecting keypad to Port 1
sbit C3 = P1^1;
sbit C2 = P1^2;
sbit C1 = P1^3;
sbit R4 = P1^4;
sbit R3 = P1^5;
sbit R2 = P1^6;
sbit R1 = P1^7;
void msdelay(unsigned int time) // Function for creating delay in milliseconds.
{
unsigned i,j ;
for(i=0;i<time;i++)
for(j=0;j<1275;j++);
}
void lcd_cmd(unsigned char command) //Function to send command
instruction to LCD
{
display_port = command;
rs= 0;
rw=0;
e=1;
msdelay(1);
e=0;
}
void lcd_data(unsigned char disp_data) //Function to send display data to LCD
{
display_port = disp_data;
rs= 1;
rw=0;
e=1;
msdelay(1);
e=0;
}
void lcd_init() //Function to prepare the LCD and get it ready
{
lcd_cmd(0x38); // for using 2 lines and 5X7 matrix of LCD
msdelay(10);
lcd_cmd(0x0F); // turn display ON, cursor blinking
msdelay(10);
lcd_cmd(0x01); //clear screen
msdelay(10);
lcd_cmd(0x81); // bring cursor to position 1 of line 1
msdelay(10);
}
void row_finder1() //Function for finding the row for column 1
{
R1=R2=R3=R4=1;
C1=C2=C3=C4=0;
if(R1==0)
lcd_data('1');
if(R2==0)
lcd_data('4');
if(R3==0)
lcd_data('7');
if(R4==0)
lcd_data('*');
}
void row_finder2() //Function for finding the row for column 2
{
R1=R2=R3=R4=1;
C1=C2=C3=C4=0;
if(R1==0)
lcd_data('2');
if(R2==0)
lcd_data('5');
if(R3==0)
lcd_data('8');
if(R4==0)
lcd_data('0');
}
void row_finder3() //Function for finding the row for column 3
{
R1=R2=R3=R4=1;
C1=C2=C3=C4=0;
if(R1==0)
lcd_data('3');
if(R2==0)
lcd_data('6');
if(R3==0)
lcd_data('9');
if(R4==0)
lcd_data('#');
}
void row_finder4() //Function for finding the row for column 4
{
R1=R2=R3=R4=1;
C1=C2=C3=C4=0;
if(R1==0)
lcd_data('A');
if(R2==0)
lcd_data('B');
if(R3==0)
lcd_data('C');
if(R4==0)
lcd_data('D');
}
void main()
{
lcd_init();
while(1)
{
msdelay(30);
C1=C2=C3=C4=1;
R1=R2=R3=R4=0;
if(C1==0)
row_finder1();
else if(C2==0)
row_finder2();
else if(C3==0)
row_finder3();
else if(C4==0)
row_finder4();
}
}

EXPECTED OUTPUT:
When a key is pressed on the 4×4 matrix keypad, the 8051
microcontroller should be able to detect and identify which key was
pressed and then produce a corresponding output.

1. Serial Monitor / UART Output


If the microcontroller is programmed to send output via serial
(UART), you may see something like:
Key Pressed: 1
Key Pressed: A
Key Pressed: 5

2. LCD Display Output


If an LCD is connected, you may see:
You pressed: 7
Or keys being displayed continuously:
123A
3. LED or Buzzer Feedback (Optional)
A short beep or LED blink whenever a key is pressed.
Keypad Layout Mapping (Typical):
[1] [2] [3] [A]
[4] [5] [6] [B]
[7] [8] [9] [C]
[*] [0] [#] [D]When the user presses a key (e.g., '5'), the
microcontroller scans rows and columns, detects the intersection,
and maps it to '5'.

PHYSICAL OUTPUT:
When a 4×4 matrix keypad is physically interfaced with the 8051
microcontroller, the observable (physical) outputs can include:
1. LCD Display (if connected)
Displays the key that was pressed.
Example:
Key: 3
or
Entered Code: 123A
2. Serial Output to PC (via UART)
Using a serial-to-USB converter and terminal software (e.g., PuTTY,
Tera Term).
Output example:
Key Pressed: B
3. LED Indicator (Optional)
A single LED may blink when a key is pressed.
Or multiple LEDs can show specific patterns based on the key.
4. Buzzer (Optional)
Emits a beep or tone each time a key is pressed.
5. Keypad Press Feedback
The tactile click or press of the button itself is physical feedback to
the user.
Summary Table:
Component Physical Output Example
LCD (16x2) Displays "Key: 7"
Serial Terminal Shows "Key Pressed: *"
LED Brief flash on key press
Buzzer Beep on key press
Keypad Tactile feel/click when pressed

You might also like