EKT 222 MICROPRESSOR SYSTEM - portal.unimap.edu.myportal.unimap.edu.my/portal/page/portal30/Lecture...

14
EKT 222 MICROPRESSOR SYSTEM LAB 4 : IO PORTS USING THE 8255 PPI DEVICE Revision 2019

Transcript of EKT 222 MICROPRESSOR SYSTEM - portal.unimap.edu.myportal.unimap.edu.my/portal/page/portal30/Lecture...

Page 1: EKT 222 MICROPRESSOR SYSTEM - portal.unimap.edu.myportal.unimap.edu.my/portal/page/portal30/Lecture Notes/KEJURUTERAAN... · ekt 222 micropressor system lab 4 : io ports using the

EKT 222

MICROPRESSOR SYSTEM

LAB 4 : IO PORTS USING THE

8255 PPI DEVICE

Revision 2019

Page 2: EKT 222 MICROPRESSOR SYSTEM - portal.unimap.edu.myportal.unimap.edu.my/portal/page/portal30/Lecture Notes/KEJURUTERAAN... · ekt 222 micropressor system lab 4 : io ports using the

1 UniMAP

PPI 8255

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. Microprocessor Training Kit Board MTK-85 3. LEDs, Resistors and wire jumpers 4. 8085 Instruction Sets (Assembly Code) 5. 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 Port B (8 Bit)

RD

WR Port C (8 Bit)

CS

There are four registers that control the operations of the PPI and there are mapped to four address locations in the Microprocessor Taining Kit System (MTK-85) as shown below:

Port Address Port A Register 30H Port B Register 31H Port C Register 32H Control Register 33H

Page 3: EKT 222 MICROPRESSOR SYSTEM - portal.unimap.edu.myportal.unimap.edu.my/portal/page/portal30/Lecture Notes/KEJURUTERAAN... · ekt 222 micropressor system lab 4 : io ports using the

2 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

0 0 0 Port A to Data

bus Data bus to Port A

0 1 0 Port B to Data

bus Data bus to Port B

1 0 0 Port C to Data

bus Data bus to Port C

1 1 0 - Data bus to Control

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

1 Port A and upper half of Port C Port B & lower half of Port C

MODE Port A Port CU MODE Port B Port CL

Figure 1 : 8255 Port control signals

Page 4: EKT 222 MICROPRESSOR SYSTEM - portal.unimap.edu.myportal.unimap.edu.my/portal/page/portal30/Lecture Notes/KEJURUTERAAN... · ekt 222 micropressor system lab 4 : io ports using the

3 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 MTK-85 user 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 33H ; 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 31H ; where 31H is the address of Port B

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

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

Page 5: EKT 222 MICROPRESSOR SYSTEM - portal.unimap.edu.myportal.unimap.edu.my/portal/page/portal30/Lecture Notes/KEJURUTERAAN... · ekt 222 micropressor system lab 4 : io ports using the

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

254 [

MVI C, 255 ; 7 states 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 4 MHz crystal,

T state, Ts= 500 ns. Time delay, td=3574 x 500 ns = 1.79 ms.

Page 6: EKT 222 MICROPRESSOR SYSTEM - portal.unimap.edu.myportal.unimap.edu.my/portal/page/portal30/Lecture Notes/KEJURUTERAAN... · ekt 222 micropressor system lab 4 : io ports using the

5 UniMAP

EKT222 Miroprocessor Systems Lab 4

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

DELAY: MVI B, x1

LOOP: MVI C, x2

LOOP1: DCR C JNZ LOOP1 DCR B JNZ LOOP

Example 2:

DELAY: LXI B, N LOOP: DCX B

MOV A, B ORA A JNZ LOOP

For example 1, we need to calculate x1 and x2. Assume that we need a ~ 250-millisecond delay. The previous sample single loop delay creates 1.79 millisecond. Therefore, if we simply repeat this delay for 140 times we will get around 250 millisecond. Therefore Example 1 subroutine can be written as follows:

DELAY: MVI B, 140 ;7 states

LOOP: MVI C, 255 ;7 states

LOOP1: DCR C ;4 states JNZ LOOP1 ;7/10 states(1o states if

;condition is met or 7 states ;condition not met

DCR B ;4 states JNZ LOOP ; 7/10 states(10 states if

;condition is met or 7 states ;condition not met

RET

The total number of state, Ts = 7 + 139([ 7 + 254(4 + 10) + 1(4 + 7)]+ 4 + 10) +

1([ 7 + 254(4 + 10) + 1(4 + 7)] +(4+7))

Ts = 7 + 139(3574 + (4+10) + (3574+(4+7) = 502,324

Time Delay = 500ns X 502324 = 251.162 millisecond

Page 7: EKT 222 MICROPRESSOR SYSTEM - portal.unimap.edu.myportal.unimap.edu.my/portal/page/portal30/Lecture Notes/KEJURUTERAAN... · ekt 222 micropressor system lab 4 : io ports using the

6 UniMAP

EKT222 Miroprocessor Systems Lab 4

MTK-85 : INTERFACING THE I/O

MTK-85 provides the following I/O interfacing features:

1. General Purpose Input Output (GPIO) provides 4-bit output port using D type F-F, 74LS175 and 4-bit input port using tristate buffer, 74LS126. The address is 00H for both ports. The low-nibble D0-D3 is output port. The higher-nibble D4-D7 is input port. The D0-D3 lines are wired to onboard LED1-LED3 (Figure 1) and Connector J1. The D4-D7 lines are wired to connector J1 (Figure 1).

2. User Programmable Port 8255 - The board provides a user programmable parallel port, 8255. I/O address from 30H to 33H map the 8255’s registers as shown in Table 1. The ports lines are connected to JP2 as shown in Figure 1. All I/O lines are accessible through this connector.

3. System Programmable Port 8255 - The board provides a system programmable parallel port, 8255. I/O address from 10H to 13H map the 8255’s registers as shown in Table 1. This I/O lines are reserved for the monitor program.

Table 1

Address TYPE PORT/REGISTER

00H GPIO I3 I2 I1 I0 O3 O2 O1 O0

10H SYSTEM PPI PORTA(D7D6D5D4D3D2D1D0)

11H SYSTEM PPI PORTB(D7D6D5D4D3D2D1D0)

12H SYSTEM PPI PORTC(D7D6D5D4D3D2D1D0)

13H SYSTEM PPI CONTROL REGISTER

30H USER PPI PORTA(D7D6D5D4D3D2D1D0)

31H USER PPI PORTB(D7D6D5D4D3D2D1D0)

32H USER PPI PORTC(D7D6D5D4D3D2D1D0)

33H USER PPI CONTROL REGISTER

Page 8: EKT 222 MICROPRESSOR SYSTEM - portal.unimap.edu.myportal.unimap.edu.my/portal/page/portal30/Lecture Notes/KEJURUTERAAN... · ekt 222 micropressor system lab 4 : io ports using the

7 UniMAP

Figure 1 MTK-85 GPIO connection to onboard LEDs indicated by red box. Connector J1 is shown by yellow box. User PPI ports are connected to connector JP2(blue box)

Page 9: EKT 222 MICROPRESSOR SYSTEM - portal.unimap.edu.myportal.unimap.edu.my/portal/page/portal30/Lecture Notes/KEJURUTERAAN... · ekt 222 micropressor system lab 4 : io ports using the

8 UniMAP

T222 Miroprocessor Systems Lab 4

LABORATORY TASK

Part A : Introduction to PPI IO Ports on MTK-85

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

1 ORG 8100H 2 MVI A,00H 3 OUT 00H

4 MVI A,01H 5 OUT 00H 6 HLT

Task 2: Driving LED using user PPI

You need to wire 1 LED and 1 kOhm to pin 26 on JP2 connector. Refer to Figure 2.

1 ORG 8100H 2 MVI A,80H 3 OUT 33H 4 MVI A,0FFH 5 OUT 30H 6 MVI A,0FEH 7 OUT 30H 8 HLT

Figure 2

I/O pin driving 8 external LEDS

Data # 1 to send to Port

Data # 2 to send to Port

Data # 2 to send to Port

Data # 1 to send to Port

Page 10: EKT 222 MICROPRESSOR SYSTEM - portal.unimap.edu.myportal.unimap.edu.my/portal/page/portal30/Lecture Notes/KEJURUTERAAN... · ekt 222 micropressor system lab 4 : io ports using the

9 UniMAP

DISCUSSION

1. For task 1, translate the assembly code to machine code and load it to MKT-85 board. Step run the program and observe the LED display. Is the LED light up correctly? Mark the LED that lights up.

3 2 1 0

2. Change the program by replacing data #2 with 02H, 04H & 08H consecutively

and step run the program on MTK-85 board. Observe which LED lights up for each modified program.

3. Wire an LED as shown in the schematic in Figure 2. Translate task 2 assembly

code to machine code and load it to MKT-85 board. Step run the program and observe the LED display. Is the LED light up correctly?

Page 11: EKT 222 MICROPRESSOR SYSTEM - portal.unimap.edu.myportal.unimap.edu.my/portal/page/portal30/Lecture Notes/KEJURUTERAAN... · ekt 222 micropressor system lab 4 : io ports using the

10 UniMAP

EKT222 Miroprocessor Systems Lab 4

Part B : Interfacing the 8255 PPI Device Construct 8 running light LED circuit as in Figure 3. Given a following program of an 8-bit running light :

ORG 8100H MVI A,10000000B ;Port A,B and C as Output. OUT 33H MVI B,FEH

LOOP: MOV A,B OUT 30H RLC MOV B,A JMP LOOP HLT

DISCUSSION

4. Step run 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? Wire the switch to the correct input pin(PB0) as indicated in Figure 3. Step run the modified program.

Figure 3

Page 12: EKT 222 MICROPRESSOR SYSTEM - portal.unimap.edu.myportal.unimap.edu.my/portal/page/portal30/Lecture Notes/KEJURUTERAAN... · ekt 222 micropressor system lab 4 : io ports using the

11 UniMAP

EKT222 Miroprocessor Systems Lab 4

Part C : Delay program for the running light

6. Instead of step run as in steps 4 and 5, run your code and observe the running light. Since the running light is moving at high frequency, 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 250 millisecond per cycles. Remember to set the stack memory location when using the CALL/RETURN instructions.

Page 13: EKT 222 MICROPRESSOR SYSTEM - portal.unimap.edu.myportal.unimap.edu.my/portal/page/portal30/Lecture Notes/KEJURUTERAAN... · ekt 222 micropressor system lab 4 : io ports using the

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

Figure 3

3. Figure 4 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.

Figure 4

Page 14: EKT 222 MICROPRESSOR SYSTEM - portal.unimap.edu.myportal.unimap.edu.my/portal/page/portal30/Lecture Notes/KEJURUTERAAN... · ekt 222 micropressor system lab 4 : io ports using the

11 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 2

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 5

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.