Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
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 Keypad interfacing (extra) © 2006-2008 [email protected] 11-1 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: Output devices include: Switches, Keyboards, Mice, Scanners, Cameras, etc. 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: 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 © 2006-2008 [email protected] 11-2 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 Example Output devices LED, bulbs Relay coils 7-segment display Example Input devices Push button Proximity switch Rotary BCD coder © 2006-2008 [email protected] 11-3 68000 Microprocessor I/O Schemes Address 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 Data CPU Read Write Memory I/O Device 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. © 2006-2008 [email protected] Address CPU Data Memory I/O Read Write I/O Port Memory I/O Device 11-4 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 00 000000 0000 004000 Program 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 © 2006-2008 [email protected] 200000 80 800000 0000 80 800003 0003 Data I/O 11-5 68000 Microprocessor Peripheral I/O Concepts I/O devices (peripheral devices) Interface (peripheral) chip Equipment that exchange data with a computer. May itself contain a microprocessor! Examples include printers, modems, keyboards, and disk drives. A chip whose function is to synchronize data transfer between the CPU and I/O devices. 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). © 2006-2008 [email protected] 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 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 © 2006-2008 [email protected] 68000 Microprocessor Polled I/O Usually in the interface chip we have Control register Data register a register where the processor is placing commands input and output data registers where the data is made available to/from the processor Status register 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. © 2006-2008 [email protected] 68000 Microprocessor A Generic Interface Chip Bidirectional data bus CPU Chip select Register select Register select R/W I/O data Port B register I/O data Bus buffers CS RS1 RS0 Control register Timing and Control Status register R/W Inputs © 2006-2008 [email protected] Port A register Register 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 Control Status I/O Device 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 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 © 2006-2008 [email protected] 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 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). © 2006-2008 [email protected] 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 Typically draws 10-20 mA Semiconductor Diode Wire Bond Anode Lead © 2006-2008 [email protected] Epoxy Lens Epoxy Case Reflective Cup Cathode Lead 11-13 68000 Microprocessor Turning on an LED Note: A zero turns on the LED No current no light +5V +5V R LED 1 output pin light Current +3.2V +5V R LED R= © 2006-2008 [email protected] voltage current = +0.4V output pin 0 2.8 13 x 10 -3 ~ 220 ohms 11-14 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 Fair circuit TTL outputs can't source above 1mA so the LED will be very dim. The LED will conduct heavily at about 2V and the 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. © 2006-2008 [email protected] 11-15 68000 Microprocessor Simple Interfacing CPU to LED LED EQU $E00010 START ORG $1000 +5V 74LS374 MOVEQ LOOP DELAY MOVE.B MOVE.L SUBQ.L BNE ROR.B #1,D0 D0,LED #200000,D1 #1,D1 DELAY #1,D0 BRA LOOP END START © 2006-2008 [email protected] D7 D6 D5 D4 D3 D2 D1 D0 D7 D6 D5 D4 D3 D2 D1 D0 Q7 Dari penyahkod alamat LE Q1 OE Q0 Dari bas data 68000 Q6 Q5 Q4 Q3 Q2 220ž 220ž 220ž 220ž 220ž 220ž 220ž 220ž 11-16 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 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 © 2006-2008 [email protected] 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 common-cathode display directly because of current (mA) requirement. A buffer circuit is used between the decoder chips and common-cathode display © 2006-2008 [email protected] 11-18 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 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 © 2006-2008 [email protected] 11-19 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. 68000 Penimbal D0-D7 atau D8-D15 D0-D7 A1-A23 Penyahkod alamat OE AS Vcc DTACK Punca DTACK daripada peranti lain © 2006-2008 [email protected] 11-20 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 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. © 2006-2008 [email protected] 11-21 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 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). © 2006-2008 [email protected] 11-22 68000 Microprocessor Interfacing Switch with 68000 ; ; ATURCARA UNTUK MENGUJI SUIS ; SUIS EQU $800001 ;ALAMAT SEBENAR BERGANTUNG SISTEM LED EQU $A00001 +5V 74LS244 ORG $1000 1kž D7 Q7 D7 START MOVE.B SUIS,LED 1kž Q6 D6 D6 Ke Q5 D5 BRA START 1kž bas Q4 D4 D5 data END 1kž Q3 D3 68000 D2 D1 D0 Q2 Q1 Q0 D4 D3 D2 Dari penyahkod alamat © 2006-2008 [email protected] OE1 D1 OE2 D0 1kž 1kž 1kž 1kž 11-23 68000 Microprocessor Switch Debouncing When mechanical switches are opened or closed there are brief oscillations due to mechanical bouncing (switch bounce). VDD Set Q R Q Reset key bounce, tBOUNCE Set Reset R (a) Set-reset latch VDD 4050 3 basic hardware debouncing methods SR latches Non-inverting CMOS gates Integrating debouncer R 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. © 2006-2008 [email protected] Vout (b) CMOS gate debouncer VDD R Vout C H Threshold level L Switch closed (c) Integrating RC circuit debouncer Figure 7.42 Hardware debouncing techniques 11-24 68000 Microprocessor One Hardware Debounce Method © 2006-2008 [email protected] 68000 Microprocessor BCD-to-7-Segment Decoder/Driver (a) BCD-to-7segment decoder/driv er driving a commonanode 7segment LED display; (b) segment patterns for all possible input codes. © 2006-2008 [email protected] 11-26 68000 Microprocessor Keypad Decoding: 4x4 or 4x3 keypad CPU checks these lines CPU sends low signal to these lines © 2006-2008 [email protected] 11-27 68000 Microprocessor Decoding the Keyboard Matrix Example: press 5 and E 0 1 2 3 Row 0 4 5 6 7 Row 1 8 9 A B Row 2 C D E F Row 3 Pressing 5 Row 1 Col 1 01 01 Pressing E (=14) Col 0 Col 2 Col 1 Col 3 Row 3 Col 2 11 © 2006-2008 [email protected] 10 11-28 68000 Microprocessor 74C922 Keypad Encoder Performs the decoding and debouncing in hardware Connect to column pins Connect to row pins Connect to oscillator Low to enable output 1 2 3 4 11 10 8 7 5 6 13 Y1 Y2 Y3 Y4 X1 X2 X3 X4 DOA DOB DOC DOD OSC KBM OE DA 74C922 © 2006-2008 [email protected] 17 16 15 14 12 Row & col position DA means Data Available High when a key is pressed 11-29 68000 Microprocessor 74C922 Keypad Encoder 74LS244 74C922 1 2 3 4 11 10 8 7 L C1 0.068µF Y1 Y2 Y3 Y4 X1 X2 X3 X4 5 6 DOA DOB DOC DOD 17 16 15 14 OSC KBM 13 DA OE C1 0.68µF 12 D0 D1 D2 D3 D4 D5 D6 D7 To 68000 Data Bus H U9C 6 5 74LS14 Wait until DA pin high before accepting the 4-bit data © 2006-2008 [email protected] 11-30 68000 Microprocessor Interfacing Other Devices with Latches Buzzers: 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. Most latches do not have the current capacity to drive a buzzer directly so a transistor is added. Diode protects coil transient voltages. +5V +5V Relay 2N3904 + D1 N.S. Piezo Buzzer D1 - To Indicating Light N.O. 12 VDC From latch 2N3904 NPN 2.2KΩ C Q1 B C From latch Q1 B E © 2006-2008 [email protected] 2N3904 NPN 2.2KΩ DC Motor E 11-31 68000 Microprocessor Example: System Having Only Elementary I/O © 2006-2008 [email protected] 11-32 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 68000 Microprocessor Multiplexing © 2006-2008 [email protected]