Experiment 04

You might also like

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

EXPERIMENT 04

INTEFACING KEYPAD TO MICROCONTROLLER AND


DISPLAYING RESULT ON SSD

OBJECTIVE:
 Interfacing Hex keypad to microcontroller
 To make students enable of controlling devices using a key press
 Displaying the number pressed against the pressed key on seven segment
display
 Making students enable to read data from the port

EQUIPMENT:
HARDWARE:
 AT89c51 microcontroller

 keypad

 Seven segment displays (SSDs)

 Resistances

SOFTWARE:
 Keil u-vision

 Proteus

 Smart-pro 5000u

DISCUSSION:
In this experiment we will interface 8051 microcontroller to keypad. This experiment
will help you to design different applications to control different processes and actions
using 8051 by just a key press. You can design a password protected application using
keypad digits or you can provide the user with different options represented by
different digits.
KEYPAD:
Keypad is a specially designed circuitry which works on row and column selection
operation. When a key is pressed, this action internally shorts a row with a column
corresponding to that digit.

General Layout:

1 2 3

4 5 6

7 8 9

* 0 #

PIN CONFIGURATION:

PIN DESCRIPTION

1 ROW 12 3

2 ROW 4 5 6

3 ROW 7 8 9

5 COL 1 4 7 *

6 COL 2 5 8 0

7 COL 3 6 9 #

8 NOT USED

 Each switch/key shorts one row to one column, for example if you press one t
hen row one would get shorted to column one
 The pins are connected at the top of keypad starting from left and advance
toward right.

 Each pin should be connected to one bit of an I/O port

CODING GUIDLINE:
As seen in pin configuration keypad has no pin for power supply so we provide binary
one to make a row or column one or high. When you will start coding for keypad you
will scan either rows or columns, referring to circuit diagram shown:

U?
19 39
XTAL1 P0.0/AD0
38
P0.1/AD1
37
P0.2/AD2
18 36
XTAL2 P0.3/AD3
35
P0.4/AD4
34
D1 P0.5/AD5
33
P0.6/AD6
9 32
RST P0.7/AD7

LED-BIRY 21
P2.0/A8

3
22
D2 P2.1/A9
29
PSEN
P2.2/A10
P2.3/A11
23
24
A 1 2 3
30 25
ALE P2.4/A12
LED-BIRY 31 26
EA P2.5/A13
D3 P2.6/A14
P2.7/A15
27
28
B 4 5 6
1 10
P1.0 P3.0/RXD
D4
LED-BIRY 2
3
P1.1
P1.2
P3.1/TXD
P3.2/INT0
11
12
C 7 8 9
4 13
P1.3 P3.3/INT1
5 14
P1.4 P3.4/T0
D5(A2)
LED-BIRY
D5
6
7
P1.5
P1.6
P3.5/T1
P3.6/WR
15
16
D 0 #
8 17
P1.7 P3.7/RD
AT89C51
LED-BIRY
D6

LED-BIRY
D7

LED-BIRY

D8

LED-BIRY

As you can see columns are connected to P2.0 to P2.2 and rows are connected to P2.4
to P2.7, so if you start with scanning the columns then you will first make all the
columns high by providing the sequence

mov p2, #00001111b

when for example user will press one, four, seven or star, column one will get shorted
to row one, two, three or four. First you will check the pressed column by using
statement:

jnb p2.2, check_row1_dig


JNB is used because when column one will get short to any row the high voltage on
that column would sink to low voltage of corresponding row. After scanning column
now you will change the sequence and scan rows now.

For example the label for column one would be:

check_row3_dig:

mov p2, #0ffh

mov p2, #11111110b

jnb p2.4, cpl_p1_0

jnb p2.5, cpl_p1_1

jnb p2.6, cpl_p1_2

jnb p2.7, cpl_p1_3

jmp cont

cpl_p1_0 is a name corresponding to digit one. You will make labels for all digits.
You can generate a sequence for SSD or any unique sequence corresponding to that
digit.for example for digit one:

cpl_p1_0:

mov p1, #7

jnb p2.4, $

jmp cont

At the end of each label jmp cont is used to ensure that the code is valid for multiple
or infinite key presses. ” jnb p2.4, $” is used to stay on this command till the key is
pressed, and return back to cont label after the key has been released.

PROCEDURE:
 Verify all the pin connections of keypad first by using voltmeter

 Calculate the sequences required for all the keys of keypad

 Code microcontroller accordingly and generate hex file

 Implement the circuit to interface keypad and SSD to the controller, make sure
that you connect the ports to keypad and SSD as you have designed in code

 Verify the output against each key.


Tasks
1. Implement the circuit to interface keypad and SSD to the controller, and verify the
output against each pressed key.

You might also like