Microprocessors

advertisement
Microprocessors
Input/Output Interface
(Chapter 10)
ACOE255
1
Introduction
• In a typical computer system, the user communicates with the computer via
standard peripheral devices such as the keyboard, mouse, display, printer e.t.c.
• Furthermore computers and microprocessor based systems are used in
instrumentation or automatic control applications. In such cases it is necessary
that the microprocessor reads the state of input devices (switches, sensors) and
activate some output devices (motors, heaters, lights).
• The I/O interface is required to enable the interface between the microprocessor
and the peripheral devices.
• The peripheral devices are connected on a microprocessor system through the
Input/Output ports.
• The I/O interface provides the following:
– Isolation between the buses and the peripheral devices.
– Address decoding.
– Synchronization/Latching.
ACOE255
2
Isolated vs Memory-mapped I/O
• Isolated I/O
– I/O locations are separate from memory locations
– Special I/O instructions are used
– The most common technique for Intel microprocessors
– Advantage: More space for memory
– Disadvantage: Additional control signals (IO/M) and instructions increase complexity
• Memory-mapped I/O
– I/O devices are treated as memory locations in the memory map
– Any memory transfer instruction can be used (MOV, LDR, STR etc)
– Advantages: Simpler decoding circuitry, no special instructions required
– Disadvantage: A portion of the memory system is used as the I/O map, reducing the
memory available to applications
ACOE255
3
Input/Output Instructions
• The 8088 and 80X86 processors use the 16 lower address lines (A0 to A15) to
address I/O devices. This limits the maximum number of I/O ports to 64K.
• The IN instruction copies the content of an input port to register AL, AX or EAX.
• The OUT instruction copies the content of register AL, AX, or EAX to an output
port.
• Register AL is used for 8-bit ports, AX for 16-bit ports and EAX for 32-bit ports.
• The 8088 and 80X86 processors support two I/O addressing modes.
– Fixed Address. The address is directly specified in the instruction as an 8-bit number.
That is loaded on the address lines A0 to A7. Address lines A8 to A15 are set to 00.
• IN AL,30H
;Read input port 0030H into register AL
• OUT 30H,AL
;Copy register AL to output port 0030H.
– Variable Address. The address is specified through register DX as a 16-bit address.
• MOV DX,3A0H
;Set I/O address
• IN AL,DX
;Read input port [DX] or 3A0H into register AL.
• OUT DX,AL
;Copy register AL to output port [DX] or 3A0H
ACOE255
4
High Level Language Input/Output Instructions (Pascal)
• Input/Output using Pascal: I/O is obtained using the ‘Port[ ]’ instruction.
– X := Port[PortAddress]; /* Copy the contents of the specified port into X */
– Port[PortAddress] := X; /* Copy the contents of X into the specified port */
• Input/Output using Delphi: Delphi does not allow direct access to I/O ports.
This can be done by inserting assembly language code into Delphi as follows:
asm
; code equivalent to ‘value:=port[portaddress];
begin
mov dx,portaddress
;specify the port address
in al,dx
;input from the port specified by “dx” into “al”
mov value,al
;copy input data into variable ‘value’
end;
asm
; code equivalent to ‘port[portaddress] := value;
begin
mov dx,portaddress
;specify the port address
mov al,value
;move output data into register “al”
out dx,al
;output data to the port specified by “dx”
end;
ACOE255
5
High Level Language Input/Output Instructions (C/C++)
• C/C++ does not allow direct access to I/O ports. This can be done by inserting
assembly language code into the C/C++ code as follows:
__asm
; code equivalent to ‘value:=port[portaddress];
{
mov dx,portaddress
;specify the port address
in al,dx
;input from the port specified by “dx” into “al”
mov value,al
}
;copy input data into variable ‘value’
__asm
; code equivalent to ‘port[portaddress] := value;
{
mov dx,portaddress
;specify the port address
mov al,value
;move output data into register “al”
out dx,al
;output data to the port specified by “dx”
}
ACOE255
6
Input/Output Using DLLs (C/C++)
• For protection purposes, modern operating systems such as the Windows XP do
not allow the use of the IN and the OUT instructions in the users programs.
• A way to have access to I/O ports is through libraries (DLL files) developed for
this purpose. Such a library is the inout32.dll
• To use this library in Visual Studio (C++) we must:
– Add the inout32.lib file in the Linker properties
• Project ->Properties->Linker->Input->Additional Dependencies
– Define the two functions for input and output and use them accordingly
short _stdcall Inp32(short PortAddress);
void _stdcall Out32(short PortAddress, short data);
main()
{
short Inval = Inp32(889);
/* input from port 889 into variable “Inval”*/
Out32(888,0x2f);
/* Output the hex value 2f to port 888 */
}
ACOE255
7
Simple Input Port
• An input port can be implemented
using a simple octal buffer such as
the 74LS244.
• The address decoding circuit is
enabled only if the IO/M signal is
set High by the 8088 (Low for the
x86 processors) and the RD signal
is Low.
D7
LS244
A11
A10
G2
G1
A9
A0
A8
A7
A6
Switch Open => Logic 1
Switch Closed => Logic 0
A5
A19
A4
WR
RD
IO/M'
A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0
0
ACOE255
D0
8088 System
• The address decoding circuit
enables the three-state buffers of
the 74LS244 whenever the port
address is selected by the
processor. In such a case the state
of the input devices appears on the
data bus.
+5V
1
0
0
0
1
1
0
X
X
X
X
Address
460H to 46FH
8
Simple Output Port (Using the 74LS373)
• An output port can be implemented
using a simple octal latch such as
the 74LS373.
• The address decoding circuit is
enabled only if the IO/M signal is
set High by the 8088 (Low for the
x86 processors) and the WR signal
is Low.
D
Q
EN
D0
A11
A10
EN
OE
A9
A0
A8
A7
A6
A5
A19
Logic 1 => LED is OFF
Logic 0 => LED is ON
A4
RD
WR
IO/M'
A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0
0
ACOE255
LS373
D7
8088 System
• The address decoding circuit
enables the D-latches of the
74LS373 whenever the port
address is selected by the
processor. In such a case the state
of the data bus is latched to the
output devices.
+5V
1
0
0
0
1
1
0
X
X
X
X
Address
460H to 46FH
9
Simple Output Port (Using the 74HCT573)
• The 74HCT573 is pin compatible
with the 74LS373. There are three
significant differences:
– The HCT573 has a 20mA current sink and
a 20mA current source, thus it can drive a
LED connected either to the ground or to
+5V. The LS373 has a 16mA current sink
and a 400uA current source, thus it can
only drive a LED connected to +5V.
– The HCT family is faster than the LS
family.
+5V
D
Q
EN
D0
A11
A10
EN
OE
A9
A0
A8
A7
A6
A5
A19
Logic 1 => LED is ON
Logic 0 => LED is OFF
A4
RD
WR
IO/M'
A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0
1
ACOE255
HCT573
D7
8088 System
– The ‘573 has all inputs on the left side and
all outputs on the right side of the IC,
while the ‘373 has the even numbered
inputs on the left side and the odd
numbered inputs on the right side. Thus
the ‘573 is easier to by handled on PCB
boards.
Logic 1 => LED is OFF
Logic 0 => LED is ON
0
0
0
0
1
0
1
X
X
X
X
Address
850H to 85FH
10
Simple I/O Example 1 (Hardware)
• Draw a circuit to show how 8 switches can be connected on the input port 3AH
and 8 LEDs on the output port 5CH.
ACOE255
11
Simple I/O Example 1 (Software)
Write a program to keep reading the state of the switches and switch ON the LED
at the position form by the switches at D2, D1 and D0 (i.e. 3X8 decoder).
Pseudo Code:
Repeat
Read Input port in InVal
Mask out D2,D1,D0 from InVal
if InVal = 0 then OutVal = 1
if if InVal = 1 then OutVal = 2
if InVal = 2 then OutVal = 4
if InVal = 3 then OutVal = 8
if InVal = 4 then OutVal = 16
if if InVal = 5 then OutVal = 32
if InVal = 6 then OutVal = 64
if InVal = 7 then OutVal = 128
Write OutVal to Output port
Until keypressed
ACOE255
C/C++ Code
main()
{
short InVal, OutVal = 0;
do { InVal = Inp32(0x3a);
InVal = InVal & 0x7;
if (InVal == 0) OutVal = 0x1;
if (InVal == 1) OutVal = 0x2;
if (InVal == 2) OutVal = 0x4;
if (InVal == 3) OutVal = 0x8;
if (InVal == 4) OutVal = 0x10;
if (InVal == 5) OutVal = 0x20;
if (InVal == 6) OutVal = 0x40;
if (InVal == 7) OutVal = 0x80;
Out32(0x5c,OutVal);
} while (!_kbhit());
}
12
Mask Operations
(a) Write a program to keep reading the
.
ACOE255
(b) Write a program to keep reading the
state of the switches and switch ON
the LEDs for which the corresponding
switch is closed.
13
Simple I/O Example 2
Four float switches and four LEDs are used to indicate the level of a liquid in the tank
shown below. The switches and the LEDs are connected on a computer through an
interface board with an input and an output port occupying the address 460H to 46FH.
• Draw the circuit diagram of the interface board.
• Write a program to keep reading the state of the float switches and display the liquid
level on the LEDs. If an error is detected then switch ON all LEDs.
DI3 DI2 DI1 DI0 DO4 DO3 DO2 DO1 DO0 State
Closed
DI3
Closed
DI2
Interface Board
DI1
DI0
Open
Full
DO4
DO3
DO2
DO1
DO0
ACOE255
Open
High
Half
Low
Empty
0
0
0
0
0
0
0
0
1
Empty
0
0
0
1
0
0
0
1
0
Low
0
0
1
0
1
1
1
1
1
Error
0
0
1
1
0
0
1
0
0
Half
0
1
0
0
1
1
1
1
1
Error
0
1
0
1
1
1
1
1
1
Error
0
1
1
0
1
1
1
1
1
Error
0
1
1
1
0
1
0
0
0
High
1
0
0
0
1
1
1
1
1
Error
1
0
0
1
1
1
1
1
1
Error
1
0
1
0
1
1
1
1
1
Error
1
0
1
1
1
1
1
1
1
Error
1
1
0
0
1
1
1
1
1
Error
1
1
0
1
1
1
1
1
1
Error
1
1
1
0
1
1
1
1
1
Error
1
1
1
1
1
0
0
0
0
Full
14
Simple I/O Example 2 (Circuit Diagram)
A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0
0
1
0
0
0
1
1
0
X
X
X
X
Address
460H to 46FH
+5V
D7
DI0
DI1
DI2
DI3
LS244
D0
DO0
DO1
DO2
DO3
DO4
HCT573
D
Q
EN
8088 System
A11
A10
A0
G1
G2
EN
OE
A9
A8
A7
A6
A19
A5
A4
IO/M'
RD
WR
ACOE255
15
Simple I/O Example 2 (Software using Case/Switch Statement)
Pseudo Code:
C/C++ Code
Set OutVal to 0, i.e switch off all leds
main()
{
short InVal, OutVal = 0;
Repeat
do {
Read Input port in InVal
InVal = Inp32(0x460);
Mask out D3,D2,D1,D0 from InVal
InVal = InVal & 0xf;
Case of InVal
switch (InVal) {
0: OutMask = 1
case 0: OutMask = 1; break;
1: OutMask = 2
case 1: OutMask = 2; break;
3: OutMask = 4
case 3: OutMask = 4; break;
7: OutMask = 8
case 7: OutMask = 8; break;
FH: OutMask = 10H
case 0xf: OutMask = 0x10; break;
else OutMask = 1FH
default OutMask = 0x1f; }
Mask in D4 to D0 of OutMask in OutVal
Write OutVal to Output port
Until keypressed
ACOE255
OutVal = (OutVal & 0xe0) | OutMask;
Out32(0x460,OutVal);
} while (!_kbhit());
}
16
Simple I/O Example 2 (Software using array as a lookup table)
C/C++ Code
Pseudo Code:
Table[0] = 00001 /*
Table[1] = 00010 /*
Table[3] = 00100 /*
Table[7] = 01000 /*
main()
{
short InVal, OutVal = 0;
short Table[16] = 0x1, 0x2, 0x1f, 0x4,
0x1f, 0x1f, 0x1f, 0x8,
Table[15] = 10000 /*
0x1f, 0x1f, 0x1f, 0x1f,
Table[rest] = 111111 /*
0x1f, 0x1f, 0x1f, 0x10;
Repeat
Read Input port in InVal
Mask out D2,D1,D0 from InVal
Mask in D2,D1,D0 of Table[InVal] to OutVal
Write OutVal to Output port
Until keypressed
ACOE255
do {
InVal = Inp32(0x460);
InVal = InVal & 0xf;
OutMask = Table[InVal];
OutVal = (OutVal & 0xe0) | OutMask;
Out32(0x460,OutVal);
} while (!_kbhit());
}
17
DC Motor Speed and Direction Control
• The speed of a DC motor is proportional to the DC voltage applied at its
terminal.
– Thus the speed can be controlled by controlling the DC voltage.
• The DC voltage can be controlled by:
– Inserting a resistor in series with the DC motor.
• Unnecessary dissipation of energy on the resistor.
– Using Pulse Width Modulation (PWM)
Average Voltage
• The direction of rotation a DC motor is reversed by reversing the polarity of the
DC voltage applied at its terminal.
– This can be obtained using a relay (change-over connection).
– Connecting a relay on an output port requires the use of high current drivers such as
the ULN2803 and diodes to protect the output transistors due to Lenz’s law.
• Special drivers (H-drivers) can also be used to provide both speed control and
direction control.
ACOE255
18
DC motor interface example
A DC motor is connected to a computer as shown below. The switches and the
motor are connected on an input and an output port occupying the address
460H to 46FH.
• Draw a circuit of the interface and the connections to the motor
• Write a program to keep reading the state of the switches and control the
operation of the motor accordingly.
Start/Stop
Fast/Slow
Fwrd/Rev.
1
1
1
0
0
0
DC Motor
Interface Board
ACOE255
19
DC motor interface example(Circuit Diagram)
A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0
0
1
0
0
0
1
1
0
X
X
X
X
Address
460H to 46FH
+5V
D7
DI7
DI6
DI5
LS244
DI4
8088 System
D0
A0
DI3
A11
DI2
DI1
A10
DI0
DO0
Frwd/Rev.
DO1
On/Off
DO2
Fast/Slow
HCT573
ULN2803
+5V
Com
D
RL
1
Q
EN
+5V
G1
G2
EN
OE
RL
2
A9
A8
A7
A6
A19
+5V
RL
2
A5
A4
IO/M'
M
RD
WR
ACOE255
20
DC motor interface example (Software using conditional execution)
Pseudo Code:
Set OutVal to 0, i.e motor is OFF
Repeat
Read Input port in InVal
If On/Off bit = 1
then OutVal(D0) = 1
else OutVal(D0) = 0
If Fast/Slow bit = 1 then OutVal(D1) = 1
else OutVal(D1) = 0
If Frwd/Rev bit = 1 then OutVal(D2) = 1
else OutVal(D2) = 0
Write OutVal to Output port
Until keypressed
ACOE255
21
DC motor interface example (Software using a lookup table)
Pseudo Code:
Table[0]
Table[1]
Table[2]
Table[3]
Table[4]
Table[5]
Table[6]
Table[7]
= 000
= 000
= 010
= 011
= 000
= 000
= 110
= 111
/* 000 ->motor is Off
/* 001 ->motor is Off
/* 010 -> On-Slow-Rev
/* 011 -> On-Slow-Frwd
/* 100 -> motor is Off
/* 101 -> motor is Off
/* 110 ->On-Fast-Rev
/* 111 ->On-Fast-Frwd
Repeat
Read Input port in InVal
Mask out D2,D1,D0 from InVal
Mask in D2,D1,D0 of Table[InVal] to OutVal
Write OutVal to Output port
Until keypressed
ACOE255
22
7-Segment Displays
• Used to display the digits from 0 to 9, as well as many letters (A,b,C,d,E,F,L,H)
• Consists of seven leds connected to a common point
• Can be common-anode or common-cathode
a
a
b
c
d
e
f
g
c
a
d
g
f
d
e
a
b
DO2
HCT573
b
D
c
Q
DO3
DO4
d
f
DO6
g
EN
ACOE255
c
OE
DO2
DO4
f
d
e
f
g
Through a BCD/7 segment decoder
HCT573
D
A
B
Q
D
/BL
DO6
/LT
EN
EN
/LE
EN
OE
a
b
c
D Q
DO5
DO7
CD4511
C
DO3
g
e
EN
DO5
DO7
b
a
OR
DO0
DO1
a
e
b
c
a
d
g
e
Buffer
DO0
DO1
d
Common Anode
Common Cathode
Can be connected directly on an O/P port
c
BCD-7seg decoder
f
0: ON
1: OFF
0: OFF
1: ON
e
g
+Vcc
b
Latch
c
b
OE
f
g
f
d
e
23
7-segment Displays – Example1
• Draw a circuit to show how a common cathode 7-segment display can be
connected on an o/p port and four switches on an i/p port both occupying the
address range 860h to 86Fh.
• Write a program to read the state of the switches and display the binary number
formed by the switches as a hexadecimal digit.
D7 D6 D5 D4 D3 D2 D1 D0
- g f e d c b a
+5V
D7
DI0
DI1
DI2
DI3
LS244
D0
8088 System
A11
A10
A0
A9
A8
A7
A6
A19
A5
A4
IO/M'
RD
WR
ACOE255
G1
G2
DO0
DO1
DO2
DO3
DO4
DO5
DO6
DO7
HCT573
a
b
D
c
Q
b
g
d
e
EN
f
g
EN
c
a
OE
f
d
e
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
0
0
1
1
1
1
1
0
1
1
1
1
0
1
1
1
1
0
1
0
0
0
1
0
1
0
1
1
1
1
1
1
1
0
1
1
0
1
1
0
1
0
0
1
1
1
1
0
1
1
0
1
1
1
1
1
1
1
1
1
0
1
0
0
1
1
1
1
1
0
0
1
1
1
1
0
0
1
0
0
1
0
1
1
0
1
1
1
1
1
1
0
1
0
1
1
1
0
0
0
1
1
1
0
1
1
1
1
1
0
1
1
3F
0C
76
5E
4D
5B
7B
0E
7F
4F
6F
79
33
7C
73
63
24
7-segment Displays – Example1: Program
ACOE255
25
7-Segment Displays: Example 2
Interface Board
Four float switches and a 7-segment display are used to indicate the level of a liquid in the
tank shown below. The switches and the display are connected on a computer through an
interface board with an input and an output port occupying the address 460H to 46FH.
Draw the circuit diagram of the interface board.
Write a program to keep reading the state of the float switches and display the liquid level
on the display using the digits F(Full), H(High), A (Half), L(Low) and E(Empty). If an error
is detected then switch ON the decimal point.
DI3 DI2 DI1 DI0 State Digit
Code
ACOE255
0
0
0
0
Empty E
0
0
0
1
Low
L
0
0
1
0
Error
.
0
0
1
1
Half
A
0
1
0
0
Error
0
1
0
1
Error
0
1
1
0
Error
.
.
.
0
1
1
1
High
H
1
0
0
0
Error
1
0
0
1
Error
DI2
1
0
1
0
Error
DI1
1
0
1
1
Error
DI0
1
1
0
0
Error
1
1
0
1
Error
.
.
.
.
.
.
1
1
1
0
Error
.
1
1
1
1
Full
F
DO7
a
DO6
b
DO5
c
DO4
d
DO3
e
DO2
f
DO1
g
DO0
dp
DI3
Closed
b
c
a
g
f
Closed
d
e
Open
Open
26
7-segment Displays – Example1: Program
ACOE255
27
7-segment Displays – Example3
• Draw a circuit to show how a common cathode 7-segment display can be
connected on an o/p port and four switches on an i/p port both occupying the
address range 860h to 86Fh.
• Write a program to read the state of the switches and display the binary number
formed by the switches as a hexadecimal digit.
D7 D6 D5 D4 D3 D2 D1 D0
- g f e d c b a
+5V
D7
DI0
DI1
DI2
DI3
LS244
D0
8088 System
A11
A10
A0
A9
A8
A7
A6
A19
A5
A4
IO/M'
RD
WR
ACOE255
G1
G2
DO0
DO1
DO2
DO3
DO4
DO5
DO6
DO7
HCT573
a
b
D
c
Q
b
g
d
e
EN
f
g
EN
c
a
OE
f
d
e
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
0
0
1
1
1
1
1
0
1
1
1
1
0
1
1
1
1
0
1
0
0
0
1
0
1
0
1
1
1
1
1
1
1
0
1
1
0
1
1
0
1
0
0
1
1
1
1
0
1
1
0
1
1
1
1
1
1
1
1
1
0
1
0
0
1
1
1
1
1
0
0
1
1
1
1
0
0
1
0
0
1
0
1
1
0
1
1
1
1
1
1
0
1
0
1
1
1
0
0
0
1
1
1
0
1
1
1
1
1
0
1
1
3F
0C
76
5E
4D
5B
7B
0E
7F
4F
6F
79
33
7C
73
63
28
7-segment Displays – Example1: Program
ACOE255
29
7-segment Displays – Example1
• Draw a circuit to show how common cathode 7-segment display can be
connected on an o/p port and four switches on an i/p port both occupying the
address range 860h to 86Fh.
• Write a program to read the state of the switches and display the binary number
formed by the switches as a hexadecimal digit.
D7 D6 D5 D4 D3 D2 D1 D0
- g f e d c b a
+5V
D7
DI0
DI1
DI2
DI3
LS244
D0
8088 System
A11
A10
A0
A9
A8
A7
A6
A19
A5
A4
IO/M'
RD
WR
ACOE255
G1
G2
DO0
DO1
DO2
DO3
DO4
DO5
DO6
DO7
HCT573
a
b
D
c
Q
b
g
d
e
EN
f
g
EN
c
a
OE
f
d
e
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
0
0
1
1
1
1
1
0
1
1
1
1
0
1
1
1
1
0
1
0
0
0
1
0
1
0
1
1
1
1
1
1
1
0
1
1
0
1
1
0
1
0
0
1
1
1
1
0
1
1
0
1
1
1
1
1
1
1
1
1
0
1
0
0
1
1
1
1
1
0
0
1
1
1
1
0
0
1
0
0
1
0
1
1
0
1
1
1
1
1
1
0
1
0
1
1
1
0
0
0
1
1
1
0
1
1
1
1
1
0
1
1
3F
0C
76
5E
4D
5B
7B
0E
7F
4F
6F
79
33
7C
73
63
30
Homework- Question 1
a) Draw a circuit diagram to show how four switches and two 7-segment displays
can be interfaced to an 8088 based system occupying the address 10H to
1FH, 20H to 2FH and 30H to 3FH respectively.
b) Write a program to read the binary number formed by the four switches and
display the equivalent decimal number on the 7-segment displays. For
example if the switches form the number 0110, the displays should display the
number 06, and if the switches form the number 1110, then the displays should
display the number 14.
ACOE255
31
Homework- Question 2
a) Draw a circuit diagram to show how four switches and a 7-segment display can
be interfaced to an 8088 based system occupying the address A0H to AFH,
F0H to FFH respectively.
b) Write a program to read the state of the switches and display on the 7-segment
display the letter:
•
•
•
H, if there are more switches closed than open,
L, if there are less switches closed than open,
E, if the number of switches closed is equal to the number of switches open.
ACOE255
32
Homework- Question 3
a) Draw a circuit diagram to show how six switches and eight Leds can be
interfaced to an 8088 based system occupying the address 30H to 3FH, 20H to
2FH respectively.
b) Write a program to read the binary number formed by the six switches and
display the equivalent Binary Coded Decimal number on the Leds. For
example if the switches form the number 100101, the displays should display
the number 00110111, since (100101)2 = (00110111)BCD.
ACOE255
33
Homework- Question 4
a) Draw a circuit diagram to show how the following can be interfaced to an 8088
based system:
i.
Four switches connected on an I/P port occupying the address range from 30H to
3FH.
ii. Eight Leds connected on an O/P port occupying the address range from 20H to
2FH.
b) Write a program to read the BCD number formed by the four switches, and
display it on the eight Leds the square of the input number in BCD form. If the
number formed by the switches is an invalid BCD number, then all of the Leds
should be switched ON.
–
–
ACOE255
For example if the switches form the number 00000101 then the Leds should
display 00100101, since (00000101)BCD = (05)10 and 52 = 25 = (00100101)BCD
If the number formed by the switches is 00001100 then the Leds should display
11111111 since 1100 is an invalid BCD number.
34
Homework- Question 5
a) Draw a circuit diagram to show how a common cathode 7-segment display can
be connected on an output port, occupying the address CAH.
b) Write a program to display the digits from 0 to 9 on the 7-segment display with
a 1-second delay between digits.
c) Write a procedure to display on the 7-segment display, the letter E if the
contents of the variable INVAL is equal to 80H, the letter H if INVAL is greater
than 80H, or the letter L if INVAL is less than 80H.
d) Write a program that keeps reading the binary number from the input port
0AAH and displays on the 7-segment display, a letter according to the table
given below.
xxxxx000 xxxxx001 xxxxx010 xxxxx011
E
ACOE255
I
L
U
xxxxx100 xxxxx101 xxxxx110
xxxxx111
Γ
F
H
Ξ
35
Homework- Question 6
a) Draw a circuit diagram to show how the following can be interfaced to an 8088 system
i.
ii.
Three switches connected on an I/P port occupying the address range from 60H to 6FH.
Eight Leds connected on an O/P port occupying the address range from 50H to 5FH.
b) Write a program to
i.
ii.
read the code formed by the three switches in a 1-second time intervals,
convert the input code into a binary value according to the table below and store it in an array
called BINV, and
iii. display it as a bar graph on the eight Leds as shown in figure below
For example if the switches form the number 101 then the number 110 must be stored in the
array BINV and the Leds should display 11111110.
ACOE255
Input
Binary
0 0 0
0 0 0
0 0 1
0 0 1
0 1 1
0 1 0
0 1 0
0 1 1
1 1 0
1 0 0
1 0 0
1 0 1
1 0 1
1 1 0
1 1 1
1 1 1
Bar Graph
36
THE 82C55 PROGRAMMABLE PERIPHERAL INTERFACE (PPI)
•A popular interfacing component, for interfacing TTL-compatible I/O devices to the microprocessor.
•Requires insertion of wait states if used with a microprocessor using higher that an 8 MHz clock.
•PPI has 24 pins for I/O that are programmable in groups of 12 pins and three modes of operation
(Basic I/O, Strobed I/O, Strobed Bi-directional Bus I/O).
•In the PC, an 82C55 or its equivalent is decoded at I/O ports 60H-63H, interfacing keyboard and
Parallel printer port).
ACOE255
VCC: The +5V power supply pin.
GND: GROUND
D0-D7: I/O DATA BUS
RESET: A high on this input clears the control register and all ports
(A, B, C) are set to the input mode with the “Bus Hold” circuitry
turned on.
CS: Chip select is an active low input used to enable the 82C55A onto
the Data Bus for CPU communications.
RD: Read is an active low input control signal used by the CPU to
read status information or data via the data bus.
WR: Write is an active low input control signal used by the CPU to
load control words and data into the 82C55A.
A0-A1: Address input signals, in conjunction with the RD and WR
inputs, control the selection of one of the three ports or the control
word register (00 – Port A, 01 – Port B, 10 – Port C, 11 – CR).
PA0-PA7 (I/O PORT A): 8-bit input and output port.
PB0-PB7 (I/O PORT B): 8-bit input and output port.
PC0-PC7 (I/O PORT C): 8-bit input and output port.
37
INTERFACING 82C55 TO AN 8088 SYSTEM (ports 60H-63H)
D7
DI0
PA7
DI1 D7
DI2
8088 System
D0
A0
A0
A7
A1
D0
A0
A1
82C55
DI3
PA0
PB7
PB0
A6
A5
A4
A19
A3
PC7
CS
RD
WR
PC0
A2
IO/M'
RD
WR
ACOE255
38
EXAMPLE
• Use a 82C55 PPI to interface four switches at address 60H
and a SSD at address 62H
+5V
D7
DI0
PA7
DI1 D7
DI2
DI2
8088 System
A0
A0
A7
A1
D0
A0
A1
82C55
DI3
D0
PA0
A4
A19
A3
A2
DI3
PB7
PB0
A6
A5
DI0
DI1
PC7
CS
RD
WR
PC0
DI0
a
DI1
DI2
b
DI3
d
c
c
g
e
f
g
IO/M'
b
a
f
d
e
RD
WR
ACOE255
39
PROGRAMMING THE 82C55
• Mode 0 operation causes the PPI to function as either buffered input or latched
output
• The 82C55 is programmed through two internal command registers, selected
through bit 7.
• Command byte A
– 0 Port C, PC3-PC0 (1-input, 0-output)
– 1 Port B (1-input, 0-output)
– 2 Mode (00-mode 0, 01-mode1)
– 3 Port C, PC7-PC4 (1-input, 0-output)
– 4 Port A (1-input, 0-output)
– 5-6 Mode (00-mode 0, 01-mode 2, 1X-mode 2)
– 7 Command byte select (always 1 for Command byte A)
• Command byte B
– Used in mode 1 and mode 2
ACOE255
40
Example
• Rewrite the program of the example of slide 30, this time using the PPI and
setting up the ports as shown in the previous slide
ACOE255
41
Homework
• All examples of slides 31-36 can be modified to include PPI interfacing
ACOE255
42
Download