Lesson 39 of 48 intermediate

8255 Programmable Peripheral Interface

The Universal Parallel I/O Chip

Open interactive version (quiz + challenge)

Real-world analogy

The 8255 is like a receptionist with three desks (Port A, Port B, Port C). You hand the receptionist a note (control word) that says 'Desk A takes incoming calls, Desk B sends outgoing mail, Desk C does both.' From then on, each desk follows its assigned role. You can even change the note mid-day to reassign everyone — that is what 'programmable' means.

What is it?

The 8255 PPI is a programmable parallel I/O chip that provides 24 I/O lines organized as three 8-bit ports (A, B, C). It supports three operating modes: Mode 0 (simple I/O), Mode 1 (strobed I/O with handshaking), and Mode 2 (bidirectional bus on Port A). A control word written to its control register configures port directions and modes. BSR mode allows individual Port C bits to be set or reset.

Real-world relevance

The 8255 was used in the original IBM PC to interface the keyboard, read DIP switch settings, and control the speaker. Many university microprocessor lab kits still include the 8255 for hands-on experiments. The concept of programmable I/O ports lives on in modern microcontrollers — every GPIO port on an Arduino or STM32 is a descendant of the 8255's design philosophy.

Key points

Code example

; =============================================
; 8255 PPI — Complete Configuration Example
; =============================================
;
; System: 8255 at I/O base 80h
;   Port A (80h) → Output to LEDs
;   Port B (81h) → Input from DIP switches
;   Port C (82h) → Mixed control signals
;   Control (83h)
;
; Step 1: Configure 8255
; Control word: Mode 0, PA=out, PB=in,
;              PCupper=out, PClower=in
; Bits: 1 00 0 0 0 1 1 = 83h
;
  MOV AL, 83h           ; control word
  OUT 83h, AL           ; write to control register
;
; Step 2: Read DIP switches (Port B)
  IN AL, 81h            ; AL = switch pattern
;
; Step 3: Process and display
  NOT AL                ; invert pattern
  OUT 80h, AL           ; write to LEDs (Port A)
;
; Step 4: Set a flag on Port C bit 0
  MOV AL, 01h           ; BSR: set PC0
  OUT 83h, AL           ; PC0 = 1 (flag active)
;
; Step 5: Read Port C lower nibble
  IN AL, 82h            ; read all of Port C
  AND AL, 0Fh           ; mask upper nibble
;
; Loop: continuously read switches, update LEDs
SCAN:
  IN AL, 81h            ; read switches
  OUT 80h, AL           ; mirror to LEDs
  JMP SCAN              ; repeat forever

Line-by-line walkthrough

  1. 1. Title comment for 8255 configuration example
  2. 2. Separator line
  3. 3. Blank line
  4. 4. System description: 8255 base address is 80h
  5. 5. Port A at address 80h is configured as output driving LEDs
  6. 6. Port B at address 81h is configured as input reading DIP switches
  7. 7. Port C at address 82h provides mixed control signals
  8. 8. Control register is at address 83h
  9. 9. Blank line
  10. 10. Step 1: Configure the 8255 by writing the control word
  11. 11. Control word breakdown: Mode 0 for all, PA=out, PB=in, PCu=out, PCl=in
  12. 12. Binary: 10000011 = 83h
  13. 13. Blank line
  14. 14. Load control word 83h into AL register
  15. 15. Write AL to control register at port 83h — 8255 is now configured
  16. 16. Blank line
  17. 17. Step 2: Read the DIP switch positions from Port B
  18. 18. IN instruction reads 8 switch bits into AL
  19. 19. Blank line
  20. 20. Step 3: Process the data and send to display
  21. 21. NOT inverts all bits — turns switch pattern into LED pattern
  22. 22. OUT sends the inverted pattern to Port A LEDs
  23. 23. Blank line
  24. 24. Step 4: Use BSR mode to set a flag on Port C
  25. 25. Value 01h in BSR format: bit7=0, bit select=000, set=1 → sets PC0
  26. 26. Writing to control register with bit7=0 triggers BSR mode
  27. 27. Blank line
  28. 28. Step 5: Read Port C and isolate lower nibble
  29. 29. IN reads all 8 bits of Port C
  30. 30. AND with 0Fh masks off the upper 4 bits, keeping only PC0-PC3
  31. 31. Blank line
  32. 32. Label SCAN for continuous polling loop
  33. 33. Read current switch states from Port B
  34. 34. Write switch states directly to LEDs on Port A
  35. 35. Jump back to SCAN — infinite loop mirrors switches to LEDs

Spot the bug

; Configure 8255 at base 80h:
;   Port A = input, Port B = output, Mode 0
;
  MOV AL, 90h          ; control word
  OUT 80h, AL          ; send to control register
;
; Read from Port A:
  IN AL, 80h
;
; Write to Port B:
  MOV AL, 55h
  OUT 81h, AL
Need a hint?
Where should the control word be written? Check the address for the control register.
Show answer
The control word is written to port 80h (Port A address) instead of port 83h (Control Register address). The 8255 control register is always at base+3. Fix: change 'OUT 80h, AL' to 'OUT 83h, AL'. Writing 90h to port 80h would send data to Port A instead of configuring the chip.

Explain like I'm 5

Imagine you have a magical switchboard with three rows of switches (Port A, B, C). You write a little instruction card (control word) telling the switchboard: 'Row A sends signals OUT, Row B listens for signals IN, Row C does a mix.' The switchboard follows your card. If you want to change what a row does, just write a new card. That is the 8255 — a switchboard you can reprogram anytime!

Fun fact

The 8255 was so popular that clone versions were made by dozens of manufacturers worldwide. NEC made the uPD8255, Mitsubishi made the M5L8255, and even Soviet-era factories produced the KR580VV55 — a pin-compatible clone. The 8255 design pattern was so influential that its mode concept (simple/strobed/bidirectional) appears in virtually every modern microcontroller's GPIO peripheral.

Hands-on challenge

Configure an 8255 at base address 60h with Port A as Mode 1 input (strobed), Port B as Mode 0 output, and Port C used for handshaking. Write the control word bit by bit, then write assembly code to wait for IBF, read Port A, and display the data on Port B LEDs.

More resources

Open interactive version (quiz + challenge) ← Back to course: Microprocessor A–Z