---
title: "8255 interface with switches and 7-segment"
subject: "Instrumentation II"
chapter: 2
key: "semester_5/instrumentation_ii:ppi-switch-sevenseg"
source: https://www.bctengineer.com/q/semester_5/instrumentation_ii/ppi-switch-sevenseg
site: BCT Engineering
---

# 8255 interface with switches and 7-segment

Instrumentation II · Chapter 2: Parallel Interfacing With Microprocessor Based System

- Asked in: 2074 Asoj, 8 marks
- Video: [Interfacing 7-Segment Display with 8086 Microprocessor by using 8255PPI](https://www.youtube.com/watch?v=gVSazQGbGc8) — NAVEEN TECHNOLOGIES
- Answer checked by Claude Sonnet 5.5 on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_5/instrumentation_ii/ppi-switch-sevenseg
- Whole chapter: https://www.bctengineer.com/md/semester_5/instrumentation_ii/chapter-2

## Question

A microprocessor kit has an onboard 8255. Interface to the 8255 eight single-pole-double-throw (SPDT) switches numbered S0 to S7 and a seven segment common anode LED display. Draw the complete circuit setup. Define clearly the functions of all ports, write a program to initialize 8255, detect a switch closure, and display the value of the switch number on the LED display.

## Short answer

Port A outputs segment codes to a common-anode 7-segment display, port B reads eight SPDT switches (closure gives 0). The 8255 is initialised with control word 82H. The program polls port B, complements the bits, rotates right to find the switch number, and outputs the corresponding code from a table: C0H, F9H, A4H, B0H, 99H, 92H, 82H, F8H for 0–7.

## Answer

#### Assumptions
8085 kit with the 8255 I/O-mapped at **80H-83H**: Port A = 80H, Port B = 81H, Port C = 82H, Control = 83H (A1 and A0 select the register; CS' comes from a decoder of A7-A2, selected when A7 = 1 and A6-A2 = 0). A switch is called "closed" when it is thrown to the GND side.

#### Circuit
```text
 Each SPDT switch Sn: one throw -> +5 V, other throw -> GND,
 common terminal -> PBn   (S0 -> PB0, S1 -> PB1, ... S7 -> PB7)

 PA0..PA6 --[330 ohm each]--> segments a..g of the common anode display
 Common anode pin ----------> +5 V

 8255: D0-D7 <-> AD0-AD7, RD', WR', A0, A1 from the 8085,
       RESET <- RESET OUT, CS' <- address decoder
```
A segment glows when its port pin is **0** (common anode).

#### Port functions
| Port | Mode | Direction | Function |
|---|---|---|---|
| A | 0 | Output | 7-segment code (PA0=a ... PA6=g, PA7=dp) |
| B | 0 | Input | Switches S0-S7 (+5 V side reads 1, closed (GND) side reads 0) |
| C | - | Unused | - |

Control word: D7=1 (mode set), A mode 0, A output, C upper output, B mode 0, B input, C lower output = 1000 0010 = **82H**.

#### Display codes (common anode, dp off)
0 = C0H, 1 = F9H, 2 = A4H, 3 = B0H, 4 = 99H, 5 = 92H, 6 = 82H, 7 = F8H.

#### Program
```text
        MVI A,82H
        OUT 83H        ; initialise 8255
START:  IN 81H         ; read switches
        CMA            ; closed switch becomes 1
        ORA A          ; set flags, clear carry
        JZ START       ; no switch closed
        MVI C,00H      ; C = switch number
NEXT:   RAR            ; shift lowest bit into carry
        JC FOUND
        INR C
        JMP NEXT
FOUND:  LXI H,TABLE
        MVI B,00H
        DAD B          ; HL = TABLE + number
        MOV A,M        ; get 7-segment code
        OUT 80H        ; display switch number
        JMP START
TABLE:  DB C0H,F9H,A4H,B0H,99H,92H,82H,F8H
```
Example: if S3 is closed, the port reads 1111 0111. After CMA it is 0000 1000. The first three RAR instructions leave carry = 0 (each is followed by INR C), and the fourth sets carry, so C = 3 and the code B0H shows "3". If more than one switch is closed, the lowest-numbered one is displayed.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What control word sets port A output, port B input in mode 0 with port C outputs?
   A. 82H
   B. 92H
   C. 80H
   D. 8BH
   Answer: A. D7=1, A out, B in, C out gives 1000 0010 = 82H. (Key point: Control word)

2. How does a segment glow on a common anode display?
   A. When its port pin is 1
   B. When its port pin is 0
   C. When port C is 1
   D. When pin is floating
   Answer: B. The common anode is at +5 V, so a low pin sinks current. (Key point: Common anode)

3. What is the common anode code for digit 3?
   A. B0H
   B. A4H
   C. F9H
   D. 99H
   Answer: A. Digit 3 = B0H in the table. (Key point: Display code)

4. Why is CMA used after reading the switches?
   A. A closed switch reads 0, so CMA makes it 1 to detect with RAR
   B. To clear the accumulator
   C. To enable interrupts
   D. To select the 7-segment table
   Answer: A. Inversion makes the closed switch a 1 bit. (Key point: Switch detection)

## Related in Instrumentation II

- [8255 mode 0 DIP switches and LEDs](https://www.bctengineer.com/question.md?key=semester_5%2Finstrumentation_ii%3Appi-mode0-dip-leds) — Instrumentation II, chapter 2
- [8-channel ADC interface with 8255 and 8085](https://www.bctengineer.com/question.md?key=semester_5%2Finstrumentation_ii%3Aadc8-8255-problem) — Instrumentation II, chapter 4
- [8255 at A0A0H: interface and control words](https://www.bctengineer.com/question.md?key=semester_5%2Finstrumentation_ii%3Appi-a0a0h-control-words) — Instrumentation II, chapter 2
- [Double handshake data transfer with 8255-PPI](https://www.bctengineer.com/question.md?key=semester_5%2Finstrumentation_ii%3Adouble-handshake-8255) — Instrumentation II, chapter 2
- [PCI bus; 8255 printer interface at 5500H](https://www.bctengineer.com/question.md?key=semester_5%2Finstrumentation_ii%3Apci-printer-5500h) — Instrumentation II, chapter 2
- [Keyboard and printer interface in 8255 mode 1](https://www.bctengineer.com/question.md?key=semester_5%2Finstrumentation_ii%3Akeyboard-printer-mode1) — Instrumentation II, chapter 2

## Related in other subjects

- [Display 99 to 00 on seven segment](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3A8051-seven-segment-99-00) — Embedded System, chapter 9
- [Seven segment display and clock counter](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3Aseven-segment-clock-design) — Embedded System, chapter 9
- [Display 0 to 9 on seven segment](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3A8051-seven-segment-0-9) — Embedded System, chapter 9, asked 2×
- [DEMUX vs decoder; seven-segment "b" segment](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3Ademux-decoder-b-segment) — Digital Logic, chapter 4
