MCP - Alm 2
MCP - Alm 2
ALM REPORT
ABHISHEK M 71812201004
ABISHEK P 71812201006
ADRIN BERSHIK C J 71812201008
AJAY ADITHYA B 71812201011
AKSHAYA R 71812201017
ANBARASAN P 71812201018
ANVIN P SHIBU 71812201019
ARAVINTH 71812201020
ARJUN SUDHEER THEKKENMAR 71812201021
BHAVATHARNI J 71812201030
COURSE COORDINATOR
Mrs. M. SHANTHINI AP (Sl. Gr.)/CSE
SRI RAMAKRISHNA ENGINEERING COLLEGE
[Educational Service: SNR Sons Charitable Trust]
[Autonomous Institution, Reaccredited by NAAC with ‘A+’ Grade]
[Approved by AICTE and Permanently Affiliated to Anna University, Chennai]
[ISO 9001:2015 Certified and all eligible programmes Accredited by NBA]
Vattamalaipalayam, N.G.G.O. Colony Post, Coimbatore – 641 022.
Assessment
Implementation
Introduction (2)
Presentation (2)
Steps (4)
Total
Report(2)
S. (10)
Name & Roll No.
No.
1. ABHISHEK M (2201004)
2. ABISHEK P (2201006)
3. ADRIN BERSHIK C J (2201008)
4. AJAY ADITHYA B (2201011)
5. AKSHAYA R (2201017)
6. ANBARASAN P (2201018)
7. ANVIN P SHIBU (2201019)
8. ARAVINTH C M (2201020)
9. ARJUN SUDHEER (2201021)
10. BHAVATHARNI J (2201030)
1. INTRODUCTION 1
2. WORKFLOW DESCRIPTION 1
3. IMPLEMENTATION STEPS 1
5. CODE IMPLEMENTATION 2
6. OUTPUT 6
4. DIAGRAMMATIC REPRESENTATION 9
5. CONCLUSION 8
INTRODUCTION
Interfacing a keyboard with the 8052 microcontroller is a fundamental concept in embedded
systems. Keyboards are essential input devices used to send data to a system. In this project,
we interface a 4x4 matrix keypad with an 8052 microcontroller and display the input on a 16x2
LCD. The microcontroller scans the keypad to detect which key is pressed and sends the
corresponding data to the LCD for display. This type of interfacing is useful in applications
like calculators, security systems, and user-interface panels in embedded systems.
WORKFLOW DESCRIPTION
The workflow for interfacing the keyboard with the 8052 microcontroller involves:
1. Key Press Detection: The microcontroller continuously scans the rows and columns
of the matrix keypad to detect which key has been pressed.
2. Debouncing: This is to ensure stable keypress detection, as mechanical keys tend to
create multiple signals due to their physical movement.
3. Key Identification: Once a key is detected, the row and column coordinates of the key
are used to identify the exact key pressed.
4. Displaying on LCD: The identified key is sent as data to the LCD, where it is
displayed. The 16x2 LCD acts as a user feedback display, showing the user input.
In this setup, the keypad is interfaced with Port 1 of the microcontroller, and the LCD is
connected to Port 2. Control signals for the LCD are sent through specific pins in Port 3.
IMPLEMENTATION STEPS
1. Hardware Connections:
o Connect the 4x4 matrix keypad to Port 1 of the 8052 microcontroller. Each
column and row of the keypad is connected to specific pins of Port 1.
o Connect the 16x2 LCD to Port 2 of the microcontroller for data transmission.
The RS, RW, and E control pins are connected to Port 3 pins (P3.2, P3.3, P3.4
respectively).
o Power the 8052 microcontroller and ensure all ground connections are common.
Below is the circuit diagram illustrating the hardware connections between the 4x4 keypad,
8052 microcontroller, and 16x2 LCD.
1
o Implement a function to scan the rows and columns of the matrix keypad. Set
all rows to a high state and columns to low, then sequentially check which row
reads low (indicating a keypress). Based on the active row and column,
determine the pressed key.
4. Displaying Key Press:
o Once a keypress is detected, the corresponding character (e.g., numeric or
operator) is displayed on the LCD using the function lcd_data(). Each key of
the keypad is mapped to a specific character (as shown in the diagram).
5. Software Flow:
o The microcontroller enters an infinite loop, constantly checking the state of the
keypad. When a key is pressed, the corresponding row and column are detected,
and the key's value is sent to the LCD.
CODE IMPLEMENTATION
The following is the embedded C code used to implement the keypad and LCD interfacing
with the 8052 microcontroller:
#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 int i, j;
for(i = 0; i < time; i++)
2
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);
3
}
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('7');
if(R2 == 0)
lcd_data('4');
if(R3 == 0)
lcd_data('1');
if(R4 == 0)
lcd_data('e');
}
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('8');
if(R2 == 0)
lcd_data('5');
if(R3 == 0)
lcd_data('2');
if(R4 == 0)
lcd_data('0');
}
void row_finder3() // Function for finding the row for column 3
{
R1 = R2 = R3 = R4 = 1;
4
C1 = C2 = C3 = C4 = 0;
if(R1 == 0)
lcd_data('9');
if(R2 == 0)
lcd_data('6');
if(R3 == 0)
lcd_data('3');
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('/');
if(R2 == 0)
lcd_data('x');
if(R3 == 0)
lcd_data('-');
if(R4 == 0)
lcd_data('+');
}
void main()
{
lcd_init();
while(1)
{
msdelay(30);
5
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();
}
}
OUTPUT
6
7
DIAGRAMMATIC REPRESENTATION
CONCLUSION
The successful interfacing of a 4x4 keypad with the 8052 microcontroller allows for user input
via a simple and efficient mechanism. By displaying the pressed keys on an LCD, the system
provides real-time feedback to the user. This basic interfacing technique forms the foundation
for more complex embedded applications such as password systems, calculators, or even user-
controlled appliances. The implementation provides insight into how embedded systems
handle user input, data processing, and output display, which is crucial for developing
interactive systems.