Digital Logic & Microprocessor — Microprocessor System, NEC licence examination syllabus (Nepal Engineering Council).
The 8255 PPI: three ports you can configure
A general-purpose I/O chip — because hard-wiring every peripheral would be madness.
A processor needs to talk to keyboards, displays, motors, sensors — each with different requirements. Building custom interface logic for every one is impractical, so Intel made a programmable chip: three 8-bit ports whose direction and behaviour you set in software by writing a control byte. The 8255 became so standard that its programming model is still worth knowing.
Internal structure
Three 8-bit ports plus a control register:
PORT A — 8 bits, most flexible (all three modes)
PORT B — 8 bits (modes 0 and 1 only)
PORT C — 8 bits, splittable into two 4-bit halves
(C upper: PC7–PC4, C lower: PC3–PC0)
Often used for handshaking signals
CONTROL REGISTER — 8 bits, sets everything
Addressing (A1, A0 select which register):
A1 A0 | Selected
──────┼──────────
0 0 | Port A
0 1 | Port B
1 0 | Port C
1 1 | Control register
Total: 24 I/O lines from one 40-pin chip.
The three operating modes
🔧 Mode 0, 1 and 2
Mode 0Simple I/O. Ports are plain inputs or outputs with no handshaking. Outputs are latched; inputs are not. Used for LEDs, switches, relays — anything that doesn't need timing coordination.
Mode 1Strobed I/O with handshaking. Port C supplies control signals (STB, IBF, ACK, OBF) so the peripheral and processor can coordinate. Used for printers, keyboards.
Mode 2Bidirectional — Port A only. The same 8 lines both send and receive, with Port C handling the handshaking. Used for two-way links between processors.
The control word format
Bit 7 = 1 selects MODE-SET format (0 selects bit set/reset)
D7 D6 D5 D4 D3 D2 D1 D0
1 |mode A |PA |PCU | modeB|PB |PCL
D7 = 1 (mode set flag)
D6,D5 = Port A mode (00=mode0, 01=mode1, 1X=mode2)
D4 = Port A direction (1 = input, 0 = output)
D3 = Port C upper (1 = input, 0 = output)
D2 = Port B mode (0 = mode0, 1 = mode1)
D1 = Port B direction (1 = input, 0 = output)
D0 = Port C lower (1 = input, 0 = output)
Mnemonic for the direction bits: 1 = In, 0 = Out.
The direction convention catches people out: 1 means input, 0 means output. It feels backwards because we usually think of output first. Write "1 = In" at the top of your answer before decoding any control word, and you'll avoid inverting the whole answer.
Worked numerical 1 — deriving a control word
Configure the 8255 with Port A as output, Port B as input, Port C upper as output, Port C lower as input, all in mode 0. Find the control word.
D7 = 1 (mode set)
D6 D5 = 00 (Port A mode 0)
D4 = 0 (Port A OUTPUT)
D3 = 0 (Port C upper OUTPUT)
D2 = 0 (Port B mode 0)
D1 = 1 (Port B INPUT)
D0 = 1 (Port C lower INPUT)
Control word = 1 00 0 0 0 1 1 = 1000 0011 = 83H
Initialisation code (control register at port 83H,
Port A at 80H, Port B at 81H, Port C at 82H):
MVI A, 83H ; the control word
OUT 83H ; write it to the control register
IN 81H ; read Port B (input)
OUT 80H ; echo it to Port A (output)
HLT
Worked numerical 2 — decoding a control word
An 8255 receives control word 98H. Determine the configuration of all ports.
98H = 1001 1000
D7 = 1 → mode set format ✔
D6 D5 = 00 → Port A in mode 0
D4 = 1 → Port A is INPUT
D3 = 1 → Port C upper is INPUT
D2 = 0 → Port B in mode 0
D1 = 0 → Port B is OUTPUT
D0 = 0 → Port C lower is OUTPUT
Summary:
Port A : input, mode 0
Port B : output, mode 0
Port C upper : input
Port C lower : output
A plausible use: read 8 switches on Port A, drive 8 LEDs on
Port B, read 4 more switches on C upper, drive 4 relays on
C lower. Twelve inputs and twelve outputs from one chip.
Worked numerical 3 — bit set/reset mode
Set bit PC3 of Port C without disturbing the other bits, then reset PC5.
BSR (Bit Set/Reset) mode uses D7 = 0:
D7 D6 D5 D4 D3 D2 D1 D0
0 | unused | bit select | S/R
D3,D2,D1 = which bit of Port C (000 to 111)
D0 = 1 to SET, 0 to RESET
To SET PC3:
D7 = 0
D3 D2 D1 = 011 (bit 3)
D0 = 1 (set)
word = 0 000 011 1 = 0000 0111 = 07H
To RESET PC5:
D3 D2 D1 = 101 (bit 5)
D0 = 0 (reset)
word = 0 000 101 0 = 0000 1010 = 0AH
Code:
MVI A, 07H
OUT 83H ; set PC3
MVI A, 0AH
OUT 83H ; reset PC5
Why this mode exists: without it, changing one bit means
reading the port, masking, and writing back — three
instructions and a race condition. BSR does it atomically
in one write, which matters when Port C carries handshake
or control signals.
💡 Exam angle: control-word calculation in both directions (given a configuration find the word; given the word find the configuration) is the guaranteed question. Draw the bit-format diagram first, then fill it in. Remember 1 = input, and that D7 chooses between mode-set (1) and bit-set/reset (0). Naming the three modes with one application each covers the descriptive marks.
Syllabus points
8255 PPI; modes of operation
Create a free account to tick topics off, take notes as you read, watch the video lessons and get a day-by-day study plan built around your exam date.