Skip to main content

8255 mode 0 DIP switches and LEDs

Short answer

Port A=8000H, B=8001H, C=8002H, Control=8003H (A15=1). Control word 83H sets A and C upper output, B and C lower input. Program reads port B switches, outputs to port A LEDs; reads port C lower switches, rotates to upper nibble, masks F0H, outputs to port C upper LEDs.

8255 is to be operated in mode 0. Port A and port C upper are designed as output for LEDs and port B and port C lower as input ports for DIP switches. Address line A15 is connected with CS of 8255 through an inverter. (a) Draw the complete mapping diagram. (b) Determine the port addresses. (c) Determine the control word. (d) Write a program to read the DIP switches and display the reading from port B at port A and C lower at port C upper.

(a) Mapping diagram (memory mapped, 8085)

A15 is connected to CS' through an inverter, so the 8255 is selected when A15 = 1; other lines A14-A2 are not decoded (partial decoding). A1, A0 select the registers.

 A15 --[NOT]--> CS'
 A1 -> A1, A0 -> A0, RD' -> RD', WR' -> WR', RESET OUT -> RESET
 AD0-AD7 -> D0-D7
 PA0-PA7 -> 8 LEDs      PC4-PC7 -> 4 LEDs
 PB0-PB7 <- 8 DIP switches   PC0-PC3 <- 4 DIP switches

(b) Port addresses

With unused lines taken as 0: Port A = 8000H, Port B = 8001H, Port C = 8002H, Control = 8003H (images exist at every address with A15 = 1).

(c) Control word

Port A out (D4 = 0), C upper out (D3 = 0), B in (D1 = 1), C lower in (D0 = 1), mode 0 (D6 D5 D2 = 0), D7 = 1: 1000 0011 = 83H.

(d) Program

        MVI A,83H
        STA 8003H       ; initialise 8255
LOOP:   LDA 8001H       ; read DIP switches of port B
        STA 8000H       ; display on port A LEDs
        LDA 8002H       ; read port C (lower nibble = switches)
        RLC
        RLC
        RLC
        RLC             ; move lower nibble to upper nibble
        ANI F0H         ; clear lower nibble
        STA 8002H       ; display on port C upper LEDs
        JMP LOOP

Writing to the lower half of port C has no effect because it is an input, so only the upper LEDs change.

✓ Answer checked by Claude Sonnet 5.5

All Instrumentation II chapter 2 questions →