11.4 8255, Keyboard, and Display Interfaces
The earlier sections built separate decoders, status registers, and handshake paths. The 8255 Programmable Peripheral Interface packages three 8-bit ports—A, B, and C—with programmable direction and operating modes. Software configures it by writing a control word.
Build an 8255 mode-set control word
When control-word bit D7 is 1, the write configures I/O modes and directions:
| Bits | Meaning |
|---|---|
| D6–D5 | Group A mode: 00 Mode 0, 01 Mode 1, 1x Mode 2 |
| D4 | Port A direction: 1 input, 0 output |
| D3 | Upper Port C direction in Mode 0 |
| D2 | Group B mode: 0 Mode 0, 1 Mode 1 |
| D1 | Port B direction: 1 input, 0 output |
| D0 | Lower Port C direction in Mode 0 |
Mode 0 provides basic latched output or simple input. Mode 1 adds strobed input or output with handshake lines assigned from Port C. Mode 2 makes Port A an 8-bit bidirectional bus with handshake control. Because handshake modes take ownership of some Port C pins, software cannot assume that all eight Port C bits remain general-purpose I/O.
When D7 is 0, the word is instead a bit set/reset (BSR) command for one Port C bit: D3…D1 choose PC0–PC7 and D0 chooses set or reset. This changes one bit without replacing the entire I/O-mode configuration.
Scan a keyboard matrix and drive a display
A keyboard matrix reduces wiring by arranging switches at row-column intersections. To find a pressed key, the interface drives one row active at a time and reads all column inputs. The active row plus the detected column identifies the key.
For a 4×4 keypad:
1. Configure four row lines as outputs and four column lines as inputs.
2. Activate row 0 and read the columns.
3. Repeat for rows 1–3.
4. Debounce a repeated result before accepting the key.
Debouncing rejects the rapid electrical make-and-break transitions produced by a mechanical contact. Without it, one physical press may appear as several presses. Multiple simultaneous keys can also create a false intersection called ghosting unless the circuit uses isolation diodes or software restrictions.
A seven-segment display uses seven individually controlled bars named a through g. A digit pattern is a bit mask: for a common-cathode display, driving a segment high turns it on. Multi-digit displays often use multiplexing, enabling one digit at a time quickly enough that human vision perceives all digits as continuously lit.
Chapter 11 connected CPU bus cycles to real peripheral behavior: address-space selection, port decoding, status polling, handshaking, buffering, programmable parallel I/O, keyboard scanning, and visible output. Chapter 12 replaces repeated polling with events that can interrupt ordinary program flow.