Transcript Document

Microcontroller and Systems
Part-5
Anil JB
Assistant Professor
Faculty of Engineering and Technology,
Mody Institute of Technology and science,
Lakshmangarh-332311
Sikar(Raj.)
Interfacing Keyboard and Display Devices






Topics Covered:
Interface switches and keyboard to the
8051
Interface LED displays to the 8051
Overcome Keybounce and multiple key
press problems
Design a microcontroller based system
with keyboard and display devices
Interface and program the LCD controller
Interfacing Switches
VCC
R
ON
P1.0
P1.1
P1.2
P1.3
P1.4
P1.5
P1.6
P1.7
8051
DIP
SWITCH
What is a Keyboard ?
 Collection
of keys interfaced to the
microcontroller
 Arranged in the form of two
dimensional matrix
 Matrix arrangement used for
minimizing the number of port lines
 Junction of each row and column
forms the key
Interfacing a Keyboard
+5V
P1.0
P1.1
P1.2
P1.3
P1.4
P1.5
P1.6
P1.7
8051
One key per port line
Interfacing a Keyboard
3
2
1
0
X1
7
6
5
4
X2
B
A
9
8
X3
F
E
D
C
P1.0
10K
PULL-UP
REGISTERS
P1.1
P1.2
P1.3
X4
8051
Y4
P2.3
Y3
P2.2
Y2
P2.1
Y1
P2.0
Keys are organized in two-dimensional matrix to
minimize the number of ports required for interfacing
Interfacing a Keyboard
P1.0
P1.1
D
E
C
O
D
E
R
X1
X2
X3
X4
8051
10K
10K
10K
3
2
1
0
10K
7
6
5
4
10K
B
A
9
8
F
E
D
C
Y4
P2.3
Y3
P2.2
Y2
P2.1
10K
Pull-up
registers
10K
10K
Y1
P2.0
Use of decoder further reduces the number of port
lines required
Key Issues
 Key
bounce can be overcome using
Software/Hardware approach
 Keyboard Scanning
 Multiple Key Closure
 2-key lockout
 2-key rollover
 Minimize Hardware Requirement:

Use of Keyboard Encoder
 Minimize
Software Overhead
Key bounce
VC
C1
S
1
R2
0.1F
R1
220 K
4.7K
2
P
O
R
T
1
L
I
N
E
S
2
3
74HC14
3
Hardware approach to overcome key-bounce
Keyboard Scanning
2
1
START
READ ALL PORT2 LINES
INITIALIZE PORT2 AS
INPUT AND PORT1 AS
OUTPUT
NO
SET ALL PORT1
LINES LOW
ANY KEY
CLOSED?
YES
READ ALL PORT2
LINES
DELAY FOR DEBOUNCE
SET PORT VALUES TO
SCAN ROW
ANY KEY
CLOSED?
NO
SET PORT VALUES TO
SCAN NEXT ROW
YES
GET KEYCODE FROM
TABLE
2
NO
ALL KEYS
OPEN?
YES
1
READ ALL PORT2 LINES
NO
RETURN
ANY KEY
CLOSED?
YES
2
Software approach for keyboard scanning
Hardware Approach







Use of an Encoder
Automatically translates key press code into
4-bit number
Built-in scanning circuit
Overcomes key bounce using a single
capacitor (1 µF for debounce time of 10 msec)
Keyclosure indicated by an output (DA) line
Last key pressed is stored in a latch
Examples of Encoder
 20 key encoder – 74C923
 16 key encoder - 74C922
Scanning by Hardware
4X4
KEYBOARD
BOARD
D
C
B
A
X1
X2
X3
X4
P1.0
P1.1
P1.2
P1.3
OE
Y1
Y2
Y3
Y4
OSC
0.1F
74C922
D
A
Port line /
Interrupt
input
KBM
8051
X1
X2
X3
1 .0  F
X4
SWITCH
CLOSED
Minimizes software overhead
at the expense of extra hardware
DATA OUTPUT
D C B A
Y1 X1
0 0 0 0
Y1 X2
0 0 0 1
Y1 X3
0 0 1 0
Y1 X4
0 0 1 1
Y2 Y1
0 1 0 0
Y2 Y2
0 1 0 1
Y2 Y3
0 1 1 0
Y2 Y4
0 1 1 1


Y4 X4
1 1 1 1
Display Devices

Most popular display device: LED











Very tiny in size
Available in many colors
Very reliable and rugged
Long life
Operates at low voltage
Small power consumption
Visible in darkness
Single LED
Bicolor LED
Seven Segment Displays
 Common Cathode Form (ICM 7218D)
 Common Anode Form (ICM 7218C)
Consumes large amount of current
Interfacing a single LED
Vcc
R
IF
LED
Driver circuit to
interface a single LED
SWITCH
Vt
R2
R1
Vcc
Port
line
R1
R1
Port
line
VF
Port
line
Seven Segment LEDs
a
f
e
b
a
b
c
d
e
f
g
dp
a
b
c
d
e
g
f
dp
g c
d
d
p
Common anode
Common Cathode
a
Two types: Common
cathode and common
anode type
a
e
b
b
e
c
c
b
b
g
g
c
e
d
d
f
b
f
b
f
g
g
g
c
c
e
d
f
f
c
c
a
b
f
c
e
b
g
g
e
c
d
a
b
d
a
a
a
a
Seven-segment LEDs
can be conveniently used
to display HEX characters
a
f
g
g
c
a
e
d
d
a
a
f
b
a
f
f
g
e
e
d
c
d
e
g
g
e
d
Interfacing multiple 7-Segment LEDs
+5V
3.9 K
A0
1
A1
7
A2
8
14
2 4
A3
150
11
75491
3
5
10
12
6 9 13
B1
1
7
9 13
3
5
B2
8
10
B3
14
B0
2 4
6
75491
a
12
11
150
3.9 K
+5V
+5V
3.9 K
11
75492
S0
3
2
S1
5
6
S2
8
7
S3
9
S4
10
12
S5
14
13
4
1
b c
d
e
f
g
d
p
a
b c
d
e
f
g
d
p
Multidigit Driver

Features of Multidigit Driver
 8-segment driver output lines
 8-digit driver lines
 20 mA peak current
 LEDs can withstand high peak current
 Sequencing operation:
 Select data using digit address lines DA0-2
 Write data using ID0-3 and ID7 lines
 Three modes of operation:
 HIGH: HEX, LOW: OFF, OPEN: CODEDHELP
Interfacing using Multidigit Driver
P1.0
P1.7
8051
P3.0
d
pg
f
e
d
c
b
a
ID0
ID1
ID2
ID3
ID7
DA0
DA1
DA2
WRITE
MODE
V+
GND
DIGIT1
DIGIT2
DIGIT3
DIGIT4
DIGIT5
DIGIT6
DIGIT7
DIGIT8
ICM7218D
a
b
c
d
e
f
g
dp
1
2
3
4
5
6
7
8
Liquid Crystal Displays

Key features:
 Low Power Consumption
 Voltage Controlled
 Easy to read in bright light
 Declining Cost
 Ability to display Characters/Graphics
 Intelligent controller and LCD display
panels readily available
Liquid Crystal Displays
P1.0
P1.1
P1.2
P1.3
B0
B1 DATA IN
B2
B3
P1.4
P1.5
P1.6
P1.7
D0
D1 DIGIT
D2
SELECT
D3
a

DIGIT 1
g
a

DIGIT 2
g
a
OSC

VCC
g
DIGIT 3
DISPLAY MODULE
a
GND

DIGIT 4
g
BACK
PLANE
LCD Display Module

LCD modules:
 An LCD panel and small circuit board
containing the controller chip
 14 – pin connections to microcontroller
 HITACHI’S HD44780 controller can control
up to 80 characters
 Easy to program
 2 rows, 20/40 character in each row
 Each character can be 5X8 or 5X11 matrix
LCD Display Module
CG ROM stores
segment pattern of 192
char.
+5V
CG RAM stores
segment patterns of 16
user-designed char.
An 8-bit instruction
reg.
An 8-bit data reg.
DD RAM stores up to
80 8-bit char. Codes
11 instructions clear
display, return home
2
8
0
5
1
P1.0
P1.1
P1.2
P1.3
P1.4
P1.5
P1.6
P1.7
P3.0
P3.1
P3.2
GND
3
1
D0
D1
D2
D3
D4
D5
D6
D7
RS
R/W
E
LCD Modules