13
INTERFACING KEYPAD AND DISPLAY THE KEY PRESSED ON SSD USING 8051

Micro c lab4(keypad)

  • Upload
    mashood

  • View
    97

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Micro c lab4(keypad)

INTERFACING KEYPAD AND DISPLAY THE KEY

PRESSED ON SSD USING 8051

Page 2: Micro c lab4(keypad)

Objectives of the Lab

Learning how a keypad works

Learning how to take input using 8051

Understanding the interfacing of keypad with 8051

Displaying SSD according to the key pressed on keypad

Page 3: Micro c lab4(keypad)

Deciding Pins or Ports to use

Use with

caution

If EA high*As keypad is

being used as

input, we can

use any port

except port0.

Let’s use port2

for keypad and

port1 for SSD

Page 4: Micro c lab4(keypad)

Keypad Keypads are usually used

for user input.

The numbers on the top

make them very easy for

a user to be used as an

input for a program.

It is widely used in

applications that use

MENU to work on.

There are 7 pins for 3x4

and are 8 pins for 4x4

keypad.

Page 5: Micro c lab4(keypad)

Keypad Internal Circuit Whenever a key is

pressed, a certain row and a column gets short.

With keypad, we only need to find out which row and column is short.

Then, we only need to know which key will make that particular row and column short.

We will use this property of the device to our advantage.

Page 6: Micro c lab4(keypad)

Keypad with 8051 We will use a 3x4 keypad, so we will have 7 pins.

These pin represents 3 columns and 4 rows.

We need to detect when a key is pressed and which key is pressed.

The process of finding the key is done by scanning.

Scanning ROWs is done by first making rows as input and giving columns a ground.

When the key is pressed, we know the row from which the button is pressed.

Then, we scan COLs by making cols as input and giving rows a ground.

This process happens so fast that still the same key is pressed and we know the column from which the button is pressed. Thus we have the corresponding key.

Page 7: Micro c lab4(keypad)

Instructions used in this Lab

JB Px.y,label

JNB Px.y,label

CJNE REG,DATA,LABEL (See instruction set)

See instruction set for the details of above commands.

Page 8: Micro c lab4(keypad)

Taking input using 8051 To interface a keypad, we need to learn how to take input.

There are two formats to take input, one is 1-bit and other is 8-bit commonly known as single bit input and port input.

In both processes, we simply set the pin or port (all pins) to ‘one’ and then make decisions later in the code.

e.g. setb p1.0

jb p1.0,$

jmp myfunc

Also, mov p1,#0FFh

cjne p1,#55,newfunc

jmp exit1

Page 9: Micro c lab4(keypad)

Keypad connections with

8051

First, we need to define the pins that can

be sorted into the columns and rows.

We can do that by using DMM; if the

same pin is short when all the keys from

the same column are pressed then this key

is corresponding to column 1.

After that, we will know which pin is for

which column or row.

Then, we can assign pins to rows and

columns and write our code.

Normally the order followed is

C3

P1.0

C2

P1.1

C1

P1.2

R1

P1.6

R2

P1.5R1

P1.4R1

P1.3

R1 R2 R3 R4 C1 C2 C3

P1.6,5,4,3,2,1,0

R1 R2 R3 R4 C1 C2 C3

P1.6 P1.5 P1.4 P1.3 P1.2 P1.1 P1.0

Page 10: Micro c lab4(keypad)

Algorithm for Keypad and SSD

DisplayStart

Scan Rows

main:

mov p2,#0FFh

mov p2,#11111000b

row1:

mov p2,#0FFh

mov p2,#00000111b

jnb p1.2,one

jnb p1.1,two

jnb p1.3,three

jmp main

one: mov p1,#0F9h

jmp main

. . .

jnb p1.6,row1

jnb p1.5,row2

jnb p1.4,row3

jnb p1.3,row4

jmp main

Key from which col?

Scan Cols

Scan Cols

Scan Cols

Scan Cols

row1 row4row2 row3

Key from which row?

Digit Display

0 1 2 3 4

0C0h 0F9h 0A4h 0B0h 099h

5 6 7 8 9

092h 082h 0F8h 080h 098h

Page 11: Micro c lab4(keypad)

Configuration of Keypad available

in Lab

7 1 2 4 3 5 6

R1 R2 R3 R4 C1 C2 C3

P1.6 P1.5 P1.4 P1.3 P1.2 P1.1 P1.0

Page 12: Micro c lab4(keypad)

Proteus Devices needed in this Lab

1. AT89c51

2. Keypad

3. 7-seg-CA

Page 13: Micro c lab4(keypad)

Lab Tasks Show the digit on SSD corresponding to the key

pressed on Keypad.