microprocessors input/output interface (chapter 10) dr. costas kyriacou and dr. konstantinos tatas

42
Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

Upload: adele-parker

Post on 05-Jan-2016

223 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

Microprocessors

Input/Output Interface(Chapter 10)

Dr. Costas Kyriacou and Dr. Konstantinos Tatas

Page 2: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 2

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.

Page 3: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 3

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

Page 4: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 4

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

Page 5: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 5

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 addressin 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 addressmov al,value ;move output data into register “al”out dx,al ;output data to the port specified by “dx”

end;

Page 6: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 6

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”

}

Page 7: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 7

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

*/

}

Page 8: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 8

Simple Input Port

• An input port can be implemented using a simple octal buffer such as the 74LS244.

• 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.

• 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.

A19

D7

D0

RD

WR

IO/M'80

88 S

yste

m

A0

+5V

LS244

G1 G2

A11

A10

A9

A8

A7

A6

A5

A4

A11A10 A9 A8 A4A7 A6 A5 A1A3 A2 A0

0 1 0 0 00 1 1 XX X X

Address

460H to 46FH

Switch Open => Logic 1Switch Closed => Logic 0

Page 9: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 9

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 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.

• 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.

LS373

D Q

EN

EN OE

A19

D7

D0

RD

WR

IO/M'8

08

8 S

ys

tem

A0

+5V

A11

A10

A9

A8

A7

A6

A5

A4

A11 A10 A9 A8 A4A7 A6 A5 A1A3 A2 A0

0 1 0 0 00 1 1 XX X X

Address

460H to 46FH

Logic 1 => LED is OFFLogic 0 => LED is ON

Page 10: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 10

Simple Output Port (Using the 74HCT573)

• The 74HCT573 is pin compatible with the 74LS373. There are three significant differences:

– 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.

– 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.

HCT573

D Q

EN

EN OE

A19

D7

D0

RD

WR

IO/M'

808

8 S

yste

m

A0

A11

A10

A9

A8

A7

A6

A5

A4

A11 A10 A9 A8 A4A7 A6 A5 A1A3 A2 A0

1 0 0 0 10 1 0 XX X X

Address

850H to 85FH

+5V

Logic 1 => LED is OFFLogic 0 => LED is ON

Logic 1 => LED is ONLogic 0 => LED is OFF

Page 11: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 11

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.

Page 12: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 12

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 portUntil keypressed

C/C++ Codemain(){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());}

Page 13: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 13

Mask Operations

(a) Write a program to keep reading the .

(b) Write a program to keep reading the state of the switches and switch ON the LEDs for which the corresponding switch is closed.

Page 14: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 14

Simple I/O Example 2Four 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.

Inte

rfa

ce B

oa

rd

EmptyLowHalfFull

DI3

DI2

DI1

DI0

DO3

DO2

DO1

DO4

Closed

Closed

Open

Open

High

DO0

DI3 DI2 DO3 DO2 DO1

0 0 0 0 0 0 0

0 0 0 1 0 0 0

0 0 1 0 1 1 1

0 0 1 1 0 0 1

0 1 0 0 1 1 1

0 1 0 1 1 1 1

0 1 1 0 1 1 1

0 1 1 1 0 1 0

1 0 0 0 1 1 1

1 0 0 1 1 1 1

1 0 1 0 1 1 1

1 0 1 1 1 1 1

1 1 0 0 1 1 1

1 1 0 1 1 1 1

1 1 1 0 1 1 1

1 1 1 1 1 0 0

DI1 DI0

Empty

Low

Error

Half

Error

Error

Error

High

Error

Error

Error

Error

Error

Error

Error

Full

0 1

1 0

1 1

0 0

1 1

1 1

1 1

0 0

1 1

1 1

1 1

1 1

1 1

1 1

1 1

0 0

DO0DO4 State

Page 15: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 15

Simple I/O Example 2 (Circuit Diagram)

A19

D7

D0

RD

WR

IO/M'

8088

Sys

tem

A0

+5V

HCT573

D Q

EN

EN OE

LS244

G1 G2

DI0

DI1

DI2

DI3

DO4

DO3

DO2

DO1

DO0

A11

A10

A9

A8

A7

A6

A5

A4

A11A10 A9 A8 A4A7 A6 A5 A1A3 A2 A0

0 1 0 0 00 1 1 XX X X

Address

460H to 46FH

Page 16: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 16

Simple I/O Example 2 (Software using Case/Switch Statement)

Pseudo Code:

Set OutVal to 0, i.e switch off all leds

Repeat

Read Input port in InVal

Mask out D3,D2,D1,D0 from InVal

Case of InVal

0: OutMask = 1

1: OutMask = 2

3: OutMask = 4

7: OutMask = 8

FH: OutMask = 10H

else OutMask = 1FH

Mask in D4 to D0 of OutMask in OutVal

Write OutVal to Output portUntil keypressed

C/C++ Code

main(){

short InVal, OutVal = 0;

do {

InVal = Inp32(0x460);

InVal = InVal & 0xf;

switch (InVal) {

case 0: OutMask = 1; break;

case 1: OutMask = 2; break;

case 3: OutMask = 4; break;

case 7: OutMask = 8; break;

case 0xf: OutMask = 0x10; break;

default OutMask = 0x1f; }

OutVal = (OutVal & 0xe0) | OutMask;

Out32(0x460,OutVal);} while (!_kbhit());}

Page 17: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 17

Simple I/O Example 2 (Software using array as a lookup table)

Pseudo Code:

Table[0] = 00001 /*

Table[1] = 00010 /*

Table[3] = 00100 /*

Table[7] = 01000 /*

Table[15] = 10000 /*

Table[rest] = 111111 /*

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

C/C++ Code

main(){

short InVal, OutVal = 0;

short Table[16] = 0x1, 0x2, 0x1f, 0x4,

0x1f, 0x1f, 0x1f, 0x8,

0x1f, 0x1f, 0x1f, 0x1f,

0x1f, 0x1f, 0x1f, 0x10;

do {

InVal = Inp32(0x460);

InVal = InVal & 0xf;

OutMask = Table[InVal];

OutVal = (OutVal & 0xe0) | OutMask;

Out32(0x460,OutVal);} while (!_kbhit());}

Page 18: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 18

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)

• 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.

Average Voltage

Page 19: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 19

DC motor interface exampleA 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.

0

1

0

1

0

1

Start/Stop Fast/Slow Fwrd/Rev.

Interface Board

DC Motor

Page 20: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 20

DC motor interface example(Circuit Diagram)

A11A10 A9 A8 A4A7 A6 A5 A1A3 A2 A0

0 1 0 0 00 1 1 XX X X

Address

460H to 46FH

RL1

ULN2803

Com

RL2

RL2

M

A19

D7

D0

RD

WR

IO/M'

808

8 S

yste

m

A0

+5V

HCT573

D Q

EN

EN OE

LS244

G1 G2

DI7

DI6

DI5

DI4

DO2

DO1

DO0

A11

A10

A9

A8

A7

A6

A5

A4

On/OffFast/Slow

Frwd/Rev.+5V

+5V

+5V

DI3

DI2

DI1

DI0

Page 21: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 21

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

Page 22: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 22

DC motor interface example (Software using a lookup table)

Pseudo Code:

Table[0] = 000 /* 000 ->motor is OffTable[1] = 000 /* 001 ->motor is OffTable[2] = 010 /* 010 -> On-Slow-RevTable[3] = 011 /* 011 -> On-Slow-FrwdTable[4] = 000 /* 100 -> motor is OffTable[5] = 000 /* 101 -> motor is OffTable[6] = 110 /* 110 ->On-Fast-RevTable[7] = 111 /* 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

Page 23: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 23

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

ab

c

de

f

g

a

b

c

d

e

f

g

a b c d e f g

a b c d e f g

+Vcc

0: OFF1: ON

0: ON1: OFF

Common Cathode Common Anode

Can be connected directly on an O/P port Through a BCD/7 segment decoder OR

HCT573

D Q

EN

EN OE

DO4

DO3

DO2

DO1

DO0

DO5

DO6

DO7

ab

c

de

f

g

a

b

c

d

e

f

g

HCT573

D Q

EN

EN OE

DO4

DO3

DO2

DO1

DO0

DO5

DO6

DO7

ab

c

de

f

g

a

b

c

d

e

f

g

CD4511

D

OE

A

/LE

C

B

D

/BL

/LT

EN

Q

Latc

h

BC

D-7

seg

dec

oder

Bu

ffer

Page 24: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 24

7-segment Displays – Example1

A19

D7

D0

RD

WR

IO/M'

8088

Sys

tem

A0

+5V

HCT573

D Q

EN

EN OE

LS244

G1 G2

DI0

DI1

DI2

DI3

DO4

DO3

DO2

DO1

DO0

A11

A10

A9

A8

A7

A6

A5

A4

DO5

DO6

DO7

ab

c

de

f

g

a

b

c

d

e

f

g

x 0 1 1 1 1 1 1 3Fx 0 0 0 1 1 0 0 0Cx 1 1 1 0 1 1 0 76x 1 0 1 1 1 1 0 5Ex 1 0 0 1 1 0 1 4Dx 1 0 1 1 0 1 1 5Bx 1 1 1 1 0 1 1 7Bx 0 0 0 1 1 1 0 0Ex 1 1 1 1 1 1 1 7Fx 1 0 0 1 1 1 1 4Fx 1 1 0 1 1 1 1 6Fx 1 1 1 1 0 0 1 79x 0 1 1 0 0 1 1 33x 1 1 1 1 1 0 0 7Cx 1 1 1 0 0 1 1 73x 1 1 0 0 0 1 1 63

- g f e d c b aD0D1D2D3D4D5D6D7

• 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.

Page 25: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 25

7-segment Displays – Example1: Program

Page 26: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 26

7-Segment Displays: Example 2

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.

Inte

rfa

ce B

oard

DI3

DI2

DI1

DI0

DO3

DO2

DO1

DO4

DO0

DO6

DO5

DO7

ab

c

de

f

g

a

b

c

d

e

f

g

dp

Open

Open

Closed

Closed

DI3 DI2

0 0 0 0

0 0 0 1

0 0 1 0

0 0 1 1

0 1 0 0

0 1 0 1

0 1 1 0

0 1 1 1

1 0 0 0

1 0 0 1

1 0 1 0

1 0 1 1

1 1 0 0

1 1 0 1

1 1 1 0

1 1 1 1

DI1 DI0

Empty

Low

Error

Half

Error

Error

Error

High

Error

Error

Error

Error

Error

Error

Error

Full

State

E

L

.A

.

.

.H

.

.

.

.

.

.

.F

Digit Code

Page 27: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 27

7-segment Displays – Example1: Program

Page 28: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 28

7-segment Displays – Example3

A19

D7

D0

RD

WR

IO/M'

8088

Sys

tem

A0

+5V

HCT573

D Q

EN

EN OE

LS244

G1 G2

DI0

DI1

DI2

DI3

DO4

DO3

DO2

DO1

DO0

A11

A10

A9

A8

A7

A6

A5

A4

DO5

DO6

DO7

ab

c

de

f

g

a

b

c

d

e

f

g

x 0 1 1 1 1 1 1 3Fx 0 0 0 1 1 0 0 0Cx 1 1 1 0 1 1 0 76x 1 0 1 1 1 1 0 5Ex 1 0 0 1 1 0 1 4Dx 1 0 1 1 0 1 1 5Bx 1 1 1 1 0 1 1 7Bx 0 0 0 1 1 1 0 0Ex 1 1 1 1 1 1 1 7Fx 1 0 0 1 1 1 1 4Fx 1 1 0 1 1 1 1 6Fx 1 1 1 1 0 0 1 79x 0 1 1 0 0 1 1 33x 1 1 1 1 1 0 0 7Cx 1 1 1 0 0 1 1 73x 1 1 0 0 0 1 1 63

- g f e d c b aD0D1D2D3D4D5D6D7

• 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.

Page 29: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 29

7-segment Displays – Example1: Program

Page 30: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 30

7-segment Displays – Example1

A19

D7

D0

RD

WR

IO/M'

8088

Sys

tem

A0

+5V

HCT573

D Q

EN

EN OE

LS244

G1 G2

DI0

DI1

DI2

DI3

DO4

DO3

DO2

DO1

DO0

A11

A10

A9

A8

A7

A6

A5

A4

DO5

DO6

DO7

ab

c

de

f

g

a

b

c

d

e

f

g

x 0 1 1 1 1 1 1 3Fx 0 0 0 1 1 0 0 0Cx 1 1 1 0 1 1 0 76x 1 0 1 1 1 1 0 5Ex 1 0 0 1 1 0 1 4Dx 1 0 1 1 0 1 1 5Bx 1 1 1 1 0 1 1 7Bx 0 0 0 1 1 1 0 0Ex 1 1 1 1 1 1 1 7Fx 1 0 0 1 1 1 1 4Fx 1 1 0 1 1 1 1 6Fx 1 1 1 1 0 0 1 79x 0 1 1 0 0 1 1 33x 1 1 1 1 1 0 0 7Cx 1 1 1 0 0 1 1 73x 1 1 0 0 0 1 1 63

- g f e d c b aD0D1D2D3D4D5D6D7

• 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.

Page 31: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 31

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.

Page 32: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 32

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.

Homework- Question 2

Page 33: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 33

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 3

Page 34: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 34

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 4

Page 35: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 35

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.

Homework- Question 5

xxxxx000 xxxxx001 xxxxx010 xxxxx011 xxxxx100 xxxxx101 xxxxx110 xxxxx111

E I L U H Γ Ξ F

Page 36: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 36

a) Draw a circuit diagram to show how the following can be interfaced to an 8088 system

i. Three switches connected on an I/P port occupying the address range from 60H to 6FH.ii. Eight Leds connected on an O/P port occupying the address range from 50H to 5FH.

b) Write a program toi. read the code formed by the three switches in a 1-second time intervals,

ii. 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.  

0 0 00 0 0

0 0 10 0 1

0 1 00 1 1

0 1 10 1 0

1 0 01 1 0

1 0 11 0 0

1 1 01 0 1

1 1 11 1 1

Input Binary Bar Graph

Homework- Question 6

Page 37: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 37

THE 82C55 PROGRAMMABLE PERIPHERAL INTERFACE (PPI)

VCC: The +5V power supply pin. GND: GROUNDD0-D7: I/O DATA BUSRESET: 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.

•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).

Page 38: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 38

INTERFACING 82C55 TO AN 8088 SYSTEM (ports 60H-63H)

A19

D7

D0

RD

WR

IO/M'

808

8 S

yst

em

A0

DI0

DI1

DI2

DI3

A7

A6

A5

A4

A3

A2

82C

55

D7

D0

RD

WR

A0A1

PA7

PA0

PB7

PB0

PC7

PC0

CS

A0

A1

Page 39: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 39

EXAMPLE

• Use a 82C55 PPI to interface four switches at address 60H and a SSD at address 62H

A19

D7

D0

RD

WR

IO/M'

8088

Sys

tem

A0

+5VDI0

DI1

DI2

DI3

A7

A6

A5

A4

A3

A2

ab

c

de

f

g

a

b

c

d

e

f

g82

C55

D7

D0

RD

WR

A0A1

PA7

PA0

PB7

PB0

PC7

PC0

CS

A0

A1

DI0

DI1

DI2

DI3

DI0

DI1

DI2

DI3

Page 40: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 40

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 (0-mode 0, 1-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

Page 41: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 41

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

Page 42: Microprocessors Input/Output Interface (Chapter 10) Dr. Costas Kyriacou and Dr. Konstantinos Tatas

ACOE255 Microprocessors I - Frederick University 42

Homework• All examples of slides 31-36 can be modified to include PPI interfacing