You are on page 1of 12

EKT 222

MICROPRESSOR SYSTEM

LAB 4 : IO PORTS USING THE


8255 PPI DEVICE
EKT222 Miroprocessor Systems Lab 4

LAB 4: I/O Ports using the


8255 PPI Device
Objectives:
1) Ability to define the 8255 PPI device
2) Ability to create programs using the I/O ports
3) Ability to execute and demonstrate simple instructions
4) Ability to analyze the 8085 register and memory map conditions

Equipments :
1. Computer station with Windows OS and MY1 8085 simulation program
2. 8085 Instruction Sets (Assembly Code)
3. 8085 Instruction Sets (Machine Code)

Introduction
The 8255 Programmable Peripheral Interface (PPI) is the general purpose
interface device which is widely used in Intel 8085 microprocessor design. It
contains three independent 8 bit ports named Port A, B and C. Port A and B can be
programmed as either input or output (all eight line must be same), while port C is
split into two 4 bit halves (Port C upper (PC4-PC7) and Port C lower (PC0-PC3) that
can be separately programmed as input or output.

Data Bus (8 Bit)

A0 Port A (8 Bit)

A1 PPI 8255
Port B (8 Bit)
RD

WR Port C (8 Bit)

CS

There are four register that control the operations of the PPI and there are mapped
to four address locations in the 8085 Development System as shown below:

Port Address
Port A Register 80H
Port B Register 81H
Port C Register 82H
Control Register 83H

1
UniMAP
EKT222 Miroprocessor Systems Lab 4

Table 1 shows the details of signals involved in controlling the PPI.

A0 A1 CS RD=1 WR=0
Port A to Data
0 0 0 Data bus to Port A
bus
Port B to Data
0 1 0 Data bus to Port B
bus
Port C to Data
1 0 0 Data bus to Port C
bus
Data bus to Control
1 1 0 -
Register

Table 1 : 8255 Port control signals

The control register is used to configure the PPI into a variety of operation modes.
There are three basic modes:

 mode 0 : basic input/output


 mode 1 : strobe input/output
 mode 2 : bidirectional bus

We will only concentrate at mode 0. Further descriptions about mode 1 and 2 can
be referred to the 8255 datasheet. Mode 0 provides for simple input output
operations with no handshaking. This means that data either to or from the port
does not depends to other signal for data transfer. Basically, to configure the PPI, a
control word must first be sent to the control register @ port 83H. Figure 1
summarizes the control word format.

bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0


Port A and upper half of Port C Port B & lower half of Port C
1
MODE Port A Port CU MODE Port B Port CL

Figure 1 : 8255 Port control signals

2
UniMAP
EKT222 Miroprocessor Systems Lab 4

Mode Definition Control Byte. Indicate by bit b7=1.

Group A - Port A and upper half of Port C


Bit b3 to a bit b6 control the mode and direction of Group A

b6 & b5 mode operation


0 0 (mode 0)
0 1 (mode 1)
1 0 (mode 2)
b4 Port A direction, 0=output, 1=input
b3 upper half of Port C direction, 0=output, 1=input

Group B - Port B and lower half of Port C


Bit b0 to bit b2 control the mode and direction of Group B

b2 mode operation, 0=mod 0, 1=mod 1


b1 Port B direction, 0=output, 1=input
b0 lower half of Port C direction, 0=output, 1=input

Therefore to enable these ports to function as input or output, the microprocessor


needs to configure the PPI by sending the control word as describe above to the
control register.

The instruction below is an example used to configure the PPI so that port A
functions as input and port B & C as output.

MVI A, 90H ; Set Port A= I/P and Port B & C=O/P.


OUT 83H ; Send control word to control register.

When the control port is configured, the data can be sent to any of the output port
using OUT instruction. For example, if a data is to be sent to the Port B. The data
must first be loaded into the accumulator and OUT instruction is used as below.

MVI A, 55H
OUT 81H ; where 81H is the address of Port B

To read a data from Port A to the accumulator, IN instruction is used.

IN 80H ; where 80H is the address of Port A

3
UniMAP
EKT222 Miroprocessor Systems Lab 4

Delay Programming Instructions

The processor speed is very fast in dealing the fetch and execute cycles.
Normally humans tend to ignore internal processes especially when a faster
operation gives quicker result than slower processors. But when dealing with inputs
and outputs, certain conditions do require a more moderate speed for humans to
accommodate.

An example where slower tempo is required for humans to accommodate can be


seen on a running light. A program to set the lights running without any delay will
cause a human to observe that all lights are turned on if the processor clock speed is
high. With the inclusion of a delay cycle to reduce the frequency will then allow
humans to observe the running light operation.

Basically, the NOP instruction code can be used as a simple delay cycle for the
microprocessor. A longer delay program can be seen as :

MVI C, 255
LOOP: DCR C
JNZ LOOP

This program forms a loop which will decrease the contents of register C by 1 until
gradually reaches 0. Any instructions after JNZ will be executed after register C
equals to zero. This loop will create a delay that can be used for certain
microprocessor application. The time delay depend’s on the instruction set which
determines the T-state for each instruction. (Please refer to Instructions Code
Summary). The following example shows the calculation of the software delay
routine.

MVI C, 255 ; 7 states


254 [ LOOP: DCR C ; 4 states
JNZ LOOP ; 7/10 states (10 states if condition is met or 7
; states if the condition not met)

The total number of state,  Ts = 7 + 254(4 + 10) + 1(4 + 7) = 3574.

Where
T state, Ts=1 / (0.5 x crystal frequency)

For 6.144 MHz crystal,

T state, Ts= 325 ns. Time delay, td=3574 x 325 ns = 1.16 ms.

4
UniMAP
EKT222 Miroprocessor Systems Lab 4

For a much longer delay, the following program can be used :

DELAY: MVI B, x1
LOOP: MVI C, x2
LOOP1: DCR C
JNZ LOOP1
DCR B
JNZ LOOP

Or

DELAY: LXI B, N
LOOP: DCX B
MOV A, B
ORA A
JNZ LOOP

5
UniMAP
EKT222 Miroprocessor Systems Lab 4

MY1 Sim85 : INTERFACING THE I/O

1. The 8085 Simulator, MY1 Sim85, also provides hardware devices to the user.
By default once the software is opened, an 8-bit LED device is assigned to
Port A @ 80H and an 8-bit SWITCH device is assigned to Port B @ 81H.

8-bit LED 8-bit Switch


@ 80H @ 81H

2. Input output device selections can also be done by choosing Devices from the
Main Menu.

3. To change the ports :


a. Right mouse click on an existing port and remove the port assignment
b. Right mouse click on the desired port and assign the free port

Example : replacing LED with a 7-segment display

1
2

Remove PA0 from LED and


reassign PA0 to 7-segment

6
UniMAP
EKT222 Miroprocessor Systems Lab 4

LABORATORY TASK

Part A : Introduction to PPI IO Ports on MY1 Sim85

In this task, we will observe how to assign an output to an LED. Given is the program
to display 1-bit LED :

1 ORG 0000H
2 MVI A,80H
3 OUT 83H
4 MVI A,0
5 OUT 80H
6 MVI A,1
7 OUT 80H
8 HLT

DISCUSSION

1. Step simulate the program above and observe the LED display. Which LED
lights up?

7 6 5 4 3 2 1 0

2. Remove PA0 and PA4 from the LED0 and LED4 display and swap the ports
assignment. LED0 assign with PA4 while LED4 assign with PA0. Step simulate
again and explain your observation.

3. Reset the LEDs with the proper port assignments. Change the instruction at
line 6 to:
MVI A,16.

Step simulate again and explain your observation

7
UniMAP
EKT222 Miroprocessor Systems Lab 4

Part B : Interfacing the 8255 PPI Device

Given a following program of an 8-bit running light :

ORG 0000H
MVI A,10011000B
OUT 83H
MVI B,01H
LOOP: MOV A,B
OUT 80H
RLC
MOV B,A
JMP LOOP
HLT

DISCUSSION

4. Step simulate the program and observe the operation. What can you say
about the running lights coming out at Port A of the PPI?

5. Set the PPI control register so that Port B is an input port switch. What is the
suitable program to show the running light when the switch at PB0 is turned
on but pauses when it is turned off? Step simulate your modified program.

8
UniMAP
EKT222 Miroprocessor Systems Lab 4

Part C : Delay program for the running light

6. Instead of step simulate as in steps 4 and 5, run your simulation and observe
the running light. Since the running light is moving at high fequency, you will
need to reduce the clocking frequency to adjust to your eye movement.
Create a delay subroutine to delay the running light by at least 5 clock cycles.
Remember to set the stack memory location when using the CALL/RETURN
instructions.

9
UniMAP
EKT222 Miroprocessor Systems Lab 4

EXERCISE

1. Eight LEDs are assigned to represent eight push-pull switches respectively.


Write a program that will display the switches on/off value.

2. Figure 1 shows the connection between LED and switch with 8255 I/O port.
Write a program to make the LED blink when the switch is ON and stop
blinking when the switch is OFF. VCC

U3 SW2
34 4 1 16
33 D0 PA0 3 2 15
32 D1 PA1 2 3 14
31 D2 PA2 1 4 13
30 D3 PA3 40 5 12
29 D4 PA4 39 6 11
28 D5 PA5 38 7 10
27 D6 PA6 37 8 9
D7 PA7
5 18 SW DIP-8
36 RD PB0 19
9 WR PB1 20
8 A0 PB2 21 VCC
35 A1 PB3 22
6 RESET PB4 23
CS PB5 24
PB6 25
PB7
14
PC0 15
PC1 16
PC2 17
PC3 13
PC4 12
PC5 11
PC6 10
PC7
8255

Figure 1

3. Figure 2 below shows the connection interface of four switches and LED with
Port A and Port C. The switches represent as a 4-bit data input. Write a
program to read 4 bit data input from the switches and the value will be used
to determine how many time the LED should blink.
VCC

U3 SW2
34 4 1 16
33 D0 PA0 3 2 15
32 D1 PA1 2 3 14
31 D2 PA2 1 4 13
30 D3 PA3 40 5 12
29 D4 PA4 39 6 11
28 D5 PA5 38 7 10
27 D6 PA6 37 8 9
D7 PA7
5 18 SW DIP-8
36 RD PB0 19
9 WR PB1 20
8 A0 PB2 21 VCC
35 A1 PB3 22
6 RESET PB4 23
CS PB5 24
PB6 25
PB7
14
PC0 15
PC1 16
PC2 17
PC3 13
PC4 12
PC5 11
PC6 10
PC7
8255

Figure 2

10
UniMAP
EKT222 Miroprocessor Systems Lab 4

4. Using two push-pull switches and eight LEDs, write a program of an 8-bit
running light that will have the following specifications shown in Table 1 :

SW1 SW0 Action


0 0 No lights ON
0 1 Running light MSB-LSB
1 0 Running light LSB-MSB
1 1 All lights ON

Table 1

5. Write a program that will display a MOD-16 counter onto a 4-bit LED.

6. A BCD counter is to be displayed onto a 4-bit LED. Write a program that will
count the BCD counter on every push button.

7. Figure 3 below show the operation of a certain running light :

Figure 3

On every clock pulse, the upper 4-bit will shift to the right while the lower 4-
bit will shift towards the left. When the upper 4-bit reaches its LSB it will
change direction and shift to the left. The same will happen to the lower 4-bit
once it reaches its MSB, it will change direction and shifts to the right.

Write a program to show the operation of this running light.

11
UniMAP

You might also like