ECE 372 Microcontroller Design Parallel IO Ports Outputs

  • Slides: 24
Download presentation
ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n Parallel IO Ports

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n Parallel IO Ports n E. g. Port T, Port AD n Used to interface with many devices n n n n Switches LEDs LCD Keypads Relays Stepper Motors Interface with parallel IO requires us to connect the devices correctly and write code to interface with the devices 1

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n HCS 12 –

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n HCS 12 – Where can we connect external hardware? n n Unused ports (every port has DIO functionality) Expand through the serial interface SPI serial peripheral interface SCI serial communication interface RS 232 2

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n HCS 12 –

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n HCS 12 – Where can we connect external hardware? n n n n Port Port B and A are not connected except PB 4 and PA 0 S 0, 1 is Rx. D and Tx. D for SCI M 2, 3, 4, 5 are used for SPI M 0, 1 are used for CAN P is cross connected with Port T except PP 5 T 0. . 7 can be sued for timer I/O and PWM A/D 0. . . 7 is used for A/D input 3

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n Directly Controlling LEDs

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n Directly Controlling LEDs n HCS 12 can directly control LED from output ports n Why would we NOT want to do this? 5 V 5 V Microcontroller 4

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n Simple LED n

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n Simple LED n Output Port is High - LED is On n Output Port is Low – LED is Off n n n 7405 inverter output will be low Current flows through 7405 to ground 7405 inverter output will be high impedance No current flows through 7405 Resistor used to control brightness: LED is about 2 V, 10 -20 m. A 5

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n LED – Open

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n LED – Open Collector n n n NPN transistor is On if Vb is High LED will be On is Vb is High Can support up to 250 m. A Microcontroller C NPN 6

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n LED – Open

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n LED – Open Emitter n n n PNP transistor is On if Vb is Low LED will be On is Vb is Low Can support up to 250 m. A E Microcontroller PNP 7

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n Directly Controlling LEDs

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n Directly Controlling LEDs n We can use external IC to drive the LEDs n n Reduce current driven by microcontroller and protects it 74 LS 244 IC Tri-state Buffer/Line Driver/Line Receiver n n Used to provide power for LEDs Has OE signals that can be used to disable the output Microcontroller OE 1 OE 2 A 8 A 7 A 6 A 5 A 4 A 3 A 2 A 1 74 LS 244 8

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n Directly Controlling LEDs

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n Directly Controlling LEDs n n Limitation - Can only drive as many LEDs as available pins Solutions: n n n Latching Scanning Multiplexing Microcontroller OE 1 OE 2 A 8 A 7 A 6 A 5 A 4 A 3 A 2 A 1 74 LS 244 9

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n LEDs - Latching

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n LEDs - Latching n n Control LED by using a latch hardware Use additional hardware to control when to latch values n Similar to memory mapped IO Microcontroller LED Address LED Data OE LE A 8 A 7 A 6 A 5 A 4 A 3 A 2 A 1 Latch A 8 A 7 A 6 A 5 A 4 A 3 A 2 A 1 Address=0 Address=1 10

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n LEDs - Latching

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n LEDs - Latching n n Control LED by using a latch hardware Use additional hardware to control when to latch values n Similar to memory mapped IO Addr Always writing last LED value! Any problems? ? Microcontroller OE LE A 8 A 7 A 6 A 5 A 4 A 3 A 2 A 1 Latch A 8 A 7 A 6 A 5 A 4 A 3 A 2 A 1 Address=0 Address=1 11

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n LEDs - Latching

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n LEDs - Latching n Add enable signal from microcontroller Microcontroller En Addr What did we build? Is there another way to implement the address decoding? OE LE A 8 A 7 A 6 A 5 A 4 A 3 A 2 A 1 Latch A 8 A 7 A 6 A 5 A 4 A 3 A 2 A 1 Address=0 Address=1 12

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n LEDs - Latching

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n LEDs - Latching n n Use decoder for addressing LED banks Decoder - Converts input binary number to single high output n 2 -input decoder: four possible input binary numbers n n Thus, four outputs, one for each possible input binary number Enable signal n n Outputs all 0 if e=0 Regular behavior if e=1 d 0 i 0 d 1 i 1 d 2 i 1’i 0’ d 0 i 1’i 0 d 1 i 1 i 0’ d 2 i 1 i 0 d 3 e d 3 i 1 i 0 13

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n LEDs - Latching

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n LEDs - Latching n Use decoder for addressing LED banks en Microcontroller En Addr d 0 d 1 i 0 1 x 2 Decoder OE LE A 8 A 7 A 6 A 5 A 4 A 3 A 2 A 1 Latch A 8 A 7 A 6 A 5 A 4 A 3 A 2 A 1 Address=0 Address=1 14

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n LEDs - Scanning

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n LEDs - Scanning n n Use software executing on the microcontroller to control LEDs row by row, col by col, or bank by bank (depending on organization) Operation n Continually scan LEDs fast enough that human eye cannot detect it n n Similar to refresh rate of TVs and Monitors Enable one column of LEDs by writing 0 to output port controlling desired column Write LEDs value for select row Cannot access all LEDs simultaneously Microcontroller Row Data Column Select 15

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs LEDs - Multiplexed n

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs LEDs - Multiplexed n Use software executing on the microcontroller to control LEDs one at a time Operation n Continually scan LEDs fast enough that human eye cannot detect it n n Similar to refresh rate of TVs and Monitors Enable LED column by outputting column address to column decoder Enable individual LEDs by outputting row address to row decoder Cannot access all LEDs simultaneously Microcontroller 4 x 16 dec n 16

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n How many LEDs

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n How many LEDs can I control using only eight output pins using the following schemes? n Latched: n Scanned n Multiplexed: 17

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n How many LEDs

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n How many LEDs can I control using only eight output pins using the following schemes? n Latched: n n Scanned n n 64 LEDs – Individual latch used for each LED 1 Enable Output, 6 Address Lines, and 1 Data Line Six address lines allow for access to 26 latches (or LEDs) 16 LEDs – 4 columns by 4 rows Multiplexed: n n 256 LEDs – 16 columns by 16 rows Enabled by using 4 x 16 decoder to select both row and columns 18

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n Mill Game n

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n Mill Game n How many pins do we need to connect the 48 LEDs in the following diagram? 19

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n Mill Game 20

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n Mill Game 20

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n 7 -Segment LEDs

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n 7 -Segment LEDs Common Cathode Microcontroller 21

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n 7 -Segment LED

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n 7 -Segment LED – Design Example n n n Control three 7 -segment LED displays Scanning through the entire display must happen faster than the human eye can detect (> 40 Hz) The LED must look like it is continuously on at 10 m. A n Average current = 10 m. A 22

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n 7 -Segment LED

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n 7 -Segment LED – Design Example n Use scanning to control 7 -segment LEDs 7447 – BCD to 7 -Segment Display Microcontroller 23

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n 7 -Segment LED

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs n 7 -Segment LED – Design Example n Use scanning to control 7 -segment LEDs Current (m. A) 10 m. A DC 30 Time (ms) 15 30 1/15 ms > 66 Hz 24