This is based on an old handheld electronic game "Simon." Through 4 pushbutton switches, the user attempts to mirror an increasingly difficult sequence of blinking LEDs and speaker tones. Upon successful game completion (of 63 moves), the game sounds a cycling series of tones. Upon failed input at any point in the game, the correct move will be displayed, the error tone will sound, and then the maximum move number reached is sounded out on the speaker: first, low tones will sound the "tens" and then a higher tone will sound the "ones." So, for 12 moves reached, one single low tone will sound followed by two higher tones.
Each move is stored in memory and matched against 4 user input switches. The "moves" generated by the program are obtained from the TMR0 register at the time of the last user input, preventing the user from intentionally pushing a switch at a specific time to generate a predictable LED turn-on.
Each "move" is recorded in EEPROM data memory, 1 "move" per memory register (since location 0x00 isn't used, we really only have 63 moves possible). Upon mismatch of a switch input from the user and a recorded (expected) "move," the correct LED will turn on while a buzzer sounds the error tone. Also, if the user takes more time than allowed (~5 seconds), the timeout will indicate failed match. Note that if the user waits 4.9 seconds to press the button, then he has another 4 seconds to release it, as TMR_Overflow is reset. This gives a total of 10 seconds time to think between moves if the user is really careful.
(Note: It is possible to fit 4 "moves" per register (shifted in) to maximize the storage capacity at 252 moves, but at this point, 63 moves are enough. If anyone wants to try to increase this to 126 moves (swap the moves into the storage registers) or more (up to 252 moves by shifting the 2 LED bits), go right ahead. I wrote the core of this in a day, and added some options later, so there's probably some room for improvement. On the other hand, if you can remember more than 63 moves in sequence, you probably shouldn't be playing this game :)
Note the use of TMR0 interrupts to generate the different tones. This effectively allows continuous asynchronous control of switch input polling and speaker oscillation. I tried to comment this as completely as possible to help out those new to PIC programming. If there's something you don't understand, drop me an e-mail and I'll try to help.
If anyone does build one of these, I would be happy to hear about it. Please send me an e-mail at firstname.lastname@example.org
Included is a very nice schematic with included recommended parts. For the piezo speaker, what I did was to scavenge one from an old internal computer modem that I had laying around. What is needed is an externally driven piezo buzzer. The specified P9924-ND speaker from Digi-Key (www.digi-key.com) works great, and it's only ~$2. You can also use a regular 7 or 8 ohm miniature audio speaker if you are careful to limit the current with a 100 ohm series resistor. Any momentary switches would work, too, but the ones recommended have a larger profile with a good sized button surface. Just build it up on perfboard or, like I did, a project box with included perfboard from Radio Shack for $4.00.
To get the +5V supply, you can use 4 AAA batteries if you like, or a couple of 3V lithium coin cells, a 6V "N" size battery, or a 4.8V rechargeable NiCD pack. Or, you can make a voltage regulator circuit using a 7805 type regulator or equivalent (like an LM2931) and power the entire circuit using a 9V battery sitting in the bottom of the Radio Shack project box. The circuit only calls out +5V supply lines. How you get there is up to you.
Also, the schematic does NOT show an On/Off power switch. I included one in the Bill of Materials. Just put it in the +5V line going to the Vdd pin. If you use this, you don't need a separate Reset Switch (SW5), but you could leave one in for convenience.
Another thing to note is that the 16F84 datasheet recommends using a 50-100 ohm resistor in series with the MCLR when it's pulled to ground. I haven't had any problems with pulling it directly to ground, but it's probably better to be safe. Just connect a 100 ohm resistor between the switch SW5 and ground.
As far as the code is concerned, particularly note the asynchronous speaker oscillation and input button polling. There are some examples of fine code (as well as some not-so-great code) in the program. Also, EEPROM data recall code is pretty solid, and use of the FSR register is nice. If you are a beginner, you might learn something from this program. If you're an expert, write your own code if you don't like it!
Bill of Materials (with Digi-Key part number and quantity): PIC16F84 PIC16F84 PIC16F84-04/P-ND 1 SW6 on/off and difficulty switch SW101-ND 2 SW1-4 momentary buttons SW421-ND 4 SW5 momentary reset button SW401-ND 1 L1 Piezo Buzzer P9924-ND 1 D1 Red LED 160-1045-ND 1 D2 Green LED 160-1049-ND 1 D3 Yellow LED 160-1053-ND 1 D4 Orange LED 160-1109-ND 1 (Note: These above LEDs have resistors ALREADY INSIDE the LED housing.) (If you want to use another type of LED, you'll have to use the 220-820 ohm) (resistor network shown on the schematic. If you use the above specified) (LEDs, you do not need the resistor network, just connect them directly to) (ground. Also, I indicated a Blue LED on the schematic and in the ASM code) (but the orange one is brighter and is available with the integral resistor.) 18pF Capacitor BC1004CT-ND 1 4.7K resistor 4.7KEBK-ND 1 10K resistors 10KEBK-ND 2 10K resistor network 4606X-1-103-ND 1 ---------------------------------------------------------------- Total parts cost: less than $10.00, not including PIC or project box
Hi Andrew, I'm keen to have a go at building this - and learning some programming at the same time hopefully. Would you confirm something for me first please?
Your schematic shows the 16F84 as per it's actual pinout. However, the datasheet shows OSC1 and OSC2 the other way round to what you have drawn. In short, should R11 and C1 connect to pin 15 or 16?
I've got a PICI6F84 chip like in the diagram, any ideas on how to program? I'm terrible at programming, though the circuit is built and ready :)
maybe some copy/paste code hehe :P
James Newton of James Newton's Massmind replies: The source code is provided on the project page above: http://www.piclist.com/techref/piclist/simon/simon.asm copy and paste it into MPLAB and program the chip. Documentation for the MPLAB software is provided by Microchip in the help system.+
|file: /Techref/piclist/simon/index.htm, 11KB, , updated: 2013/7/1 13:17, local time: 2021/10/18 07:32,
|©2021 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?|
<A HREF="http://www.piclist.com/techref/piclist/simon/index.htm"> Andrew D. Vassallo's Simon game.</A>
|Did you find what you needed?|
PICList 2021 contributors:
o List host: MIT, Site host massmind.org, Top posters @20211018 Neil, Harold Hallikainen, Alan Pearce, RussellMc, Bob Blick, Allen Mulvey, Sean Breheny, Dwayne Reid, Justin Richards, madscientistatlarge,
* Page Editors: James Newton, David Cary, and YOU!
* Roman Black of Black Robotics donates from sales of Linistep stepper controller kits.
* Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters.
* Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.
Welcome to www.piclist.com!