PICs in Space

Quinapalus Home :: Things Technical :: 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.

Features

  • Full colour
  • Animated invaders
  • High-resolution display
  • High-quality stereo sound effects
  • Non-volatile high score table
  • High-tech rolling score
  • Mother ship with random score
  • Progressively increasing speed and difficulty
  • Realistic shield damage
  • Bonus lives
  • Compatible with 625-line/50Hz televisions that have an RGB SCART input
  • Uses standard retro Atari-style joystick
  • Solid interlaced display
  • Accurate synchronisation waveforms, including serration and equalisation
short animation
Longer animation (approx 500kB)
high score table
High score table

Hardware

circuit diagram

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.


Software

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.

Construction

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.

front view back view in the enclosure
Front view; larger version
Back view; larger version
In the enclosure

Similar projects

  • Rickard Gunée has described generating black-and-white video signals with a PIC microcontroller, making a Tetris game and a Pong game. He has also made similar games using a Scenix microcontroller and an external digital-to-analogue converter to produce an NTSC composite colour video signal.
  • Jakub Trznadel has demonstrated the generation of PAL composite colour video signals using an AVR microcontroller.
  • Eric Smith has developed a black-and-white Pong game running on a PIC and a black-and-white terminal based on a Scenix microcontroller plus external digital-to-analogue converter.
  • Les Johnson has written a Space Invaders game in BASIC for a PIC connected to a dot-matrix LCD.

This page most recently updated Thu Apr 10 22:13:01 BST 2014
Word Matcher

Options...
Type a pattern, e.g.
h???o
into the box and click ‘Go!’ to see a list of matching words. More...


Qxw screen
Qxw is a free (GPL) crossword construction program. Answer treatments, circular and hex grids, jumbled entries, more besides. New release 20140331 for both Linux and Windows. More...

Practical Signal Processing front cover
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.

Copyright ©2004–14.
All trademarks used are hereby acknowledged.