68000 Microprocessor
Module 12: Elementary Input/Output
I/O Concepts
Typical Organization of an I/O Device
Memory-mapped vs Isolated I/O
Elementary output with latch and LED
Elementary input with buffer and switch
7-segment interfacing
© 2006-2008 [email protected] 11-1
7-segment interfacing
Keypad interfacing (extra)
68000 Microprocessor
Input and Output (I/O)
One of the basic and essential features designed in a computer system is its ability to exchange data with other external devices, and to allow the user to interact with the system:
Input Devices include: Switches, Keyboards, Mice, Scanners, Cameras, etc.
Output devices include: Lamp/LED/LCD displays, Video monitors, Speakers, Printers, etc.
One or more interface circuits usually are used between I/O devices and the CPU to:
© 2006-2008 [email protected] 11-2
the CPU to:
Handle transfer of data between CPU and I/O interface.
Handle transfer of data between I/O device and interface.
Enable the CPU to request the status of data sent/received by the interface.
Common I/O interfaces:
Elementary I/O: Simple two-state devices such as LED and switches
Peripheral I/O: Non-trivial interaction with complex I/O devices such as printers and keyboards
68000 Microprocessor
Elementary I/O
Two-state peripheral devices
May involve more than one bit - e.g., BCD
Requirements
Bit signals can be written to output devices under program control
Bit signals can be read from input devices under program control
Devices required
Latches such as 74LS374 for output
Tri-state buffers such as 74LS244 for input
© 2006-2008 [email protected] 11-3
Tri-state buffers such as 74LS244 for input
Example Output devices
LED, bulbs
Relay coils
7-segment display
Example Input devices
Push button
Proximity switch
Rotary BCD coder
68000 Microprocessor
Address
CPU
Memory I/O Device
Data
Read
Write
I/O Schemes
Memory-mapped I/O
The I/O devices and memory
components are resident in the
same memory space
The microprocessor uses the
same instruction set for I/O
operations
Isolated I/O
© 2006-2008 [email protected] 11-4
CPU
MemoryI/O Device
Data
Read
Write
Address
I/O Port
Memory I/O
Isolated I/O
The microprocessor has a
separate address space for I/O
devices
The microprocessor has
dedicated instructions for I/O
operations
Special bus lines
Traditionally, Intel microprocessors use the isolated I/O method, whereas Motorola microprocessors use the memory-mapped I/O method.
68000 Microprocessor
Memory Mapped I/O
Part of the CPU's normal memory space is dedicated to I/O operations and all I/O ports look exactly like normal memory locations.
Pros
Rich set of addressing modes for I/O operation (e.g. bit manipulation)
No overhead on special instructions ProgramProgram
000000000000
004000004000
© 2006-2008 [email protected] 11-5
No overhead on special instructions
Cons
Processor’s address space is allocated to I/O devices
Risk of errors due to spurious accesses (elaborated address decoding)
Lack of special purpose I/O signals to control the I/O operation
ProgramProgram
DataData
I/OI/O
220000000000
808000000000808000030003
68000 Microprocessor
Peripheral I/O Concepts
I/O devices (peripheral devices) Equipment that exchange data with a computer.
May itself contain a microprocessor!
Examples include printers, modems, keyboards, and disk drives.
Interface (peripheral) chip A chip whose function is to synchronize data transfer between the CPU
and I/O devices.
© 2006-2008 [email protected]
An interface may consist of control registers, status registers, data registers, and control circuitry.
An interface chip has data pins that are connected to the CPU and I/O port pins that are connected to the I/O devices.
Data transfer between an I/O device and the CPU can be proceeded bit-by-bit (serial) or in multiple bits (parallel).
68000 Microprocessor
I/O Transfer Synchronization
The role of an interface chip
Synchronizing data transfer between the CPU and the interface chip.
Synchronizing data transfer between the interface chip and the I/O device.
© 2006-2008 [email protected]
68000 Microprocessor
Synchronizing µP and the Interface Chip
The polling method
Repeatedly checks the status of an I/O device (through a status register of the associated I/O controller) until the desired condition is met
This process is called polling
Polling involves overhead
Repeated testing of condition
© 2006-2008 [email protected]
Repeated testing of condition
Can be used to handle only anticipated event
The interrupt-driven method
Processor gets interrupted when a specified event occurs
Very efficient
Can be used to handle unanticipated events
68000 Microprocessor
Polled I/O
Usually in the interface chip we have
Control register
a register where the processor is placing commands
Data register
input and output data registers where the data is made available to/from the processor
Status register
© 2006-2008 [email protected]
a register that shows the status of the peripheral device
For input -- the microprocessor checks a status bit of the interface chip to find out if new data has been received from the input device.
For output -- the microprocessor checks a status bit of the interface chip to find out if it can send new data to the interface chip.
68000 Microprocessor
A Generic Interface Chip
Chip select
Register select
Register select
R/W
CS
RS1
RS0
R/W
Timingand
Control
Busbuffers
Bidirectionaldata bus
Port Aregister
Port Bregister
Controlregister
Statusregister
I/O data
I/O data
Control
Status
CPU I/ODevice
© 2006-2008 [email protected]
register
InputsRegister Selected
E RS1 RS0
1 X X None
0 0 0 Port A Register
0 0 1 Port B Register
0 1 0 Control Register
0 1 1 Status Register
68000 Microprocessor
Communicating with External Devices : Parallel Interface
Several ports each 1-byte wide
A full byte of data or more is transferred on data cycle.
Example devices:
MC6821 PIA for 6800 CPU
MC68230 PIT for 68000 CPU
They are general purpose devices
Direction of data flow is programmable, unlike in elementary I/O
© 2006-2008 [email protected]
Direction of data flow is programmable, unlike in elementary I/O
Strobe and handshaking lines for more efficient data transfers.
May interrupt the CPU if peripheral is ready for data
These devices are often quite complex and can operate in one of several modes
68000 Microprocessor
Communicating with External Devices : Serial Interface
Serial data transmission
One bit is transferred for each clock cycle.
cheap, simple, easy to use
Connects the µP to another µP or peripheral such as modem
Example devices:
MC6850 ACIA for 6800 CPU
MC68681 DUART for 68000 CPU
© 2006-2008 [email protected]
They are programmable devices
To use, the designer must program number of bits per character (not necessarily 8 bit/char), parity etc
Can interrupt µP when peripheral is ready
Possible to connect many device to single serial line (multidrop).
68000 Microprocessor
LEDs – Simples Elementary Output
An LED is a semiconductor device that converts electrical energy directly into a discrete color of light
Can be visible or IR
White LEDs are blue LEDs plus phosphor
1.5 - 2 V voltage drop
© 2006-2008 [email protected] 11-13
1.5 - 2 V voltage drop
Typically draws 10-20 mA
Wire BondAnode Lead Cathode LeadEpoxy CaseEpoxy LensSemiconductor Diode Reflective Cup
68000 Microprocessor
Turning on an LED
+5VR
output pin1
No current
LED
no light+5V
Note: A zero turns on the LED
© 2006-2008 [email protected] 11-14
+3.2VCurrent
light
R =voltage
current=
2.8
13 x 10-3 ~ 220 ohms
+5VR
output pin0
LED
+0.4V
68000 Microprocessor
Interfacing LED with Latch
Unlike diodes, Light-emitting diodes have a forward voltage drop from 1.7 to 2.5 volts and most of them flow a forward current 10-20mA.
Poor circuit
TTL outputs can't source above 1mA so the LED will be very dim.
Fair circuit
The LED will conduct heavily at about 2V and the extra 3V has to be dropped in the TTL circuitry. This
© 2006-2008 [email protected] 11-15
extra 3V has to be dropped in the TTL circuitry. This causes high power dissipation in the TTL or the LED fails.
Good circuit
The resistor limits the current. The resistance can be calculated by assuming its voltage is about 2V and the TTL output is 0.4V. See previous page. The resistor should not less than 100ohm or the LED would fail.
68000 Microprocessor
Simple Interfacing CPU to LED
+5V
220ž74LS374
D7
D6
D5
D4
D3
Q7
Q6
Q5
Dari bas data
220ž
220ž
220ž
D7
D6
D5
D4
D3
LED EQU $E00010
START ORG $1000
MOVEQ #1,D0
LOOP MOVE.B D0,LED
© 2006-2008 [email protected] 11-16
D3
D2
D1
D0
LE
OE
Q4
Q3
Q2
Q1
Q0
data 68000
Dari penyahkod alamat
220ž
220ž
220ž
220ž
220ž
D3
D2
D1
D0
MOVE.L #200000,D1
DELAY SUBQ.L #1,D1
BNE DELAY
ROR.B #1,D0
BRA LOOP
END START
68000 Microprocessor
7-Segment Display
There are applications where you need to display a decimal digit using a seven segment LED display.
The display could represent e.g. the number of times a switch was pressed.
Digits 0-9 and hex A-F can be displayed by giving the proper 7-segment codes
q g f e d c b a q g f e d c b a
0 0 1 1 1 1 1 1 8 1 1 1 1 1 1 1
© 2006-2008 [email protected]
0 0 1 1 1 1 1 1 8 1 1 1 1 1 1 1
1 0 0 0 0 1 1 0 9 1 1 0 0 1 1 1
2 1 0 1 1 0 1 1 A 1 1 1 0 1 1 1
3 1 0 0 1 1 1 1 b 0 0 1 1 1 1 1
4 1 1 0 0 1 1 0 C 0 1 1 1 0 0 1
5 1 1 0 1 1 0 1 d 1 0 1 1 1 1 0
6 1 1 1 1 1 0 1 E 1 1 1 1 0 0 1
7 0 0 0 0 1 1 1 F 1 1 1 0 0 0 1
68000 Microprocessor
Types of 7 Segment Displays
Common-anode (CA):
LED ON when Output is LOW.
8 cathode legs, 1 anode
Common-cathode (CC):
LED ON when Output is HIGH.
8 anode legs, 1 cathode
TTL and CMOS devices are normally not used to drive the
© 2006-2008 [email protected] 11-18
normally not used to drive the common-cathode display directly because of current (mA) requirement. A buffer circuit is used between the decoder chips and common-cathode display
68000 Microprocessor
Using Lookup Tables
Using lookup table to drive the 7-segment displays will result in efficient programs.; Driver subroutine to display digits
; Digit to be displayed in D0
; Address of interface is "DISP"
; Table of segments is "DIGTAB"
DSPLAY: MOVEM.L A0/DO,-(A7)
MOVE.L #DIGTAB,A0
EXT.W D0
© 2006-2008 [email protected] 11-19
EXT.W D0
EXT.L D0
ADD.L D0,A0
MOVE.B (A0),DISP ;OUTPUT
MOVEM.L (A7)+,A0/D0
RTS
; Format of 7-segment: 0gfedcba Common-anode
DIGTAB: DC.B %00111111, %00000110
DC.B %01011011, %01001111
DC.B %01100110, %01101101
DC.B %01111101, %00000111
DC.B %01111111, %01100111
68000 Microprocessor
Elementary Input with 68000
Simplest input device is the three-state buffer .
Buffer is very fast (around 20 ns), so DTACK* does not need to be delayed.
Needs only 1 memory address.
D0-D7 atau
68000 Penimbal
D0-D7
© 2006-2008 [email protected] 11-20
atau D8-D15
A1-A23
AS
DTACK
Penyahkod alamat
OE
D0-D7
Punca DTACK daripada peranti lain
Vcc
68000 Microprocessor
Interfacing Switch with 68000
Poor circuit
Logic 1 is stable when the switch is closed. But when the switch is open, the input floats to a noise-sensitive high rather than a low. An open TTL pin is usually read as logic 1 but the pin may picks up noise like an antenna. Impossible to get a stable low input.
Fair circuit
© 2006-2008 [email protected] 11-21
Fair circuit
Requires a very small the pull-down resistor. Otherwise, the pin will rise above 0.9V when the resistor passes the 1.6mA sinking current. When the switch is closed, the circuit waste a large current since virtually no current flows into the pin. The only advantage is that a switch closure gives logic 1.
68000 Microprocessor
Interfacing Switch with 68000
Good Circuit
When the switch is open, the 10k resistor
supplies very small current needed for logic
1. When it is closed, the port pin is short to
ground. The voltage is 0V and all the sinking
current requirement is met, so it is logic 0.
The 10k resistor will pass 0.5 mA (5 Volt/10k
ohm). Thus the circuits waste very little
current in either state. The drawback is that
the closure of switch gives logic 0 and
© 2006-2008 [email protected] 11-22
the closure of switch gives logic 0 and
people like to think of a switch closure gives
logic 1. But this is not a matter because it is
easy to handle in software.
To conclude, driving a TTL input should always consider current sinking (pulling input to 0V).
68000 Microprocessor
Interfacing Switch with 68000
+5V
1kž
1kž
74LS244
D7
D6
Q7
Q6
D7
D6
;
; ATURCARA UNTUK MENGUJI SUIS
;
SUIS EQU $800001 ;ALAMAT SEBENAR BERGANTUNG SISTEM
LED EQU $A00001
ORG $1000
START MOVE.B SUIS,LED
© 2006-2008 [email protected] 11-23
1kž
1kž
1kž
1kž
1kž
1kž
1kžOE1
OE2
D6
D5
D4
D3
D2
D1
D0
Q6
Q5
Q4
Q3
Q2
Q1
Q0
Ke bas data 68000
Dari penyahkod alamat
D6
D5
D4
D3
D2
D1
D0
BRA START
END
68000 Microprocessor
VDD
Set
Reset
R
R
Q
Reset Set
Q
(a) Set-reset latch
RV
DD
Switch Debouncing
When mechanical switches are opened or closed there are brief oscillations due to mechanical bouncing (switch bounce).
key bounce, tBOUNCE
© 2006-2008 [email protected] 11-24
4050 Vout
(b) CMOS gate debouncer
VDD
Vout
H
L
Threshold level
Switch closed
(c) Integrating RC circuit debouncer
Figure 7.42 Hardware debouncing techniques
R
C
3 basic hardware debouncing methods SR latches
Non-inverting CMOS gates
Integrating debouncer
The most popular and simple one has been the wait and see method. The program simply waits for about
10 ms and reexamines the same key again to see if it is still pressed.
68000 Microprocessor
BCD-to-7-Segment Decoder/Driver
(a) BCD-to-7-segment decoder/driver driving a common-anode 7-segment
© 2006-2008 [email protected] 11-26
segment LED display;
(b) segment patterns for all possible input codes.
68000 Microprocessor
CPU checks
Keypad Decoding: 4x4 or 4x3 keypad
© 2006-2008 [email protected] 11-27
checks these lines
CPU sends low signal to these
lines
68000 Microprocessor
Row 0
Row 1
Row 2
Row 3
0 1 2 3
4 5 6 7
8 9 A B
C D E F
Row 1
01 01
Decoding the Keyboard Matrix
Pressing 5Example: press 5 and E
Col 1
5
E
© 2006-2008 [email protected] 11-28
Col 0
Col 1
Col 2
Col 3
11 10
Pressing E (=14)
Row 3 Col 2
68000 Microprocessor
123
171615
Y1Y2
DOADOBConnect to column pins Row & col position
74C922 Keypad Encoder
Performs the decoding and debouncing in hardware
© 2006-2008 [email protected] 11-29
74C922
34
111087
56
13
1514
12
Y2Y3Y4X1X2X3X4
OSCKBM
OE
DOBDOCDOD
DA
Connect to column pins
Connect to row pins
Connect to oscillator
Low to enable output
Row & col position
DA means Data
Available
High when a key
is pressed
68000 Microprocessor
74LS244
To 68000Data Bus
D1D2D3D4D5D6
74C9221234
1110
8
17161514
Y1Y2Y3Y4X1X2X3
DOADOBDOCDOD
74C922 Keypad Encoder
D0
© 2006-2008 [email protected] 11-30
HL
U9C
74LS14
56
D6D7
C1
0.068µF
C1
0.68µF
87
56
13 12
X3X4
OSCKBM
OE DA
Wait until DA pin high before accepting the 4-bit data
68000 Microprocessor
Interfacing Other Devices with Latches
Buzzers: Most latches do not have the current
capacity to drive a buzzer directly so a
transistor is added.
Diode protects coil transient voltages.
Relays:
A relay is an excellent way of isolating
the latch & CPU from high voltage
circuits.
Use a relay to control motors,
solenoids, lamps etc.
+
+5V
2N3904
+5VRelay
N.S.To Indicating
© 2006-2008 [email protected] 11-31
From latch2.2KΩ
Q1
C
B
E
D 1
2N3904NPN
PiezoBuzzer
-
2.2KΩ
Q1
C
B
E
D 1
2N3904NPN
N.O.
N.S.To Indicating Light
DC Motor
12 VDC
From latch
68000 Microprocessor
Liquid Crystal Displays: HD44780
The HD44780 is an industry standard LCD controller.
An I/O port can easily be used to interface with the HD44780.
By controlling the value of RS and R/W the MCU can easily either sends instructions or data to the controller.
Most operations require 40 micro seconds to complete.
© 2006-2008 [email protected] 11-33