Experiment 04

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

EXPERIMENT 04

Interfacing Keypad to 8051 Microcontroller and Displaying Results on SSD

Objective:

• Interfacing 4x3 keypad with 8051 microcontroller


• Displaying the pressed key number on seven segment display

Equipment:

• Hardware:
1. 8051 microcontroller
2. Seven segment displays (SSDs)
3. 4x3 Keypad
4. Resistances
• Software:
1. Keil µVision
2. SmartPRO 5000U
3. Proteus

Introduction:

Interfacing 8051 microcontroller to keypad helps in the design of various applications which control
different processes and actions by just a key press. One can design a password protected application using
keypad digits or provide users with different options represented by different digits by using keypad
interfacing.

Keypad:

A keypad is a block of buttons set with an arrangement of digits, symbols, or alphabetical letters. A keypad
is a specially designed circuitry which works on row and column selection operation. When a key is pressed,
a row is internally shorted with a column corresponding to that digit. A 4x3 keypad is shown below:
A 4x3 keypad has12 individual push buttons and the configuration requires 13 input pins (one for each key
and a ground pin) in order to make them work. However, with matrix arrangement, one only needs 7
microcontroller pins (4-rows and 3-columns) to scan through the keypad.

The working principle of keypads is very simple. When a button is pressed, it shorts one of the row lines to
one of the column lines, allowing current to flow between them. For example, when key ‘4’ is pressed,
column 1 and row 2 are shorted.
The pins are connected at the top of keypad starting from left and advance toward right. Each pin should
be connected to one pin of an I/O port.
Scanning a Keypress:
A microcontroller can scan a keypress by following the given steps:
1. A microcontroller sets all the row lines to HIGH.
2. Then, it picks a row and sets it LOW and checks the column lines one at a time.
3. If the column connection stays HIGH, the button on the row has not been pressed.
4. If it goes LOW, the microcontroller figures which button was pressed corresponding to the detected
row and column.

Procedure:

• Verify all the pin connections of keypad by using voltmeter.


• Calculate the sequences required for all the keys of keypad depending on the type of SSD being
used.
• Write the code to interface 8051 microcontroller accordingly and generate hex file.
• Implement the circuit to interface keypad and SSD to the microcontroller.
• Verify the output displayed on SSD against each key press.
Lab Task 1:
Write a code to interface a 4x3 keypad with 8051 microcontroller, burn the hex file in microcontroller and
display the results on SSD. Verify these results in Proteus.

Code
ORG 0000H
MOV DPTR,#lookupTable
MOV A,#11111111B
MOV P2,#00000000B
LOOP:MOV P1,#11111111B
CLR P1.0
JB P1.4,Disp2
MOV A,#1D
ACALL DISPLAY
Disp2:JB P1.5,Disp3
MOV A,#2D
ACALL DISPLAY
Disp3:JB P1.6,Disp4
MOV A,#3D
ACALL DISPLAY
Disp4:SETB P1.0
CLR P1.1
JB P1.4,Disp5
MOV A,#4D
ACALL DISPLAY
Disp5:JB P1.5,Disp6
MOV A,#5D
ACALL DISPLAY
Disp6:JB P1.6,Disp7
MOV A,#6D
ACALL DISPLAY
Disp7:SETB P1.1
CLR P1.2
JB P1.4,Disp8
MOV A,#7D
ACALL DISPLAY
Disp8:JB P1.5,Disp9
MOV A,#8D
ACALL DISPLAY
Disp9:JB P1.6,Disp0
MOV A,#9D
ACALL DISPLAY
Disp0:SETB P1.2
CLR P1.3
JB P1.5,LOOP
MOV A,#0D
ACALL DISPLAY
LJMP LOOP
DISPLAY:MOVC A,@A+DPTR
MOV P2,A
RET
lookupTable: DB 11000000b, 11111001b, 10100100b, 10110000b, 10011001b, 10010010b,
10000010b, 11111000b, 10000000b, 10010000b
end

Procedure
First, I made a lookup table, then I set Accumulator register as input & port 2 as output. Next, I
started a loop & initialized port one will one’s. Then I clear P1.0 & used ‘JB’ command to check
whether P1.4 is zero the display ‘1’ other wise move to next check of ‘disp’ function & same
procedure for the next columns. Then for row 2 I used SETB to set P1.0 to 1 & cleared P1.1 &
the same process as used in row 1 & repeated the same process.
Proteus Simulation
Lab Task 2:
Write a code to interface a 4x4 keypad with 8051 microcontroller and verify the results in Proteus.

Code
ORG 0000H
MOV DPTR,#lookupTable
MOV A,#11111111B
MOV P2,#00000000B
LOOP:MOV P1,#11111111B
CLR P1.0
JB P1.4,Disp2
MOV A,#7D
ACALL DISPLAY
Disp2:JB P1.5,Disp3
MOV A,#8D
ACALL DISPLAY
Disp3:JB P1.6,Disp4
MOV A,#9D
ACALL DISPLAY
Disp4:SETB P1.0
CLR P1.1
JB P1.4,Disp5
MOV A,#4D
ACALL DISPLAY
Disp5:JB P1.5,Disp6
MOV A,#5D
ACALL DISPLAY
Disp6:JB P1.6,Disp7
MOV A,#6D
ACALL DISPLAY
Disp7:SETB P1.1
CLR P1.2
JB P1.4,Disp8
MOV A,#1D
ACALL DISPLAY
Disp8:JB P1.5,Disp9
MOV A,#2D
ACALL DISPLAY
Disp9:JB P1.6,Disp0
MOV A,#3D
ACALL DISPLAY
Disp0:SETB P1.2
CLR P1.3
JB P1.5,LOOP
MOV A,#0D
ACALL DISPLAY
LJMP LOOP
DISPLAY:MOVC A,@A+DPTR
MOV P2,A
RET
lookupTable: DB 11000000b, 11111001b, 10100100b, 10110000b, 10011001b, 10010010b,
10000010b, 11111000b, 10000000b, 10010000b
end

Proteus Simulation
First, I made a lookup table, then I set Accumulator register as input & port 2 as output. Next, I
started a loop & initialized port one will one’s. Then I clear P1.0 & used ‘JB’ command to check
whether P1.4 is zero the display ‘7’ other wise move to next check of ‘disp’ function & same
procedure for the next columns. Then for row 2 I used SETB to set P1.0 to 1 & cleared P1.1 &
the same process as used in row 1 & repeated the same process.
Proteus Simulation

Conclusion:
In this lab, we have learnt about the interfacing a keypad to a micro-controller and displaying the
number pressed on keypad on seven segment. We have also learnt some new commands in
assembly language which helped us in coding.

You might also like