Instructables
This project shows how to create an MB Electronics Simon game clone using an 8-pin PIC12F683 microcontroller. The game includes a full emulation of the original Simon 'game 1' and the ability to select from 4 skill levels which control the number of colours you must repeat in a sequence in order to win the game.

The project was created for Sparkfun's microcontroller competition 2011 and aims to demonstrate an number of useful design techniques which can be used when working with low-pin count microcontrollers. The code is written entirely in C and fits neatly into the 2K of available program flash on the chip. The PCB is only 1.5 inches square and uses both SMD and through-hole components, however it is perfectly possible to recreate the project using larger components on a breadboard or a small piece of strip-board.

The game is powered by a standard CR2032 3V lithium cell which is mounted on the underside of the game. The design uses the ultra low power standby feature of the microcontroller meaning that no power switch is required. Overall power consumption is kept to a minimum by using the internal oscillator of the PIC running at 4Mhz.

You can see a video of it in action over on youtube
 
Remove these adsRemove these ads by Signing Up

Step 1: Parts List


The MicroSimon hardware consists of the following parts:

* 1 x PIC12F683 SOIC 8-pin microcontroller
* 5 x 10K resistors (1206 SMD)
* 1 x BC817 NPN Transistor
* 1 x 100nF capacitor (0805 SMD)
* 4 x 3mm LEDs
* 1 x CR2032 battery holder
* 5 x Tactile push-button switches
* 1 x QMX-05 speaker
* 1 x 6 pin 2.54" right angled header
Grazfather3 years ago
Nice. I like this a lot and I have a few 12f683's sitting around. Nice code, too.

One totally useless tip:

randomNumber++;
if (randomNumber == 5) randomNumber = 1;

could be

randomNumber &= 0b11;
randomNumber++;

to get rid of the branch, not that you have such a busy loop that you need to save instructions...
simoninns (author)  Grazfather3 years ago
@Grazfather - You could actually do it in one line using the mod operator, something like:

randomNumber = (randomNumber + 1) % 5;

But there is always the trade-off between code readability and memory efficient coding. I always go the 'readable' route unless I really need to save some bytes.
Actually, you'd want
randomNumber = (randomNumber % 4) + 1;
The way you have it, it'll make a number between 0 and 4, but it looks like you're looking for a number between 1 and 4 in the original code.
Or you could do
randomNumber = (randomNumber & 0b11) + 1;
With the same effect of being on one line...
However, you should not use a mod operator here, because depending on the compiler your mod operator could end up eating up a lot pf processing. On most processors, division (including modulo division) is about the very slowest single action you can have the processor take, and for a PIC, it might end up expanded into a fairly large subroutine call. (If you are paying a few hundred dollars for a proprietary compiler for embedded system development, then it might not matter, as the compiler will likely optimize it to the same thing Grazfather suggested)
ishiyakazuo6 months ago
I like the resistor ladder for the buttons a lot.
I'm definitely going to use that in a project I'm working on, but with one small change: the top resistor I'm planning on making a 4.7k vs. all 10k. The reason is, it staggers the values to be away from binary midpoints so I can just look at the top few bits of the ADC. It'd put the values at approximately 68%, 40% and 28%, rather than 50%, 33% and 25%. Having 33% and 25% in there means I'd need to look at more bits of the ADC, but with these values, I can easily get away with looking at only the upper 3, as long as the resistors are within some reasonable tolerances (i.e. not 20% resistors). I really don't like 50% and 25% being in there, because it could be that you have 1000000000b or 0111111111b for 50%, and similar for 25%, and I'd rather just say "ignore the lower N bits, and if the upper bits match this value exactly, you have button press." :)
Anyway, just a thought. It really depends more about your code size vs. stock of resistors. Still can do the same thing with all 10k, just needs more bits and therefore more cases to handle.
Simon, I need desperate help with a similar project using a 16F84. Unfortunately my programming skills are absolutely awful. I have the 4 inputs on PORTA and the 4 LEDs on PORTB but I can't for the life of me figure out how to program SIMON into the chip. I know the commands but figuring it out is intensely frustrating.
deattila1 year ago
hello i have made your project but the programming is a little
problem, cause i use winpic wat for code do i need to use for
that program, i dont program for a long time so i hope you can help my

simoninns (author)  deattila1 year ago
You need to use MPLAB from Microchip to do the programming. You can download it (and the compiler) free from their website.
nodoubtman2 years ago
Here's the version of Colin Mitchell i have realised : http://www.youtube.com/watch?v=IzJERfsaF6E
nodoubtman2 years ago
I have used Colin Mitchel one's with a pic16f84A : http://www.talkingelectronics.com/te_interactive_index.html

it is great! :)
congradulation Colin!
Keep the good work!
marC:)
nodoubtman2 years ago
2n3904 is okay?
simoninns (author)  nodoubtman2 years ago
It should be fine. I've never used one myself, so I can't be 100%. The application is a very basic one though, so pretty much any NPN would probably do the trick.
nodoubtman2 years ago
any other substitute for bc817?

thank you!
marC:)
simoninns (author)  nodoubtman2 years ago
Any small signal NPN would do (like a BC337 for example).
2n3904 should work?

do you have a bigger schematic please? i don't see much on this one

thank you!
marC:)
simoninns (author)  nodoubtman2 years ago
Follow the link in my profile to my website; there you will find better pictures of the project.
Stanh113 years ago
is there any other pic that i can use i cant find that pic where i live
simoninns (author)  Stanh113 years ago
I would think that any similar PIC12F should do the trick. You will need to alter the fuse settings accordingly though.
what about the PIC12C508A the only difference i see is the memory this one is EEPROM and yours is flash
simoninns (author)  Stanh113 years ago
I can't say I've played with that many types of PIC12F to really give you good advice (I usually work with 18Fs). Microchip have an on-line product selection tool which you may find useful:

http://www.microchip.com/productselector/MCUProductSelector.html
i have another question you have your own pic programmer or you using pickit?
because pickit is expensive and i would like to make my own programmer if i can
thank you this is my first project with a pic im kinda confused because i dont know much about pics but ill try to do this thanks for this tutorial
Tolaras3 years ago
Hello!

Really nice project! Congratulations!

I have one problem though. How can I assemble all these .c and .h files to an .asm file in order to load them to the PIC microcontroller? I tried microC for PIC and MPLab IDE but I couldn't managed it.

Thanks!
simoninns (author)  Tolaras3 years ago
The source code is for MPLAB with the HiTech PICC18 compiler which you can download for free from Hi-Tech's website. The code will not work with microC or microchip C18 compilers without alteration.

Hope this helps!
I 'll try it later today..

Thanks!
notsure3 years ago
Very well done!