www.NewsDownload.co.uk Page 37

Open Source Microchip PIC Game

2017-07-19 05:02 By Jason Birch

Design and development of a game using a Microchip PIC micro-controller. Detailed analysis of the development process to create the circuit and assembly code.

REFERENCE
PIC Game Source Code
Microchip PIC12F629

VIDEO
PIC Game Programming PART 1: GOAL

First part in the series of design and programming of a Microchip PIC game. Demonstrating and describing the end product in detail, in order that the following parts in the series have a reference to show what effects are being developed.
VIDEO
PIC Game Programming PART 2: HARDWARE

A description of the simple circuit required to make this project. Describing the circuit operation and design for low power consumption, due to the project being powered by a single CR2032 coin cell battery.
VIDEO
PIC Game Programming PART 3: PCB

The assembly of a PCB for the project. Discussing the placement of components on both sides of the PCB to reduce the overall footprint and improve usability. And the use of a printed out silkscreen layer to aid the assembly of home made printed circuit boards.
VIDEO
PIC Game Programming PART 4: SOFTWARE DESIGN

Presentation covering the software design, approach and concepts used. Covering software and hardware initialization, finite state machines, settings, game play, low power mode and restarting game play.
VIDEO
PIC Game Programming PART 5: ANIMATING LEDs

Starting the development by laying out a template for a PIC assembly program and writing the functions to control the LEDs in the circuit. Create a test harness to prove the functions are working and program the compiled code onto a PIC device to see the effect in circuit.
VIDEO
PIC Game Programming PART 6: PLAYING SOUND

In this part the functions for playing sound are added. An interrupt handling routine is required so the micro-controller timers can be used to generate audible frequencies. The issues around using interrupts are described and the test harness is updated to play a tune while the LEDs animate with the code added from the previous part.
VIDEO
PIC Game Programming PART 7: READING SWITCHES

The timer 0 interrupt is handled, this moves much of the previous test harness code into their correct locations and adds the call to the read switch state function. The test harness is updated to check for switch presses and play the win tune when a switch is pressed. Additional switch functions required for the game play are added and the pause function has been removed from the test harness and written for multi-threading purposes.
VIDEO
PIC Game Programming PART 8: RANDOM NUMBERS

Generating random numbers, so each time the game played it is a unique experience for the user. Explaining why not all RAM in cleared at start up, the process of adding random values to a cache of random numbers and overwriting them on a regular basis. Having a simple call to get a random number when one is required. The test harness is replaced to constantly display flashing random LEDs.
VIDEO
PIC Game Programming PART 9: LOW POWER SLEEP

Placing the device in to low power mode after no activity for a period of time. This allows the device to switch itself off and not require a power switch. Pressing any key will turn the device back on again. Also covered is the initial finite state machine, which will be used to run the application.
VIDEO
PIC Game Programming PART 10: USER SETTINGS

Handling user key press actions for selecting game level, toggling sound on and off and starting a game. Adding the required function to the applications finite state algorithm. Using the process of check for required key and perform required action, and finally clear processed key presses ready for next time.
VIDEO
PIC Game Programming PART 11: GAME PLAY

Final part in series. Playing a game, adding a random number to the sequence of random numbers, playing the sequence on the LEDs, with sound if enabled, and the user playing back the sequence played by the micro-controller. Repeat the process until the player times out, gets it wrong, or wins the game.
VIDEO
How To Make A Solar Powered Simon PIC Game

As part of my series on programming this project, a quick aside, showing the game being played solely from solar power. Sound has to be turned off with a solar panel this small, but the game can still be played.

HARDWARE
This project is ideal for learning to program PIC micro-controllers as the circuit is very simple and easy to put together. The source code covers many concepts such as:
  • Logic operators in both pre and post compiled.
  • Finite state machines.
  • Generating random values.
  • Handling processor interrupts.
  • Using timers.
  • Bi-directional ports.
  • Reading inputs.
  • Setting outputs.
  • Generating audible sounds.
  • Designing low power circuits and software.


PIC Game Hardware PCB

MAKING
The circuit can be assembled simply on strip-board.

There are videos describing how to make a PCB on this site here:
Designing a Printed Circuit Board on a Raspberry Pi

Preparing to Etch a PCB at Home Using KiCad on a Raspberry Pi

Making, Assembling & Testing, The Raspberry Pi KiCad PCB

There are videos describing how to program a PIC device using a Raspberry Pi on this site here:
Raspberry Pi Microchip PIC Micro-controller Programmer



Circuit for PIC Game [Click To Enlarge]

SOFTWARE
The software is written in assembly language and is available here: Microchip PIC Game Source Code

The videos in the series listed above, go into detail describing how the software works and provide comparable examples which can be programmed onto a PIC device and tried. The final video shows the source code in completion, this source code is Open Source and can be programmed onto a PIC device and used in the circuit shown on this page. A full copy of the Open Source license must be kept with the source code at all times, with a credit to the original author Jason Birch.


PIC Game Hardware Strip Board

Project Cost
Item Reference Qty Each Cost
Red LED 3mm BitsBox 1 £0.10 £0.10
Green LED 3mm BitsBox 1 £0.10 £0.10
Yellow LED 3mm BitsBox 1 £0.10 £0.10
Amber LED 3mm BitsBox 1 £0.10 £0.10
120R Resistor Carbon film 1/4W 5% BitsBox 4 £0.06 £0.24
0R Resistor Carbon film 1/4W 5% BitsBox 4 £0.08 £0.32
1K Resistor Carbon film 1/4W 5% BitsBox 1 £0.06 £0.06
1uF Tantalum Capacitor BitsBox 1 £0.21 £0.21
Black Tactile 4.3mm Switch 100g eBay 4 £0.17 £0.68
8 Pin DIL Socket BitsBox 1 £0.12 £0.12
Microchip PIC12F629 Micro-Controller BitsBox 1 £0.90 £0.90
BC337 NPN Transistor BitsBox 1 £0.10 £0.10
Miniature Electromagnetic Transducer BitsBox 1 £0.37 £0.37
CR2032 Coin Cell Holder BitsBox 1 £0.58 £0.58
CR2032 Coin Cell Pound Land 1 £1.00 £1.00
Stripboard 95x64mm BitsBox 1 £0.98 £0.98
TOTAL £5.96


Loading...