Neven's Electronics Page

ZX Spectrum 24-lines Input/Output Interface

This is a simple I/O interface for ZX Spectrum 16/48k with 24 inputs/outputs and with RESET key. It can be used for home automation, controlling a robot, connecting some homemade peripherals to a Spectrum computer and other interesting stuff.

This interface DOES NOT utilize the complete address decoding and PIO chip is accessed at every odd address (but who cares, since Sinclair did the same thing with ULA chip in ZX Spectrum which is accessed at every even address). It didn't seem that important to me to put some more logic gates to decode all eight address lines, and in case of a boo-boo you have those 470 ohm resistors anyway, so there will be no smoke.

circuit diagram

circuit diagram

The circuit itself is fairly simple, not much to say about that. It takes power from +9V pins and stabilizes it to +5V with it's own 7805 voltage regulator IC, rather than just using +5V from already very strained 7805 chip inside the Spectrum. Two NAND gates from 74LS00 are used for incomplete address decoding for accesing the 8255 PIO chip. The only other thing worth mentioning is the RESET key which will reset your Spectrum so you won't have to unplug the power then plug it in again as before.

Inputs and outputs are taken directly from the PIO chip. They are standard 5V TTL. You can use transistors as buffers to drive loads that require higher currents/voltages, relays, triacs and other. The safest method would be to use optocouplers.

8255 PIO chip has three I/O ports, PORT A, PORT B and PORT C, every one of them with 8 I/O lines. You can program PIO chip to define which ports will be inputs and which will be outputs. PORT C can be all 8 lines outputs, all 8 lines inputs or 4 lines inputs and other 4 lines outputs. To program PIO chip you send a byte that defines ports to a particular address. That byte looks like this:

Bit 7: 1 Bit 6: 0 Bit 5: 0 Bit 4: PORT A (0=output, 1=input) Bit 3: PORT C upper nibble (0=output, 1=input) Bit 2: 0 Bit 1: PORT B (0=output, 1=input) Bit 0: PORT C lower nibble (0=output, 1=input)

Recommended address is $27 hex (decimal 39).
Other addresses are:
$21 hex (decimal 33) for PIO PORT A
$23 hex (decimal 35) for PIO PORT B
$25 hex (decimal 37) for PIO PORT C

So, if you want PORT A to be output, and PORT B and PORT C to be inputs, from BASIC you would send the following configuration word: 10001011 binary or 139 decimal.

OUT 39,139

9 is address for PIO configuration, 139 is binary 10001011, ie. configuration word for the above combination of inputs/outputs.
Now, if you want to read PORT B you would type:

LET A = IN 35

and that would put in the variable A binary representations of logic states at pins of PORT B.
If you want to activate output on PORT A, say line 0 and line 1 to be logic "1" (+5V) and lines 2 to 7 to be logic "0" (0V) you would type:

OUT 33,3

because decimal 3 is binary 00000011, and 33 is address of PORT A.

To the top of the page Back to the home page

Projects list:

Valid XHTML 1.0 Strict Valid CSS!