CH6-Parallel IO Port
CH6-Parallel IO Port
Introduction
A parallel I/O port is used for interfacing with external peripherals Writes (output) data and reads (input) data I/O devices
LEDs Seven-segment display Switches
Introduction
An I/O port consists of a set of I/O pins and the registers required to control its operation An I/O pin can be configured for input or output An I/O pin usually serves multiple functions When it is not used as a peripheral function, it can be used as a general-purpose I/O pin.
Port A Port B
Table 4.5 Num ber of pins available in each paralle port Port Nam e A B E H J K M P S T PAD1, PAD0 L U V W No. of Pins 8 8 8 8 4 7 8 8 8 8 16 8 8 8 8 Pin Nam e PA7~PA0 PB7~PB0 PE7~PE0 PH7~PH0 PJ7~PJ0 PK4~PK0 PM 7~PM0 PP7~PP0 PS3~PS0 PT7~PT0 PAD15~PAD0 PL7~PL0 PU7~PU0 PV7~PV0 PW 7~PW0
DDR is 8-bit register Setting a bit of the DDR to 1, the corresponding I/O pin is configured as output Setting a bit of the DDR to 0, the corresponding I/O pin is configured as input
DDRA
Port A
DDRA
Port A
DDRA
Port A
Electrical Characteristics
Electrical compatibility issues needs to be considered when interfacing I/O device to the MCU Two major concerns in interfacing IC chips
Voltage-level compatibility Is the high output level of an IC chip high enough to be considered as a high for the input of another IC chip? Is the low output level of an chip low enough to be considered as a low for the input of another IC chip?
Current drive capability Does the output of an IC chip have enough current to drive its load? Can the output circuit of an IC chip sink the currents of its load?
In order for device X to drive device Y correctly, the following condition must be satisfied:
Output high voltage of device X (VOHX) must be higher than input high voltage of device Y (VIHY). VOHX > VIHY Output low voltage of device X (VOLX) must be lower than the input low voltage of device Y (VILY). VOLX < VILY
Table 7.1 Input and output voltage levels of common logic families Logic family
HCS123 S4 LS4 AS4 F4 HC3 HCT3 ACT3 ABT5 BCT5 FCT5
VCC
5V 5V 5V 5V 5V 5V 5V 5V 5V 5V 5V
VIH
3.25 V 2V 2V 2V 2V 3.5 V 3.5 V 2V 2V 2V 2V
VOH
4.2 V 3.0~3.4 V1 3.0~3.4 V1 3.0~3.4 V1 3.4 V 4.9 V 4.9 V 4.9 V 3V 3.3 V 2.4 V
VIL
1.75 V 0.8 V 0.8 V 0.8 V 0.8 V 1.5 V 1.5 V 0.8 V 0.8 V 0.8 V 0.8 V
VOL
0.8 V 0.4~0.5 V2 0.4~0.5 V2 0.35 V 0.3 V 0.1 V 0.1 V 0.1 V 0.55 V 0.42 V 0.55 V
Notes. 1. VOH value will get lower when output current is larger. 2. VOL value will get higher when output current is larger. The VOL values of different logic gates are slightly different. 3. HCS12, HC, HCT, ACT are based on the CMOS technology. 4. S, LS, AS and F logic families are based on the bipolar technology. 5. ABT, BCT, and FCT are using the BiCMOS technology.
Cont.
If a device cannot source or sink enough current, then using buffer device is a common solution The current capabilities of a logic device are determined by the following currents:
Input high current (IIH): The input current (flowing into the input pin) when the input voltage is high. Input low current (IIL): the input current (flowing out of the input pin) when the input voltage is low. Output high current (IOH): The output current (flowing out of the output pin) when the output voltage is high Output low current (IOL): The output current (flowing into the output pin) when the output voltage is low.
Cont.
To determine whether a pin can supply and sink currents to all the peripheral pins that it drives directly, the following requirements need to be checked:
The IOH of an output pin must be equal to or larger than the total current flowing into all the peripheral pins that are connected to directly to the uC I/O pins The IOL of an output pin must be equal to or larger than the total current flowing out from all the peripheral pins that are connected directly to uC I/O pins
Need to make sure that the total current needed to drive the peripheral signals pins does not exceed the total current that the microcontroller can supply. What should be done if an I/O cannot supply or sink the current needed to drive the peripheral pins?
Use buffer chips
VCC
5V 5V 5V 5V 5V 5V 5V 5V 5V 5V 5V
IIH
2.5 A 50 A 20 A 20 A 20 A 1 A 1 A 1 A 1 A 20 A 1 A
IIL
2.5 A 1.0 mA 0.2 mA 0.5 mA 0.5 mA 1 A 1 A 1 A 1 A 1 mA 1 A
IOH
25 mA 1 mA 15 mA 15 mA 1 mA 25 mA 25 mA 24 mA 32 mA 15 mA 15 mA
IOL
25 mA 20 mA 24 mA 64 mA 20 mA 25 mA 25 mA 24 mA 64 MA 64 mA 64 mA
Notes. 1. Values are based on the 74xx244 of Texas Instrument (xx is the technology name) 2. The total HCS12 supply current is 65 mA. 3. The values for IIH and IIL are input leakage currents.
Current required to light an LED is 10 mA Voltage drop across an LED ranging from 1.6V - 2.2 V
VCC
Port pin
R3
Port pin
Figure 4.15 An LED connected to a CMOS inverter through a current -limiting resistor .
Example 4.12
Write a program to drive the LEDs shown in Figure 4.16 so that one LED is lighted at a time from top to bottom and then from bottom to top with each LED lighted for about 200 ms.
H C S1 2 1.5 K PB7 PB6 PB5 PB4 PB3 PB 2 PB 1 PB 0 PJ1 Figure 4 .1 6 C ircuit connection for Exam ple 4 .1 2
#include org lpcnt ds.b org Start movb bset bclr forever movb ldx led_lp movb ldy jsr dec bne bra led_tab dc.b dc.b
"C:\miniide\hcs12.inc" $1000 1 $1500 #$FF,DDRB ; configure port B for output DDRJ,$02 ; configure PJ1 pin for output PTJ,$02 ; enable LEDs to light #16,lpcnt ; initialize LED pattern count #led_tab ; Use X as the pointer to LED pattern table 1,x+,PORTB ; turn on one LED #5 ; wait for half a second delayby100ms ; " lpcnt ; reach the end of the table yet? led_lp forever ; start from beginning $80,$40,$20,$10,$08,$04,$02,$01 $01,$02,$04,$08,$10,$20,$40,$80
; ;
#include "C:\miniide\delay.asm" org $FFFE ; uncomment this line for CodeWarrior dc.w start ; uncomment this line for CodeWarrior end
Seven-Segment Display
A common necessity for many different digital devices is a visual numeric display Individual LEDs can display the binary states of a set of latches or flip-flops However human more used to dealing with decimal numbers clearly represent decimal numbers without translating binary to decimal
Seven-Segment Display
One possibility is to arrange the minimum possible number of LEDs in such a way as to represent only numbers in a simple fashion Seven LEDs (plus an eighth one for the decimal point, if needed) Seven bars are laid out as a squared-off figure "8 and is known as a seven-segment display Use to display decimal digits, small subset of letters
470 each a a b g
74HC244
b f c
d e e c f d g com m on cathode
Table 4.7 Decimal to seven -segment decoder Decimal digit 0 1 2 3 4 5 6 7 8 9 Segments a b c d e f g 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0 1 1 0 1 1 0 1 1 1 0 1 0 0 0 1 0 1 0 1 0 0 0 1 1 1 0 1 1 0 0 1 1 1 1 1 0 1 1 Corresponding Hex Number
Figure 4.17 circuit Dragon12 demo board
$7E $30 $6D $79 $33 $5B $5F $70 $7F $7B
$3F $06 $5B $4F $66 $6D $7D $07 $7F $67
800
#0 a b
800 g
#1 . . . g a b
#5
. . . . . .
a b
. . . 74HC244
PB0 PB1 PB6
. . . g
common cathode common cathode
common cathode
74HC367
A0 A1 A2 A3 A4 A5 Y0 Y1 Y2 Y3 Y4 Y5
. . .
Figure 4.18 Port B and Port P together drive six seven -segment displays (MC9S12DG256)
Example 4.13
Write an instruction sequence to display 7 on the seven-segment display #5
seven
; ; ; ;
configure Port B for configure Port P for enable display #5 to send out the segment
Example 4.14
Write a program to display 123456 on the six seven-segment displays
#include "c:\miniide\hcs12.inc" org $1500 start lds #$1500 movb #$FF,DDRB movb #$3F,DDRP forever ldx #DispTab ; set X to point to the display table loopi movb 1,x+,PTB ; output segment pattern movb 1,x+,PTP ; output display select ldy #1 jsr delayby1ms ; wait for 1 ms cpx #DispTab+12 ; reach the end of the table? bne loopi bra forever #include "c:\miniide\delay.asm" DispTab dc.b $06,$1F dc.b $5B,$2F dc.b $4F,$37 dc.b $66,$3B dc.b $6D,$3D dc.b $7D,$3E ; org $FFFE ; uncomment this line for CodeWarrior ; dc.w start ; uncomment this line for CodeWarrior end
DIP Switch
A set of manual electric switches that are packaged in a group in a standard dual in-line package (DIP) Commonly used to customize the behavior of an electronic device for specific situations store setting/configuration
SW DIP-8
H CS12
Keypad
Keypad is input device that is constructed by arranging an array of switches mechanical, membrane, capacitive or Hall effect Mechanical switches have a problem called contact bounce.
Mechanical switch generates a series of pulses because the switch contacts do not come to rest immediately. A human cannot press and release a key switch in less than 20ms During this interval, microprocessor can scan the same key switch closure tens or even hundreds of thousands of times
Debouncing is needed to solve the disparity in speed between the microprocessor and human key pressing
Re-scan the key switch closure to make sure a key is indeed pressed
Keypad scanning
HCS12 MCU PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0 10 K 3 2 1 0 7 6 5 4 B A 9 8 F E D C
PA7 1 1 1 0
PA6 1 1 0 1
PA5 1 0 1 1
PA4 0 1 1 1 0, 4, 8, C,