PICs in Space
This page describes how to build a ’Space Invaders‘-type game with a total component cost of just a couple of pounds.
The circuit diagram is shown to the right. You can get a larger version or a PostScript version if you prefer. The design is based around a Microchip PIC16F628A microcontroller. At the time of writing, this device is available for less than one pound from (among others) Crownhill Associates. All the work, including colour video and synchronisation signal generation, is done in the microcontroller, and so there are no other active components. Purists who contend that the LED is an active component may replace it with a light bulb.
We will describe the circuit from left to right. On the far left of the circuit diagram are the battery, power switch and decoupling capacitors. The smaller decoupling capacitor should be wired as close to the power pins of the microcontroller as possible.
Three buttons with pull-up resistors provide the game controls. We have shown the buttons wired in parallel with a 9-pin D connector, into which you can plug an Atari-style digital joystick. You can of course dispense with either the buttons or the connector if you wish.
The connector to the above left of the microcontroller is for in-circuit programming of the device. You may need to change this part of the circuit to suit your programmer. Note that MCLR must be pulled high and RB4 pulled low for normal operation.
The microcontroller derives its clock from a 20MHz crystal. The load capacitor values shown should be suitable for most readily-available crystals. A ceramic resonator could be used instead of the crystal, and should be accurate enough to allow most televisions to lock on to the resulting signal.
On the right, a handful of resistors and capacitors match the audio (top right) and video (bottom right) signal levels to those required by the television. Crude anti-alias filtering is provided for the audio. The LED lights when the microcontroller takes the RGB select pin on the SCART connector high: this occurs shortly after power-up, and so the LED provides some indication that the circuit is functioning correctly.
Note that the SCART lead you use to connect the game to your television must be fully-wired: not all leads carry the RGB signals. Your television must also be capable of accepting the RGB signals. Most modern televisions have at least one SCART input with this facility, though you may need to check the manual (or experiment) to determine which one it is.
The software is by far the most complex part of the design, and it will not be described in detail here. Large parts of it are automatically generated using specially-written tools. Almost all the resources of the PIC microcontroller are used: 99.9% of the program memory (2046 out of 2048 locations), all but two of the data EEPROM locations, and almost all of the data RAM. You will need a programmer capable of writing to the program memory, data EEPROM and configuration bits of the device. Here is the object code in Intel HEX format: many thanks to Adrian Higginson for preparing this file and testing it with MPLAB. The code is made available without warranty of any kind and is for hobby use only. Commercial use is not permitted.
Here are a couple of pictures of the prototype, assembled using a DIL version of the microcontroller and mostly surface-mount resistors and capacitors. Proper panel-mounted SCART connectors are hard, if not impossible, to obtain, and so the prototype employs a rather odd mounting arrangement to achieve mechanical strength. The corners have been cut away from the board so that it fits (just!) in a type H2855 ABS enclosure (available from Maplin Electronics) along with three AA cells. The enclosure measures 83mm by 53mm by 31mm.
This page most recently updated Mon 16 Jan 11:10:08 GMT 2017
New: Free, fast, and accurate ARM Cortex-M3 floating-point library; UnLife; Pound Shop BASIC; Logic Tutor
Qxw is a free (GPL) crossword construction program. Answer treatments, circular and hex grids, jumbled entries, more besides. Release 20140331 for both Linux and Windows. More...
My book, ‘Practical Signal Processing’, is published by Cambridge University Press. You can order it directly from them, or via amazon.co.uk or amazon.com. Paperback edition now also available. Browse before you buy at Google Books. Wydanie polskie.
If you find this site useful or diverting, please consider a donation to NASS (a UK registered charity), to KickAS (in the US), or to a similar body in your own country.
All trademarks used are hereby acknowledged.