BANGALORE INSTITUTE OF TECHNOLOGY
An Autonomous Institute Affiliated to VTU, JnanaSangama, Belagavi – 590 018
KR Road,VV Pura,
Bengaluru560 004
Report on the subject
“Microcontrollers – BEC405A”
Bachelor of Engineering
In
Electronics Engineering (VLSI Design and Technology)
Submitted By
Name: Sudhindra M Acharya
USN: 1BI24VL049
Under the guidance of
Lavanya Y S
Assistant Professor
Department of Electronics Engineering
(VLSI Design and Technology)
Bangalore Institute of Technology
Bengaluru
TABLE OF CONTENTS
[Link] Contents Page No.
1 INTRODUCTION
1
2 CIRCUIT DESIGN
2
3 ALGORITHM
3
4 FLOWCHART
4
5 ALP CODE
5
6 PROGRAM EXPLANATION
7
7 RESULT
8 CONCLUSION
Matrix Keypad Interfacing with LCD Display 2025-26
INTRODUCTION
In embedded systems, user input is often required in the form of numeric or
alphanumeric data. A matrix keypad provides a compact and efficient way to capture
multiple inputs using fewer microcontroller pins. The 8051 microcontroller is widely
used in academic and industrial applications due to its simplicity and versatility. In
this project, a 4×4 hexadecimal keypad is interfaced with an LCD display. The keypad
allows entry of digits 0–9 and letters A–F, representing the complete hexadecimal set. The
microcontroller scans the keypad, detects the pressed key, converts it into its ASCII
equivalent, and displays it on the LCD. This project demonstrates keypad scanning,
ASCII mapping, and LCD interfacing — fundamental concepts in microcontroller
programming.
CIRCUIT DESIGN
Keypad: 16 keys arranged in 4 rows × 4
columns. Rows : P1.0-P1.3
Columns : P1.4-P1.7
LCD:
Data bus (D0-D7) : Port 2 of 8051
Control signals : Port 3.0 (RS), Port 3.1 (RW), Port 3.2
(EN) Pull-up resistors on column lines ensure default logic
high.
When a key is pressed, the row driven low and the column pulled low form a
unique combination detectable by the microcontroller.
F E D C
P1.
7
805
P1.
B A 8 6
9 P1.
5
7 6 4 P1.
4
3 2 0
5
1
P1.
3
P1.
2
P1.
1
P1.
0
Interfacing a Keypad
Department of Electronics Engineering (VDT), BIT Page 1
Matrix Keypad Interfacing with LCD Display 2025-26
CIRCUIT DIAGRAM
The circuit diagram shows how the 4×4 hexadecimal keypad is connected to the
8051 microcontroller and how the microcontroller drives the LCD display. The
keypad is arranged in a matrix of four rows and four columns. The rows are connected to
pins P1.0– P1.3, while the columns are connected to P1.4–P1.7 with pull-up resistors.
When a key is pressed, a specific row and column line are shorted, producing a unique
combination that the microcontroller can detect.
The 8051 microcontroller continuously scans the keypad by driving one row low at a
time and checking the column inputs. Once a pressed key is identified, the microcontroller
maps it to its ASCII code. This ASCII value is then sent to the LCD via Port 2 (data
lines). The control signals RS, RW, and EN are provided through Port 3 to ensure proper
data transfer and display.
Department of Electronics Engineering (VDT), BIT Page 2
Matrix Keypad Interfacing with LCD Display 2025-26
ALGORITHM
1. Start the system.
Port 1 → configured for keypad
input/output. Port 2 → configured for LCD
data lines.
Port 3 → configured for LCD control signals (RS, RW, EN).
2. Initialize the LCD.
Send command 38H to set 8-bit mode, 2-line display.
Send command 0EH to turn display ON and enable
cursor. Send command 01H to clear display.
Send command 06H to set cursor auto-increment.
Send command 80H to set cursor at the first line, first
position. Each command is sent by setting RS=0, RW=0,
EN=1→0.
3. Begin keypad scanning loop.
Set Port 1 to 0FEH (Row 1 low, others
high). Read column inputs (P1.4–P1.7).
If any column bit = 0, a key in Row 1 is pressed.
Identify which column is low and map to the corresponding key (1, 2, 3,
A). If no key detected, proceed to next row.
4. Repeat scanning for all rows.
Row 2 → 0FDH → keys (4, 5, 6,
B). Row 3 → 0FBH → keys (7, 8,
9, C). Row 4 → 0F7H → keys (E, 0,
F, D).
For each row, check columns and identify pressed key.
5. Key identification logic.
Combine row and column position to determine the key
label. Convert the label to its ASCII equivalent:
‘0’–‘9’ → 30H–39H
‘A’–‘F’ → 41H–46H
‘E’ and ‘F’ replace ‘*’ and ‘#’ for full hexadecimal range.
6. Display the key on LCD.
Move ASCII value to accumulator
(A). Send it to Port 2 (LCD data bus).
Set RS=1 (data mode), RW=0 (write),pulse
EN=1→0. Call delay routine to allow LCD to latch
data.
The pressed key appears on the LCD.
Department of Electronics Engineering (VDT), BIT Page 3
Matrix Keypad Interfacing with LCD Display 2025-26
7. Delay routine.
Nested loops using registers R6 and R7 create a short delay.
Ensures LCD timing requirements are met before next operation.
8. Return to main loop.
After displaying the key, resume scanning from Row
1. Continue indefinitely to detect subsequent key
presses.
9. End of program.
FLOWCHART
Department of Electronics Engineering (VDT), BIT Page 4
Matrix Keypad Interfacing with LCD Display 2025-26
ASSEMBLY LANGUAGE PROGRAM CODE
ORG 0000H ; Origin address – program starts at 0000H
LJMP START ; Jump to START label
; LCD connections:
; Port2 = Data lines (D0–
D7) ; P3.0 = RS (Register
Select)
; P3.1 = RW
(Read/Write) ; P3.2 = EN
(Enable)
; Keypad connections:
; P1.0–P1.3 = Rows
; P1.4–P1.7 = Columns
; Delay Routine
DELAY: MOV R7,#0FFH ; Outer loop counter
D1: MOV R6,#0FFH ; Inner loop counter
D2: DJNZ R6,D2 ; Decrement R6 until zero
DJNZ R7,D1 ; Decrement R7 until zero
RET ; Return from delay
; LCD Initialization
LCD_INIT:
MOV P2,#38H ; Command: 8-bit mode, 2-line display
CLR P3.0 ; RS=0 (command mode)
CLR P3.1 ; RW=0 (write mode)
SETB P3.2 ; EN=1 (enable high)
LCALL DELAY ; Wait for LCD to latch
CLR P3.2 ; EN=0 (enable low)
LCALL DELAY ; Extra delay
RET ; Return from LCD init
; Program Start
START: LCALL LCD_INIT ; Call LCD initialization routine
LJMP MAIN ; Jump to main scanning loop
; Main Keypad Scanning Loop
MAIN: MOV P1,#0FEH ; Drive Row1 low (others high)
JNB P1.4,K1 ; If Column1 low → Key1 pressed
JNB P1.5,K2 ; If Column2 low → Key2 pressed
JNB P1.6,K3 ; If Column3 low → Key3 pressed
JNB P1.7,K4 ; If Column4 low → KeyA pressed
Department of Electronics Engineering (VDT), BIT Page 5
Matrix Keypad Interfacing with LCD Display 2025-26
MOV P1,#0FDH ; Drive Row2 low
JNB P1.4,K5 ; Key4
JNB P1.5,K6 ; Key5
JNB P1.6,K7 ; Key6
JNB P1.7,K8 ; KeyB
MOV P1,#0FBH ; Drive Row3 low
JNB P1.4,K9 ; Key7
JNB P1.5,K10 ; Key8
JNB P1.6,K11 ; Key9
JNB P1.7,K12 ;
KeyC
MOV P1,#0F7H ; Drive Row4 low
JNB P1.4,K13 ; KeyE
JNB P1.5,K14 ; Key0
JNB P1.6,K15 ; KeyF
JNB P1.7,K16 ;
KeyD
LJMP MAIN ; Repeat scanning
continuously ; Key Mapping Section
K1: MOVA,#'1' LJMP DISP ; Load ASCII '1'
K2: MOVA,#'2' LJMP DISP ; Load ASCII '2'
K3: MOVA,#'3' LJMP DISP ; Load ASCII '3'
K4: MOVA,#'A' LJMP DISP ; Load ASCII 'A'
K5: MOVA,#'4' LJMP DISP ; Load ASCII '4'
K6: MOVA,#'5' LJMP DISP ; Load ASCII '5'
K7: MOVA,#'6' LJMP DISP ; Load ASCII '6'
K8: MOVA,#'B' LJMP DISP ; Load ASCII 'B'
K9: MOVA,#'7' LJMP DISP ; Load ASCII '7'
K10: MOVA,#'8' LJMP DISP ; Load ASCII '8'
K11: MOVA,#'9' LJMP DISP ; Load ASCII '9'
K12: MOVA,#'C' LJMP DISP ; Load ASCII 'C'
K13: MOVA,#'E' LJMP DISP ; Load ASCII 'E'
K14: MOVA,#'0' LJMP DISP ; Load ASCII '0'
K15: MOVA,#'F' LJMP DISP ; Load ASCII 'F'
K16: MOVA,#'D' LJMP DISP ; Load ASCII 'D'
DISP: MOV P2,A ; Send ASCII data to LCD
SETB P3.0 ; RS=1 (data mode)
CLR P3.1 ; RW=0 (write mode)
SETB P3.2 ; EN=1 (enable
high)
LCALL DELAY ; Wait for LCD to
latch CLR P3.2 ; EN=0 (enable low)
LCALL DELAY ; Extra delay
LJMP MAIN ; Return to scanning
loop END ; End of program
Department of Electronics Engineering (VDT), BIT Page 6
Matrix Keypad Interfacing with LCD Display 2025-26
EXPLANATION
The program continuously scans the keypad by driving each row low in turn. When a
key is pressed, the corresponding column line goes low. The microcontroller identifies the
key using the row+column combination, maps it to its ASCII code, and sends it to the
LCD. Control signals RS, RW, and EN ensure proper latching of data. The LCD then
displays the pressed key character. Simulation confirms correct mapping of all
hexadecimal digits (0–9, A–F), making the design suitable for applications requiring
hexadecimal input such as memory address entry, debugging, and digital system control.
EXPECTED OUTPUT TABLE
Key Pressed Row Value Column ASCII (Hex) LCD Display
clear
1 0FEH P1.4=0 31H 1
2 0FEH P1.5=0 32H 2
3 0FEH P1.6=0 33H 3
A 0FEH P1.7=0 41H A
4 0FDH P1.4=0 34H 4
5 0FDH P1.5=0 35H 5
6 0FDH P1.6=0 36H 6
B 0FDH P1.7=0 42H B
7 0FBH P1.4=0 37H 7
8 0FBH P1.5=0 38H 8
9 0FBH P1.6=0 39H 9
C 0FBH P1.7=0 43H C
E 0F7H P1.4=0 45H E
0 0F7H P1.5=0 30H 0
F 0F7H P1.6=0 46H F
D 0F7H P1.7=0 44H D
Department of Electronics Engineering (VDT), BIT Page 7
Matrix Keypad Interfacing with LCD Display 2025-26
RESULT
During the execution of the program in Keil, the Port 1 values is set to drive rows
low sequentially (FEH, FDH, FBH, F7H). When a key was pressed, the corresponding
column line goes low (e.g., P1.4 = 0).
When P1 = FEH and P1.4 = 0, the microcontroller identified Row 1, Column 1,
which corresponds to key ‘1’
The ASCII code 31H is sent to Port 2(0A0F) , and the LCD displays the character 1.
Before Execution
Department of Electronics Engineering (VDT), BIT
Matrix Keypad Interfacing with LCD Display 2025-26
After Execution
Department of Electronics Engineering (VDT), BIT
Matrix Keypad Interfacing with LCD Display 2025-26
When P1 = F7H and P1.7 = 0,
The ASCII code 44H is sent to Port 2(0A0F) , and the LCD displays the character D.
Before Execution
Department of Electronics Engineering (VDT), BIT
Matrix Keypad Interfacing with LCD Display 2025-26
After Execution
Department of Electronics Engineering (VDT), BIT
Matrix Keypad Interfacing with LCD Display 2025-26
CONCLUSION
The 8051 keypad–LCD interface project successfully shows how a microcontroller
can detect key presses from a 4×4 hexadecimal keypad and display them on an LCD. Each
key (0–9, A–F) is correctly identified, converted to ASCII, and displayed, confirming
proper keypad scanning and LCD communication.
This experiment proves the reliability of the 8051 for real-time input and display
applications, forming a solid base for advanced embedded projects like password
systems or digital control panels.
Department of Electronics Engineering (VDT), BIT