Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Input/Output Interface
(Chapter 10)
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.
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
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
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;
{
mov dx,portaddress
in al,dx
mov value,al
}
__asm
{
mov dx,portaddress
mov al,value
D7
LS244
D0
8088 System
+5V
A11
A10
G2
G1
A9
A0
A8
A7
A6
A5
A19
A4
WR
RD
IO/M'
A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0
0
Address
460H to 46FH
LS373
D7
EN
D0
8088 System
+5V
A11
A10
EN
OE
A9
A0
A8
A7
A6
A5
A19
A4
RD
WR
IO/M'
A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0
0
Address
460H to 46FH
+5V
HCT573
D7
EN
D0
8088 System
A11
A10
EN
OE
A9
A0
A8
A7
A6
A5
A19
A4
RD
WR
IO/M'
A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0
1
Address
850H to 85FH
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
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());
}
Mask Operations
(a) Write a program to keep reading the
.
DI2
Interface Board
DI1
Open
DI0
Open
Full
DO4
DO3
DO2
DO1
DO0
High
Half
Low
Empty
Empty
Low
Error
Half
Error
Error
Error
High
Error
Error
Error
Error
Error
Error
Error
Full
Address
460H to 46FH
+5V
D7
DI0
DI1
DI2
DI3
LS244
D0
DO0
DO1
DO2
DO3
DO4
HCT573
D
EN
8088 System
A11
A10
A0
A9
A8
A7
A6
A19
A5
A4
IO/M'
RD
WR
G1
G2
EN
OE
C/C++ Code
main()
{
Repeat
do {
InVal = Inp32(0x460);
Case of InVal
switch (InVal) {
0: OutMask = 1
1: OutMask = 2
3: OutMask = 4
7: OutMask = 8
Pseudo Code:
Table[0] = 00001 /*
Table[1] = 00010 /*
main()
{
Table[3] = 00100 /*
Table[7] = 01000 /*
Table[15] = 10000 /*
Table[rest] = 111111 /*
Repeat
do {
InVal = Inp32(0x460);
OutMask = Table[InVal];
Until keypressed
Out32(0x460,OutVal);
} while (!_kbhit());
}
Special drivers (H-drivers) can also be used to provide both speed control and
direction control.
Start/Stop
Fast/Slow
Fwrd/Rev.
DC Motor
Interface Board
Address
460H to 46FH
+5V
D7
DI7
DI6
LS244
DI5
DI4
D0
DI3
8088 System
A11
A10
A0
HCT573
G2
EN
RL
1
EN
G1
+5V
Com
D
+5V
DI2
DI1
DI0
ULN2803
OE
RL
2
A9
A8
A7
A6
A19
DO0
Frwd/Rev.
DO1
On/Off
DO2
Fast/Slow
+5V
RL
2
A5
A4
IO/M'
RD
WR
then OutVal(D0) = 1
else OutVal(D0) = 0
= 000
= 000
= 010
= 011
= 000
= 000
= 110
= 111
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
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
d
f
0: ON
1: OFF
0: OFF
1: ON
e
g
+Vcc
DO0
DO1
DO2
DO3
DO4
DO5
DO6
DO7
HCT573
D
a
b
c
d
e
EN
f
g
EN
OE
f
e
Common Anode
Common Cathode
OR
HCT573
D
EN
A
B
C
D
/LE
/BL
/LT
EN
OE
CD4511
D Q
EN
a
b
c
d
e
Buffer
BCD-7seg decoder
Latch
OE
f
g
f
e
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
G1
G2
DO0
DO1
DO2
DO3
DO4
DO5
DO6
DO7
HCT573
D
a
b
c
d
e
EN
f
g
EN
OE
f
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
Interface Board
State
Digit
Empty E
Low
Error
Half
Error
Error
Error
.
.
.
High
Error
Error
DI2
Error
DI1
Error
DI0
Error
Error
.
.
.
.
.
.
Error
Full
DO7
DO6
DO5
DO4
DO3
DO2
DO1
DO0
dp
DI3
Closed
c
g
f
Closed
d
Open
Open
Code
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
G1
G2
DO0
DO1
DO2
DO3
DO4
DO5
DO6
DO7
HCT573
D
a
b
c
d
e
EN
f
g
EN
OE
f
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
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
G1
G2
DO0
DO1
DO2
DO3
DO4
DO5
DO6
DO7
HCT573
D
a
b
c
d
e
EN
f
g
EN
OE
f
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
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.
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 7segment display the letter:
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.
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.
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.
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 xxxxx100 xxxxx101 xxxxx110
xxxxx111
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.
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
EXAMPLE
Use a 82C55 PPI to interface four switches at address 60H
and a SSD at address 62H
Command byte B
Used in mode 1 and mode 2
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
Homework
All examples of slides 31-36 can be modified to include PPI interfacing