Intel 8255
Programmable Peripheral Interface
Handshaking
o Handshaking is a method used for synchronized communication
between a processor and peripherals to ensure data is exchanged
reliably
o In a larger context, handshaking happens when two modules
communicate with each other for reliable data transfer
o For very simple IO devices such as push button or LEDs such
handshaking is not required
2
ADC
o Till now we assumed an ADC model when converts analog data to
digital format instantaneously
o But practically ADC takes some amount of time for this conversion
(that decides the max. ADC sampling rate such as 1Mbps ADC)
o If the processor blindly reads from the ADC, it might be an invalid
data since ADC might be in the middle of a conversion
o So, communication goes some thing like this
CPU : Hey ADC I want a fresh input data so better you start a
conversion
A few moments later…
ADC : OK I am done with the conversion and data is ready 3
Then processor reads it
ADC
Start input from processor
End of conversion indication
4
Keyboard
o When you type a key on a keyboard, it gets stored in a small buffer
(memory) in the keyboard
o Then it should indicate to the processor that it has a data to
transfer
o The processor should indicate when it is ready to accept this data
o Once both parties are ready, the data transfer occurs
o Modern keyboards can buffer from 6-keys to 256-keys
o So, if you press Ctrl+Alt+Del, it will buffer 3 keys and indicate it has
data
o It will keep on indicating it has data until all 3 key information are
read 5
Why PPI?
o 8086 is not very efficient in the hand-shaking schemes we
discussed
o The READY signal that we discussed during machine cycles is a
kind of handshaking
o As we have seen handshaking involves multiple discrete control
signals
o If we want to interface these signals to 8086, we will have to do it
though the data bus
o And an address decoding circuit to access these discrete signals!!
o This is mainly because 8086 does not have built-in ports like many
other micro-controllers
6
o It is also not capable of bit-level control of its data bus
8255 Programmable Peripheral Interface (PPI)
o Intel introduced 8255 PPI for interfacing with peripherals
supporting different kinds of hand-shaking (also without
handshaking)
o Processor views 8255 as a peripheral and accesses it as a
memory (if memory mapped) or IO device (if IO mapped)
o It acts as a bridge (glue logic) between peripherals and processor
o It comes in a 40-pin dip package and has 3 ports
o The ports can be programmed as input or output (through software
running on a processor)
o The ports can be programmed to support different hand-shaking
schemes (through software running on a processor)
7
o Hence the name Programmable peripheral interface
8255 Overview
Port A
Port C
Port B
8
8255 Overview
Address input to select a Port
(Will get connected to address
bus of processor)
A1 A0 Port
Selected
0 0 Port A
0 1 Port B
1 0 Port C
1 1 Control Reg.
9
8255 Overview
Chip select of 8255. Should
be connected to address
decoder
10
8255 Overview
Connected to Data bus of processor
11
8255 Overview
Active low read and write enable
signals. Should be connected to IORD’
and IOWR’ or MEMRD’ and MEMWR’
depending on whether 8255 is
memory mapped or IO mapped to the
processor
12
8255 Overview
Active high reset. Upon reset, all 8255
ports are configured as input ports (high-
impedance state)
13
Example 1
o An 8255 is IO mapped to address 50H. Draw the interfacing
diagram. Determine the address mapping of each port from
processor perspective. What is the IO address range of 8255. If
8255 is IO mapped to address 51H, what is the IO address range
14
Case: 1
o An 8255 is IO mapped to address 50H. Port A is connected to 8
slide switches and Port B is connected to 8 LEDs. Write a program
to reflect the switch status using the LEDs
In this case there are no handshaking
Since LEDs are output devices, you need to configure Port B as
output port
Since switches are input, you need to configure Port A as input
In a loop, continuously read from Port A then write to Port B
15
Case: 1
A1:A0
Addr bus Addr
Decode CS’ PB
r
8086 8255
Data bus
P
A
16
8255 Control Word Register
o 8255 has an internal register that sets the direction (input/output)
and the mode (different handshaking) of different ports
D7 D6 D5 D4 D3 D2 D1 D0
Mode set flag Port A Port C [3:0]
(Active 1) 1= Input 1= Input
0= Output 0= Output
Port C [7:4] Port B
1= Input 1= Input
0= Output 0= Output
o Bits 2,5 and 6 decides the handshaking. Since no handshaking,
17
Case: 1
.MODEL TINY
.DATA
.CODE
PortA EQU 50H ; Port A address
PortB EQU 51H ; Port B address
Control EQU 53H ; Control reg address
MOV AL, 90H; Configure 8255: PA input, PB output
OUT Control, AL ; Send control word to 8255
MAIN_LOOP:
IN AL, PortA ; Read switch status from Port A
OUT PortB, AL ; Output switch status to LEDs
JMP MAIN_LOOP ; Repeat indefinitely
.EXIT
END 18
Modes of Operation
19
Bit Set/Reset (BSR) Mode
o Only supported by Port C
o Allows individually set and reset Port C pins
o Allows bit-wise control of devices like LEDs and relays without
affecting the entire port
o Port C need not be explicitly configured as output port when using
this mode
20
Control Word for BSR
D7 D6 D5 D4 D3 D2 D1 D0
BSR Mode
1= Set
(Active 0)
Not Used 0= Reset
Bit Select
o Eg : 0000 0110B (06H) Reset PC.3
0000 1011B (0BH) Set PC.5
o Using a BSR control word does not affect mode settings done
using a prior non-BSR control word
21
Example
o An 8255 PPI is interfaced with an 8086 microprocessor with IO address 300H.
Its PC.1 is connected to a green LED which blinks to indicate system is active
with 0.5 sec delay. PC.2 is connected to push button. Write the ALP
.MODEL TINY DELAY: ;0.5 is 7A120H us
.DATA mov CX, 7
.CODE mov DX, 0A120H
PortC EQU 302H ; mov ah, 86h
Control EQU 303H ; Control reg address int 15h
mov DX, Control ; 8255 Control Register ret
MAIN_LOOP: END
mov AL, 02H ; BSR Mode: 0000 0010 → Clear PC1
out DX, AL ; Send control word to 8255
call DELAY ; Call delay of 0.5 sec
mov AL, 03H ; BSR Mode: 0000 0011 → Set PC1
out DX, AL ; Send control word to 8255
call DELAY ; Call delay of 0.5 sec
jmp MAIN_LOOP ; Repeat blinking 22
Input Output Modes
o 8255 supports 3 input/output modes; mode0, mode1 and mode2
o Based on the ports which are part of different modes, they are
grouped into 2, Group A and Group B
o Group A consists of Port A and Upper nibble of Port C
o Group B consists of Port B and Lower nibble of Port C
23
Control Word for Mode and Direction Selection
24
Mode0 (Basic I/O mode)
o Supported by Port A, Port B and Port C
o No handshaking is involved
o The outputs are latched but the inputs are buffered but not latched,
ie. data coming from processor is internally latched before
outputting through the pin when the port is configured as output
port
o If the port is configured as input port, data coming from the pins is
directly connected to the processor bus.
o Thus, as a designer, we need to make sure the data is valid and
does not glitch during data transfer
o The first example discussed using LEDs and Slide switches is an
example for Mode0 operation 25
Mode1 (Handshake or strobed I/O)
o Supported by Port A and Port B. Port C signals are used for
handshaking
o The outputs and inputs are latched
o It is possible that Port A operates in Mode 1 and Port B operates in
Mode 0
26
Mode1 Input Handshaking (Processor reading from input Device)
27
Mode1 Input Handshaking (Processor reading from input Device)
o STB ( active low ) goes low.
o IBF goes high.
o INTR goes high.
o RD ( active low ) goes low.
o INTR goes low.
o RD ( active low ) goes high.
o IBF goes low.
28
Mode1 Input Handshaking
STB’
DATA
From
Peripheral
IBF
INT
RD’
DATA
To
Processor 29
Mode1 Output Handshaking (Processor writing to output Device)
30
Mode1 Output Handshaking (Processor writing to output Device)
o WR signal is activated.
o INTR is set to low. [ now 8086 cannot send data again ]
o OBF goes low [ Output buffer is full ]
o ACK goes low ( it is active low signal )
o OBF goes back to high
o ACK goes back to high
o Data transfer is successful, so INTR goes back to high.
31
Mode1 Input Handshaking
WR’
DATA
From
Processor
OBF’
INT
ACK’
DATA
To
Peripheral 32
Control Signals
For Port A Mode 1 Input
• PC3: INTR (Interrupt Request) – Output signal to indicate that
data is ready for input or output.
• PC4: STB’ (Strobe Input) – Input signal to latch data into Port
A.
• PC5: IBF (Input Buffer Full) – Output signal to indicate that
data has been latched into Port A.
For Port B in Mode 1 Input:
• PC0: INTR (Interrupt Request) – Output signal to indicate that
data is ready for input or output.
• PC2: STB’ (Strobe Input) – Input signal to latch data into Port
B.
33
• PC1: IBF (Input Buffer Full) – Output signal to indicate that
Control Signals
For Port A Mode 1 Output
• PC3: INTR (Interrupt Request) – Output signal to indicate that
data is ready for input or output.
• PC6: ACK’ (Acknowledge Input) – Input signal to indicate
peripheral accepted data
• PC7: OBF ’(Output Buffer Full) – Output signal to indicate that
data is available on Port A.
For Port B in Mode 1 Output:
• PC0: INTR (Interrupt Request) – Output signal to indicate that
data is ready for input or output.
• PC2: ACK’ (Acknowledge Input) Input signal to indicate
peripheral accepted data
• PC1: OBF’ (Output Buffer Full) – Output signal to indicate that34
Mode2 (Bidirectional Handshaking)
o Supported only by Port A.
o Port C signals are used for handshaking
o The outputs and inputs are latched
o It is possible that Port A operates in Mode 2 and Port B operates in
Mode 0 or Mode 1
35
Control Signals
For Port A Mode 2
• PC3: INTR (Interrupt Request) – Output signal to
indicate that data is ready for input or output.
• PC6: ACK’ (Acknowledge Input) – Input signal to
indicate peripheral accepted data
• PC7: OBF ’(Output Buffer Full) – Output signal to
indicate that data is available on Port A.
• PC4: STB’ (Strobe Input) – Input signal to latch
data into Port A
• PC5: IBF (Input Buffer Full) – Output signal to 36
indicate that data has been latched into Port A
Case 1
8086 is interfaced with a dot matrix printer using a
parallel port through 8255 mapped to IO address 50H.
Write an ALP to print “hello world” using the printer
37
Case 1
.MODEL TINY
.DATA
MESSAGE DB 'hello world$’
.CODE
START:
MOV AL, 10100000B ; Control word: Port A in Mode 1, Port B in
Mode 0, Port C upper as output
OUT 53H, AL ; Send control word to 8255 control register
LEA SI, MESSAGE ; SI points to the start of the message
PRINT_LOOP:
MOV AL, [SI] ; Load character from memory into AL
CMP AL, ‘$’ ; Check end of string
JE DONE ; If null terminator, exit loop
; Send the character to the printer via Port A 38
OUT 50H, AL ; Send character to Port A (printer data port)
Case 1
WAIT_ACK:
IN AL, 52H ; Read Port C status
AND AL, 01000000B ; Check if ACK (PC6) is low
JNZ WAIT_ACK ; If ACK is low, keep waiting
INC SI ; Increment SI to point to the next
character
JMP PRINT_LOOP ; Repeat for the next character
DONE:
MOV AH, 4CH ; DOS interrupt to exit program
INT 21H
END START
39
40