[go: up one dir, main page]

0% found this document useful (0 votes)
9 views44 pages

Chapter 9-Part2 - Merged

The document provides detailed information on the Programmable Peripheral Interface (PPI) 8255, including pin descriptions and various applications for interfacing with input and output devices using assembly language programs. It covers applications such as connecting switches to displays, driving motors, and reading keyboard inputs, along with the necessary assembly language code for each application. Additionally, it discusses interfacing digital to analog converters and the handshaking mode for data transfer between devices.

Uploaded by

shikah7214
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views44 pages

Chapter 9-Part2 - Merged

The document provides detailed information on the Programmable Peripheral Interface (PPI) 8255, including pin descriptions and various applications for interfacing with input and output devices using assembly language programs. It covers applications such as connecting switches to displays, driving motors, and reading keyboard inputs, along with the necessary assembly language code for each application. Additionally, it discusses interfacing digital to analog converters and the handshaking mode for data transfer between devices.

Uploaded by

shikah7214
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

PROGRAMMABLE PERIPHERAL INTERFACE (PPI) -8255

PROGRAMMABLE PERIPHERAL INTERFACE (PPI) -8255

Pin description
𝑪𝑺 A1 A0 Selection
0 0 0 Port-A
0 0 1 Port-B
0 1 0 Port-C
0 1 1 Control Register
Application # 1: Port-A (PA0 – PA3) is connected to four switches and Port-B (PB0 – PB3) is connected to 7-segment display
driver to display decimal value of the binary information of the switches. Write an ALP program to perform the job.

.MODEL SMALL
PORTA EQU 8000H
PORTB EQU 8001H
PORTC EQU 8002H
CR EQU 8003H
.CODE
MOV DX, CR
MOV AL, 10011001B
OUT DX, AL
Start: MOV DX, PORTA
IN AL, DX
INC DX
OUT DX, AL
JMP Start
END
Application # 2: An 8255 IC is used to interface input and output devices with the 8086 microprocessor. Port-A
is connected to 8 LEDs, Port-B is connected to 8 switches and Port-C lower (PC0 – PC3) is connected to seven-
segment display. Write a program to sense the pattern of the switches, turn ON the LEDs according to same
pattern of the switches and find the number of ON Switches to show on seven-segment display.

The Assembly Language Program(ALP):


;Control Word: 1000 X010 = 82H / 8AH
.model small
MOV AL, 82H
OUT 0746H, AL
START: IN AL, 0742H
OUT 0740H, AL
MOV BL, 0
MOV CX, 8
L2: ROL AL, 1
JNC L1
INC BL
L1: LOOP L2
MOV AL, BL
OUT 0744H, AL
JMP START
END
Application # 3: An 8255 IC is used to interface input and output devices with the 8086 microprocessor. Port-A
is connected to seven-segment display driver and Port-B is connected to digit driver for 8-digit display set .
Write a program to display UOHB2019 on the screen.

1 turns segment ON

0 turns digit ON
.model small START:
PA equ 8060H MOV CL, 8
PB equ 8062H MOV SI, OFFSET
PC equ 8064H TABLE
CR equ 8066H MOV AL, 0FEH
TABLE DB XX L1: OUT PB, AL
DB XX MOV AH, AL
DB XX MOV AL, [SI]
DB XX OUT PA, AL
DB XX CALL DELAY ; 1
DB XX ms Delay
DB XX INC SI
DB XX ROL AH, 1
A15A14A13A12 A11A10A9A8 A7A6A5A4 A3A2A1A0 .code
1 0 X X X X X X X 1 1 0 X 00 0 = 8060H (Port-A) MOV AL, 80H MOV AL, AH
1 0 X X X X X X X 1 1 0 X 01 0 = 8062H (Port-B) OUT CR, AL LOOP L1
1 0 X X X X X X X 1 1 0 X 10 0 = 8064H (Port-C) JMP START
1 0 X X X X X X X 1 1 0 X 11 0 = 8066H (Control
Register) DELAY: MOV CX, 270
Control Word: 1000 X00X = 80 H/89H L: DEC CX
JNZ L
RET
END
Application # 4: An 8255 IC is used to interface input and output devices with the 8086 microprocessor. Port-A
is connected to stepper motor. Write a program to drive the motor on 2-phase ON mode.

The Assembly Language Program(ALP):


; Port-A address: 0010 0000 0000 0000 = ; 2000 H
; Port-B address: 2001 H
; Port-C address: 2002 H
; CR address: 2003 H
; Control Word: 1000 0000 = 80 H
.model small
MOV AL, 80H
OUT 2003H, AL
L2: MOV AL, 33 H
MOV CX, 4
M: OUT 2000H, AL
CALL DELAY ; 1 ms delay
ROL AL, 1
LOOP M
JMP L2

DELAY: MOV CX, 273


L: DEC CX
JNZ L
RET
END
Keyboard Reading Procedure: 1st row is made
zero/Gnd and scan is done at all columns. If any key is
pressed, a zero will be found. Then it makes the 2nd
row Gnd and scan all the columns. There should be
10 ms provided, so that the key can be bounced back.
This is the algorithm for keyboard reading.

o Therefore, it is necessary that the bouncing of the key should


not be read as in input. o The key bounce can be eliminated
from input data by the key-debounce technique, using either
hardware or software.
GND
How key works on a keyboard

We suppose that we use simple mechanical switches.


For keyboard, then to get the meaningful data from a
keyboard requires three steps :
• (1) Detect a key press
• (2) Debounce the key press
• (3) Encode the key press
The three tasks can be done with a hardware,
software or a combination of the two.
The rows of the matrix are connected to four output
port lines. The column line of the matrix are
connected to four input port lines

• Here we use port A as output port for selecting a row of keys


while port B is used as an input port for sensing a closed key. •
Hence the keyboard lines are selected one by one through Port
A and the Port B lines are polled continuously till a key closure
is sensed. • The higher order lines of Port A and Port B are left
unused. The flow chart of the ALP is as shown below :
Example 5:- Interface a 4 4 Hex keyboard with 8086
using 8255, and write an ALP for detecting a key closure
and show it on 7-Segment display connected to PC (PC0
– PC3). The debouncing period for a key in 10 ms.

ROW0: MOV al, 0FEH


OUT PA, AL ROW3: MOV al, 0F7H
IN AL, PB OUT PA, AL
And AL, 0FH IN AL, PB
CMP AL, 0FH And AL, 0FH
JE ROW1 CMP AL, 0FH
MOV si, offset ROW_0 JE KEYP
JMP COL_ID MOV si, offset ROW_3
ROW1: MOV al, 0FDH ;; KEY IDENTIFICATION
OUT PA, AL COL_ID: SHR AL, 1
IN AL, PB JNC FOUND
And AL, 0FH INC SI
The Assembly Language Program(ALP): CMP AL, 0FH
JMP COL_ID
; Control Word: 1000 X010 = 82 H/ 8AH Start: MOV AL, 00 H JE ROW2
FOUND: MOV AL, [si]
.model small OUT PA, AL MOV si, offset ROW_1
MOV KEY, AL
ROW_0 DB 0 , 1, 2, 3 KEYP: IN AL, PB JMP COL_ID
OUT PC, AL
ROW_1 DB 4 , 5, 6, 7 and AL, OFH ROW2: MOV al, 0FBH JMP Start
ROW_2 DB 8 , 9, 0AH, 0BH cmp AL, 0FH; OUT PA, AL
ROW_3 DB 0CH , 0DH, 0EH, 0FH JE KEYP IN AL, PB Delay: MOV CX, 2730
KEY DB ? Call Delay; debouncing time = 10 ms And AL, 0FH L: DEC CX
.CODE IN AL, PB CMP AL, 0FH JNZ L
MOV AL, 82H AND AL, 0FH JE ROW3 RET
OUT CR, AL CMP AL, 0FH MOV si, offset ROW_2 END
JE KEYP JMP COL_ID
INTERFACING DIGITAL TO ANALOG CONVERTERS
The digital to analog converters convert binary number into their Triangular Wave Generation:
equivalent voltages. The DAC find applications in areas like PROGRAM:
digitally controlled gains, motors speed controls, programmable .model small
gain amplifiers etc. • DAC0800 is a 8-bit Multiplying DAC : This is MOV AL, 80H; Control Word
a 16 pin DIP, multiplying digital to analog converter, containing R-
OUT CR, AL ; CR is a variable for Control register address
2R ladder for D-A conversion along with single pole double
MOV AL, 00H
thrown NMOS switches to connect the digital inputs to the
L1: OUT PB, AL ; PB is a variable for Port-B address
ladder.
INC AL
CMP AL, FFH
JNZ L1
L2: OUT PB, AL
DEC AL
JNZ L2
JMP L1
END
Interfacing Analog to Digital Converter
Use port A of 8255 for transferring digital data output of ADC to the CPU and port C for control signals. Assume that an analog
input is present at I/P2 of the ADC and a clock input of suitable frequency is available for ADC.
• Solution:
The analog input I/P2 is used and therefore address pins A,B,C should be 0,1,0 respectively to select I/P2. The OE and ALE
pins are already kept at +5V to select the ADC and enable the outputs. Port C upper acts as the input port to receive the EOC
signal while port C lower acts as the output port to send SOC to the ADC.
• Port A acts as a 8-bit input data port to receive the digital data output from the ADC. The 8255 control word is written as
follows: .model small
.code
Mov al, 98H; CW = 10011000 = 98H
OUT CR, al
Mov al, 02H; to select I/P2
Out PB, al
Mov al, 00H ; to give Start of Conversion pulse
Out PC, al; initiating the SOC pulse.
Mov al, 01H; to give Start of Conversion pulse
Out PC, al; generating another SOC pulse.
Mov al, 00H
Out PC, al; resetting the SOC pulse.
Wait: IN AL, PC
ROL AL, 1
JNC Wait
IN AL, PA
END
Isolated I/O : 64 Parallel Output lines
Isolated I/O : 64 Output lines
Isolated I/O : 64 Output lines
Handshaking Mode: when one
device sends a message to
another device indicating that it
wants to establish a
communications channel. The two
devices then send several
messages back and forth that
enable them to agree on a
communications protocol. In
computer or memory
technology, a strobe is
a signal that is sent that
validates data or other signals
on adjacent parallel lines.
Data transfers can only take place if the printer is
Ready to accept data. Printer readiness is indicated
by status line, like BUSY.
MPU outputs data on data bus D0-D7. The 𝑆𝑇𝐵
signal is used to inform the printer that new data
are available. If printer is busy on doing job, it sends
BUSY signal for wait.
Program: For example a string of data are save at TABLE. Number of data is N.
Read the data from memory and Send them to printer with handshake mode.
MOV SI, OFFSET TABLE
MOV CX, N
BUSY: MOV DX, 8004H
IN AL, DX
AND AL, O1H
JNZ BUSY ; keep polling till BUSY = 0
CLD ; clear DF
LODSB
MOV DX, 8000H
OUT DX, AL

MOV AL, 00H; generate low STROBE signal


MOV DX, 8001H
OUT DX, AL
DELAY: MOV BX, 0FH; delay for low STROBE signal duration
DEC BX
JNZ DELAY
MOV AL, 01H; generate high STROBE signal
OUT DX, AL
LOOP BUSY
END
Programming the 82C55: Mode 1

Mode 1 – Handshake I/O mode or strobed I/O mode. In this mode either port A or port B can work as
simple input port or simple output port, and port C bits are used for handshake signals before actual
data transmission. It has interrupt handling capacity and input and output are latched. Example: A
CPU wants to transfer data to a printer. In this case since speed of processor is very fast as
compared to relatively slow printer, so before actual data transfer it will send handshake signals to the
printer for synchronization of the speed of the CPU and the peripherals.
Programming the 82C55: Mode 1 Strobed Input
o It causes port A and/or port B to function as latching
input devices.
o It allows external data to be stored to the port until
the microprocessor is ready to retrieve it.
o Port C is used in mode 1 operation—not for data, but
for control or handshaking signals.
o to help operate either or both port A and B as
strobed input ports
Programming the 82C55: Mode 1 Strobed Output
o The strobed output operation is similar to mode 0 output operation, except control signals are included to provide
handshaking,
o When data are written to a strobed output port, the output buffer full signal becomes logic 0 to indicate data are present
in the port latch
Programming the 82C55: Mode 1 Strobed Output
o OBF: Output buffer full goes low whenever data are
output (OUT) to the port A or B latch. The signal is set to
logic 1 when the ACK pulse returns from the external
device.
o ACK: The acknowledge signal causes the OBF pin to return
to logic 1. The ACK signal is a response from an external
device, indicating that it has received data from the 82C55
port.
o INTR: Interrupt request often interrupts the processor
when the external device receives the data via the ACK
signal. Qualified by the internal INTE (interrupt enable) bit.
o INTE: Interrupt enable is neither input nor output; it is an
internal bit programmed to enable or disable the INTR pin.
INTE A is programmed using PC6 bit. INTE B is programmed
using the PC2 bit.
Status Word for Port-C
I/O I/O IBFA STBA INTRA ACKB OBFB INTRB

.model small
.data
X DB 200 DUP(?) Print:
.code Mov si, offset X
Mov al, B4H Mov cx, N
Out FFH, al L: IN al, FEH
Mov al, 09H; BSR CW AND al, 02H
Out FFH, al JZ L
STI ; set IF Mov al, [si]
Call Keyboard Out FDH, al
Addresses and Control Word: Call Print Inc si
Port-A address: 0000 0000 1111 1100 = ; 00FC H Keyboard: Loop L
Port-B address: 00FD H Mov si, offset X END
Port-C address: 00FE H IN al, FEH
Control Register address: 00FF H AND al, 20H
Control Word: 1011 X10X = B4 H/BD H JNZ Keyboard
BSR Control Word: 0XXX 1001 = 09H for PC4 set IN al, FCH
Mov [si], al
Memory-mapped Input-Output Ports

So, Port-B of PPI-0 is selected


for memory-mapped I/O.

You might also like