0% found this document useful (0 votes)
102 views4 pages

Expt3 Keypad LCD43321

The document describes interfacing a 4x4 matrix keypad to a PIC microcontroller. It discusses the operation of matrix keypads, including how they save I/O pins by using a scanning method. The scanning sequence and key detection process are explained. It also covers keyboard debouncing. The objectives are to understand matrix keypad operation, interfacing techniques, and to interface a 4x4 keypad to a PIC microcontroller. The keypad values will be read and displayed on a 16x2 LCD.

Uploaded by

Sujal Golar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
102 views4 pages

Expt3 Keypad LCD43321

The document describes interfacing a 4x4 matrix keypad to a PIC microcontroller. It discusses the operation of matrix keypads, including how they save I/O pins by using a scanning method. The scanning sequence and key detection process are explained. It also covers keyboard debouncing. The objectives are to understand matrix keypad operation, interfacing techniques, and to interface a 4x4 keypad to a PIC microcontroller. The keypad values will be read and displayed on a 16x2 LCD.

Uploaded by

Sujal Golar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

BVCOEL

TITLE: Interfacing 4x4 Matrix Keypad to PIC Microcontroller

PROBLEM STATEMENT:
Interface 4x4 Matrix Keypad to PIC Microcontroller. Write a program in Embedded C to
display Key pressed by user on 16x2 LCD.

OBJECTIVE :
a. To understand the basic operation of Matrix Keypad.
b. To study keypad interfacing techniques
c. To interface 4x4 Matrix Keypad to PIC Microcontroller

S/W PACKAGES AND H/W USED:


MPLAB IDE, C18 Compiler, ExplorePIC Development Board

THEORY
1. Matrix Keypad Operation
Programming technique under conditions of one key has been investigated in the
Experiment 1. While in practice since usually many keys are applied to attain input signals. It’s
not economic to input one signal through one I/O line. Therefore, a new method where
keystroke signals can be attained with a small quantity of I/O pins is specified. It is called
scanning method for matrix keyboard.
When input keys are more than 4, matrix keyboard can save I/O. In following figure, 16
keys make up a 4 X4 matrix. Where 8 I/O are employed and one key can nestle on one
intersection. Attention: the two lines that formed an intersection are electrically connected only
when the key is pressed down. Among the 8 I/O lines, 4 (vertically arranged) are called
scanning line (output) and 4 (horizontally arranged) are called feedback line (input). The
signals of a matrix keyboard are read in time-sharing mode, once a line. Therefore, CPU can
attain status of keyboard after reading four times.

Figure 1.1: Matrix Keypad connection diagram

E&TC
BVCOEL

2. Key Detection
Software scanning sequence of the circuit shown in circuit diagram is as follows (Attention:
RB3—RB0 are scanning lines and must be set to output mode, while RB7—RB4 are feedback
lines and must be set to input mode.
1. Output 1110 to the scanning line RB3—RB0. Since RB0 output “0”, when keys in the
row0 that is connected to RB0 are pressed down, the status of the feedback line is “0”.
However, when keys on the other three lines/rows are pressed down, status of the
feedback line won’t be changed.
2. Input status of the feedback line (RB7—RB4), and check if the four keys in the first row
(the row controlled by RB0) are pressed down. The checking method is as follows.
Checking the four bits of the feedback lines. If one of these feedback lines is “0”, it
indicates that the key connected to this line is pressed down.

3. If there is no key pressed down in the first row, and then output 1101 to RB3-RB0 to
scan the line controlled by RB1 which is second row - Row1.
4. Input status of the feedback line again. The data attained is the status of the second
row (the row controlled by RB1), and check if there is a key pressed down.

5. Output scanning signal of 1011 to scan the line controlled by RB2 which is third row –
Row2
6. Input status of the feedback line. The data attained is the status of the third row (the
row controlled by RB2), and check if there is a keystroke.
7. Output scanning signal of 0111 to scan the line controlled by RB3 which is fourth row –
Row3.
8. Input status of the feedback line. The data attained is the status of the fourth row (the
row controlled by RB3), and check if there is a keystroke.
9. Return to step 1 to start next scanning period.

The nine steps above are repeated ceaselessly until a keystroke of a certain row is
detected (status of the feedback line is “0”), then this key will be coded by the program. There
is no standard coding ways. The coding principle is to distinguish these keys by defining
different codes for different keys.
As the keyboard shown in above figure 1.1 the keys are to be defined as the codes labeled in
the figure (‘0’, ’1’, ’2’, ’3’, ’4’, ’5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’).
The relationship between codes of keys and the ranging positions can be expressed as
follows:
Key coding = Row Number X 4 + Column number
For example, the key named 09 is arranged at Row 2 and Column 1, according to the formula:

Key code for key ‘9’ = Row Number X 4+Column number = 2 X 4 + 1

E&TC
BVCOEL

3. Keyboard debounce:
When striking a keyboard key, the key oscillates against its contacts several times
before settling. When released, it bounces again until it reverts to its rest state. Although it
happens on such a small scale as to be invisible to the naked eye, it's sufficient for the
computer to register multiple key strokes inadvertently.
To resolve this problem, the processor in a keyboard "debounces" the keystrokes, by
aggregating them across time to produce one "confirmed" keystroke that (usually) corresponds
to what is typically a solid contact. Early membrane keyboards limited typing speed because
they had to do significant debouncing.
When any of the key is pressed i.e. zero on any of the key i s detected, the controller
waits for 20mS for the key debounce and then scans the columns again. The debounce is
necessary because:
a. Waiting for key debounce help to detect if the key press was not erroneous viz due
to spike.
b. 20ms to 100ms delay also prevents the same key press from being interpreted as
a multiple key press.

E&TC
BVCOEL
5. Algorithm
1. As LCD data bus is connected to PORTD and handshaking signal EN-RE0, RS-RE1,
E-RE2, configure these pins output writing 0x00 to the appropriated TRES register.
2. The RE0, RE1, RE2 this pins have dual function (analog/digital), by default on every
reset it work as analog input. So make this pin as digital by using ADCON1 register.
3. As KBD is connected to PORTB, here rows of KBD are connected to RB3-RB0 and
column of KBD are connected to RB7-RB4, so configure column as input and row as
output by writing appropriated in TRESB register.
4. As we know the PORTB pins have dual function (analog/digital), by default on every
reset it work as analog input. So make this pin as digital by using ADCON1 register.
5. Initialize LCD.
6. Display message on first line.
7. Read key endlessly as per the procedure which we discus above
8. End

4. Source Code

E&TC

You might also like