PIC Blitz is a tiny, low-power, ultra-low-cost device that plays lightning chess. It is based on a PIC16F628A microcontroller, which has just 3.5 kbytes of flash and 224 bytes of RAM.
The circuit (PDF here) is very straightforward. The microcontroller is overclocked, with the clock derived from a 20 MHz crystal; the five buttons are connected to input port bits and are fitted with pull-up resistors; and the LCD is connected directly to output pins (the interface is ‘bit banged’). The processor and LCD together take about 2 mA in operation, and so a CR2032 lithium coin cell with a nominal capacity of around 220 mAh should last for hundreds of five-minute games.
The LCD used is a 96-by-68 monochrome type based on an STE2007 controller, available as a spare part for Nokia 1202 mobile ’phones. These can be had from various on-line sellers very cheaply indeed. It is perfectly legible in normal conditions without a backlight; but if you wish you can supply its backlight from the 3 V supply via a resistor (perhaps 470 Ω), which will give enough light to make the display readable in the dark as well, at a small cost in battery life. (Since the forward voltage of the backlight LED varies considerably from unit to unit and is in any case more than 3 V, this is hardly a technically satisfactory approach, but it is better than nothing.)
Control is via five pushbuttons, four of which (‘up’, ‘down’, ‘left’ and ‘right’) are normally used to provide cursor movement and one (‘OK’) confirms an entry. A five-way tactile switch or a digital joystick with a fire button could be used instead.
The circuit can be built on a printed circuit board measuring approximately 50 mm square.
Gerber files for this layout, produced using KiCad, are available
I have a small number of spare unpopulated printed circuit boards like the one shown in the picture available in exchange for a donation to a charity as indicated in the bar to the right. Please get in touch if you are interested via the e-mail address on the home page. The design uses 0603 surface-mount passives and the LCD connector has a pitch of 0.6 mm, so you will need reasonable soldering skills and equipment.
The microcontroller requires a 5 V supply while it is being programmed. This is outside the operating voltage range of the LCD module (although it is within its ‘absolute maximum’ rating), so ideally you should program the microcontroller before fitting the LCD. If you want to keep the option of reprogramming the device, you may wish to add a regulator (a resistor plus a Zener diode will do) for the LCD supply and series resistors for its data lines. Or you could take a chance and see if you can successfully program the microcontroller at say 4 V.
The code occupies all but three locations of the program memory and all of the data memory. The (somewhat tersely commented) source code and binary dumps of the program and data memory are available here. The code is open source, licensed under version 2 of the GNU GPL.
The files pmem.bin and dmem.bin in the archive are the contents of the program and data memory respectively. The file pmem.bin is represented as two bytes per instruction, more significant byte first: the first three opcodes are 0x2E2E 0x0782 0x3400. The file dmem.bin is represented as one byte per data memory location. You may need to convert the files to a different format to suit your programmer. The configuration word should be set to 0x3FAE (high speed crystal, brown-out detector disabled).
PIC Blitz was written using a set of C macros to represent the microcontroller’s instruction set with a two-pass assembly process reminiscent of the BBC BASIC in-line assembler. This allowed for flexible simulation and testing of the code during development. The mnemonics used are to my mind more logical than those proposed by Microchip, but they may not be to everyone’s taste. The code is thus built by compiling and running the program picblitz.c in the archive. At the Linux command line, for example, this can be done by typing
gcc picblitz.c && ./a.out
This will overwrite the files pmem.bin and dmem.bin, so you may wish to make copies of them first, compare them to the newly-generated versions using diff and (assuming you have not edited the source code) make sure they are recreated identically. The checksums of the original files are as follows:
$ sha1sum pmem.bin dmem.bin c2e7a987a32b020868d517e44df2e7df926ce64f pmem.bin 37341b93f819fab797ab49ee2ebc1c95344e3a0a dmem.bin
I am grateful to Tim Kallweit for testing this Intel HEX file which includes both the program and data memory contents.
Switch the unit on. The clocks (yours at the bottom right of the display, PIC Blitz’s at the top right) are initially set to five minutes each; press the ‘up’ and ‘down’ buttons to change them. Press the ‘right’ button to rotate the board and play as black. The book icon on the right indicates that PIC Blitz will use its openings book: press ‘left’ to change this. Press the ‘OK’ button to start.
The cursor is indicated by two triangles, one on the bottom edge of the board and one on the right edge. Move the cursor to the piece you want to move using the direction buttons and press ‘OK’. Then move the cursor to the square to which you want to move the piece and press ‘OK’ again to confirm the move. Your move is displayed in algebraic notation in the bottom right corner of the display. Illegal moves are rejected.
PIC Blitz’s move is shown at the top right; while it is thinking, dashes are displayed instead. The book icon disappears when PIC Blitz is out of its openings book.
You can start to enter a move (but not confirm it) while PIC Blitz is thinking.
Special moves are entered as follows.
PIC Blitz will underpromote if it feels the need.
When a player runs out of time the clock will flash at zero; however, the game can still be completed if desired.
The early dedicated chess computers ran on microprocessors with very limited hardware. For example, Boris used an eight-bit microprocessor with only 2.5 kbytes of ROM and 256 bytes of RAM, and the programmers still found room to have it make witty comments on your play.
The Micro-Max engine by Harm-Geert Muller has been ported to the Atmel AVR eight-bit microcontroller architecture by Andre Adrian (site in German). The design appeared as the AVR-Max Chess Computer in Elektor magazine in November 2009. It uses an ATmega88 with 8 kbyte of flash memory (more than twice the PIC16F628A) and 1 kbyte of RAM (more than four times the PIC). The main reason for the greater use of RAM seems to be that its move stack takes a rather profligate 34 bytes per ply; PIC Blitz uses six bytes per ply. In fact, PIC Blitz only uses a total of about 176 bytes of RAM, including board storage, move stack and temporary variables.
Arthur Benemann has written a program called picChess with video output. It runs on a DSPIC33 series microcontroller with plenty of flash and RAM. The total code size appears to be about 46 kbytes, but it is not clear how much of that is the chess program.
This page most recently updated Thu Aug 7 12:10:29 BST 2014
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...
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.