Vous êtes sur la page 1sur 5

Microprocessor Systems Design (EEE315M2)

Lab - week 6

Aims: Interfacing I/O and programming PPI 8255

Intel PPI 8255 has three ports A, B, C, and a control register for initialisation. Ports A
and B can be programmed as either input or output and ports A and C can be used as
bidirectional. Port C can be programmed as a pair of 4-bit bidirectional control ports or
individual lines can be set or reset.

These ports operate in three modes mode 0, mode 1, and mode 2. The ports and control
register are mapped to addresses as follows:

Name of Port Address


Port A $106C
Port B $106D
Port C $106E
Control register $106F

Exercise 1: Initialising ports

Before reading or writing from or to a port, it should be initialised. Initialisation is done


in the following way
• Find the control word
• Load the control word into control register
• Read or write from or to port

Control word can be found by setting or resetting individual bits of the control register
according to the requirement.

7 6 5 4 3 2 1 0
D7 D6 D5 D4 D3 D2 D1 D0
Group B
Port C(L) – 1 Input
0 output
Port B – 1 Input 0 output
Mode select: 0 mode 0; 1 mode 1

Port C(U) – 1 Input 0 output


Port A – 1 Input 0 output
Mode select: 00 mode 0;
01 mode 1; 1x mode 2
1 – mode select
Group A
0 – bit set/reset
Suppose you have to read from port A and send a result to port B in order to interface
another subsystem. Initialise the ports of PPI 8255. Display the control word on LED
display.

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

Port C(L) – x
Port B – 0 output
Mode select: 0 mode 0

Port C(U) – x don’t care


Port A – 1 Input

Mode select: 00 mode 0

1 – mode select

Control word is then 1 00 1 x 0 0 x - don’t cares can be chosen as 0 or 1. So the control


word is 1 00 1 0 0 0 0. This is equivalent to $90

.area text
_main::
LDAA #$90 ;A ← control word $90
STAA $106F ;put control word into control register -$106F
;always use a time delay
BSR Delay40

STAA $1064 ;display control word on LEDs


BSR Dealy40

SWI ;Return to monitor

Delay40: LDAB #40


Loop: DECB
BNE Loop
RTS ;Return to main program
Exercise 2: Reading a port

Ports A, B, and C are memory mapped whose addresses are given as $106C, $106D, and
$106E. Reading a port is done by simply reading the memory addresses of the ports.

Suppose you are designing a microprocessor-based door lock. It will compare a code
value and will open the door for few seconds if it matches the code. The code is read
from 8-pins of port A. Write an HC11 assembly language program for the digital lock.
Open door is indicated by the switching the 1st LED on and closed door is indicated by
switching all the LEDs (1st through 8th ) on.

.area text
_main::

;Initialisation
LDAA #$90 ;A ← control word $90
STAA $106F ;put control word into control register -$106F
BSR Delay40

LDAA $106C ;Read port A


CMPA $1003 ;Compare A with [$1003]
BNE Close

Open: LDAA #01


STAA $1064
BSR Dealy40

Close: LDAA $FF


STAA $1064
SWI ;Return to monitor

Delay40: LDAB #40


Loop: DECB
BNE Loop
RTS

Exercise 3: Writing to port

Writing to ports is done by simply storing values to the memory addresses of the ports.

Modify the program in exercise 2 by lighting red LED to indicate closed door and green
LED to indicate open door.
.area text
_main::

;Initialisation
LDAA #$90 ;A ← control word $90
STAA $106F ;put control word into control register -$106F
BSR Delay40

LDAA $106C ;Read port A


CMPA $1003 ;Compare A with [$1003] before that store a code
BNE Close

Open: LDAA #01


STAA $106D ;Write to port B
BSR Dealy40

Close: LDAA $......


STAA $106D ;Write to port B
SWI ;Return to monitor

Delay40: LDAB #40


Loop: DECB
BNE Loop
RTS

0 5v signal
1
Port A 2
3
4
5
8255- 6
7
MC68HC11- 0 +
1
based µP 2
-
3
4

Port B
5
6 +
7
-
Figure 1

Exercise 4: Consider the application shown in Figure 2. Three traffic signal lights, green,
amber and red are to be controlled by the microprocessor over the 8255 PPI. The green
light is connected to pins (0,1) denoted by G, amber light is connected to pins (3,4)
denoted by A and the red light is connected to pins (6,7) denoted by R. For experiment
we used 3 LEDs. The green light will go on and stay on for some time. When green light
will go off, the amber will go on and stay on for some time. When the amber will go off,
the red will go on and stay for some time. The sequence will be repeated continuously.
Address of control register and port B are $106F and $106D respectively. Develop the
systems using 3 LEDs connected to ports of PPI 8255. Write an assembly language
program for the control problem.

Port B 0 -
8255- 1 G

MC68HC11-
2
3 - +
A
4
based µP 5
6 - +
7 R
+

Figure 2

Exercise 5: Consider the application in Figure 3. The switch button generates a 5V


signal to pin 0 of port A. The microprocessor system will turn on the LED connected
to pin 6 and 7 of port B if the switch is on. Develop the systems using a switch and a
LED connected to ports of PPI 8255. Write an assembly language program which will
perform the task.

0
1
Port A 2 switch
3
4
5
8255- 6
7
MC68HC11- 0
1
based µP 2
3
4

Port B
5
6
+
7
-
Figure 3

You need to submit exercises 4 and 5 with proper lab cover sheet. Demonstrate the
functioning system to demonstrator/module coordinator.

Vous aimerez peut-être aussi