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

Interfacing

Keyboard
Keyboards are used for interfacing i.e., giving data and
control commands to the microcontroller-based system
The keys are usually pushbutton switches
When this pushbutton key is pressed or released, the
metal contact momentarily bounces (vibrates) before
making steady contact
To eliminate this problem, key debouncing technique
either using hardware or using software is used
(preferably software due to low cost)
In the software technique, when a key press is found, the
VCC
processor waits for at least 10 ms before it accepts the key as
an input
Based upon the way keys are connected, there are two
configurations of keyboards:
simple keyboards (one dimensional): connected directly to I/O
pins
Simple
matrix keyboards (two-dimensional): placed in the matrix with keyboard
rows and columns

Dr. Santosh Kumar Singh | GP Kuru Pindra Varanasi / Ghazipur Microcontroller | 79


Interfacing

Matrix Keyboard
To save the number of port pins, the keys are
arranged in a matrix form Vcc
Number of port pins occupied to interface N M 4.7 k
keys is only N + M instead of N M
Figure beside shows 16 keys arranged in a 4 4 3 2 1 0
4.7 k
matrix of four rows and four columns D0
The rows are connected to an output port and the 7 6 5 4
columns are connected to an input port D1
B A 9 8
If no key has been pressed, reading the input port
D2
will yield 1s for all columns since they are all F E D C
connected to high (VCC)
D3
If all the rows are grounded and a key is pressed,
Port 1
one of the columns will have 0 since the key (Out)
pressed provides the path to ground D3 D2 D1 D0
Port 2
It is the function of the microcontroller to scan the (In)
keyboard continuously to detect and identify the
key pressed
Dr. Santosh Kumar Singh | GP Kuru Pindra Varanasi / Ghazipur Microcontroller | 80
Interfacing

Scanning and Identifying Key


Steps to identify the pressed key and to generate the key codes are given below
Check for previously pressed key release:
To make sure that the preceding key has been released, 0s are output to all
rows at once, and the columns are read and checked repeatedly until all the
columns are high i.e., all keys are open
When all columns are found to be high, the program waits for a short amount
of time or debounce before it goes to the next stage of waiting for a key to be
pressed
Detect for any key press
To see if any key is pressed, columns are scanned over and over in an infinite
loop until one of them has a 0 on it since rows are grounded i.e., any key is
closed
After the key press detection, the microcontroller waits 20 ms for the bounce
and then scans the columns again to ensure no erroneous spike detection or
multiple key press detection
If the key press is genuine, it goes to the next stage to detect which row it
belongs to; otherwise, it goes back into the loop to detect a real key press
Dr. Santosh Kumar Singh | GP Kuru Pindra Varanasi / Ghazipur Microcontroller | 81
Interfacing

Scanning and Identifying Key


Detect for row of key press
To detect which row the key press belongs to, the microcontroller grounds one
row at a time, reading the columns each time
If it finds that all columns are high, this means that the key press cannot
belong to that row; therefore, it grounds the next row and continues until it
finds the row the key press belongs to
Upon finding the row that the key press belongs to, it goes to the next stage to
identify the key
Identify the key press
To identify the key press, the microcontroller finds the column to which the
pressed key belongs to
Upon finding the column, it pulls out the ASCII code for that key from the look-
up table
Figure shows flowchart for scanning and identifying the pressed key
While the key press detection is standard for all keyboards, the process for
determining which key is pressed varies, generally either using the counters
method or using look-up tables method

Dr. Santosh Kumar Singh | GP Kuru Pindra Varanasi / Ghazipur Microcontroller | 82


Interfacing

Seven-segment Display
A seven-segment display consist of a group of seven LEDs
(rectangular) to display the decimal (or hexadecimal) numbers
They also have a LED for dot point (decimal point), therefore, contain eight
LEDs in a module designated as a/A to h/H/DP

There are two types of seven-segment display modules: (i) common


cathode: where all the LEDs in the module have common cathode and,
(ii) common anode: where all the LEDs have common anode
The typical values of forward voltage VF are 2 to 3 V and forward
current IF are 10 to 20 mA, depending upon the type and size of the
LED
The current drawn by the seven-segment module is around 15 8 = 120 mA

Segment Multiplexing within one Seven-segment Display module


(i.e., only one segment is activated at a time in such a rate that it
create an illusion of simultaneous activation of all the segments)
reduces the current requirement to only 15 mA
When two or more digits are required for an application, we need to
use Digit Multiplexing
Dr. Santosh Kumar Singh | GP Kuru Pindra Varanasi / Ghazipur Microcontroller | 83
Interfacing

Seven-segment Display
Figure beside shows interfacing of four seven-
segment modules with the 8051
Four port pins of the uC are connected as an
input to the 7448 segment driver and its output
are connected to all 4 seven-segment modules in
parallel
IC7448 is a BCD to seven-segment code converter or
segment driver to provides required drive current BCD to seven segment codes
Segments
Another set of four port pins of the uC acts as Digit
h g f e d c b a
HEX Code

digit multiplexing drivers which activate any 0


1
0
0
0
0
1
0
1
0
1
0
1
1
1
1
1
0
3F h
06 h
modules by driving corresponding transistor 2 0 1 0 1 1 0 1 1 5B h
3 0 1 0 0 1 1 1 1 4F h
To display the digit, BCD code for a digit is sent 4 0 1 1 0 0 1 1 0 66 h
5 0 1 1 0 1 1 0 1 6D h
to 7448 from port pins (lower 4 bits of Port 1) and 6 0 1 1 1 1 1 0 1 7D h

to select a particular digit (module), the common 7


8
0
0
0
1
0
1
0
1
0
1
1
1
1
1
1
1
07 h
7F h
pin of the corresponding module is grounded by 9
A
0
0
1
1
1
1
0
1
0
0
1
1
1
1
1
1
67 h
77 h
making the corresponding pin of the port high B 0 1 1 1 1 1 1 1 7F h
C 0 0 1 1 1 0 0 1 39 h
(lower 4 bits of Port 2) D 0 0 1 1 1 1 1 1 3F h
E 0 1 1 1 1 0 0 1 79 h
F 0 1 1 1 0 0 0 1 71 h

Dr. Santosh Kumar Singh | GP Kuru Pindra Varanasi / Ghazipur Microcontroller | 84

You might also like