This is only a preview of the January 2005 issue of Silicon Chip. You can view 40 of the 104 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Articles in this series:
Items relevant to "Build A V8 Doorbell":
Items relevant to "IR Remote Control Checker":
Items relevant to "Simon Says . . .":
Purchase a printed copy of this issue for $10.00. |
Simon
Says . . .
Ahhhh! – nostalgia, it ain’t what it used
to be. We take a look at how electronic
games have changed over the last 25
years and describe a new “Simon Says”
game for you to build.
By CLIVE SEAGER
R
EMEMBER THE 70s? The BBC in
the UK recently produced a series
of television programs called “I Love
197x”. You certainly start to realise
your age when you discover that 1978
was over 25 years ago! The 1978 program made reference to the cult toy
of the year, “Simon”, made by MB
Games, which was loved by children
Fig.1: this page from the General
Instruments 1977 catalog lists
the PIC1650 as a “Programmable
Intelligent Computer”
76 Silicon Chip
and loathed by parents! This was one
of the very first mass-produced electronic games and I remember playing
it with friends and relatives.
Simon
For those too young to remember
1978, the idea behind the Simon game
was quite simple. It was based on the
old school playground game “Simon
Says”. The game was made up of a big
round plastic case with four coloured
panels. Each panel concealed a switch
and a light bulb.
At the start of a game, the electronics
inside would light up one of the four
panels briefly and sound a tone. The
player then had to press that panel,
after which Simon would repeat, lighting the same panel briefly and adding
another. Again, it was the player’s turn.
He or she then had to press the two
panels in the correct sequence.
Each round, the number of panels
increased by one until the player
could no longer remember the correct
sequence. Simon would then issue a
harsh buzz and end the game.
As I watched the TV program, it
struck me that this vintage toy from
1978 could probably be reproduced
with a PICAXE microcontroller at
very low cost.
So I set myself the task of building
This is the original MB “Simon”
game from 1978.
my own PICAXE version of the “Simon
Says” game, particularly as I thought
it would provide a perfect example
of how to remember sequences in a
PICAXE BASIC program, something
that many users find quite difficult.
Internet trivia
A quick Google search on the Internet soon revealed lots of trivia about
the original “Simon” game.
The first single-player game was
released in 1978. Subsequently, MB
released “Super Simon” in 1979,
which had two sets of panels for two
players. In 1980, a smaller version
called “Pocket Simon” appeared.
There was also a special edition Simon
with a clear casing so that the internal
workings could be seen.
Apparently, “Super Simon” even
makes an appearance in the film “ET”,
where it can be seen on the shelf behind ET’s head when he first speaks!
However, I was more interested
in how the original game worked. I
discovered it needed both a 9V PP3
and two large D cells to make it work,
presumably to power the light bulbs
and speaker, but could not discover
much more online.
Then using my “you can buy anything on eBay” philosophy, I did a
quick search and sure enough, dissiliconchip.com.au
covered that I could buy a real Super
Simon, complete with box and instructions, for just £5. So five days later I
was the proud owner of a vintage game,
which I then, as you probably expect
by now, completely disassembled!
The original game
Removing the cover exposed a
sparsely populated PC board. It consisted only of a metal switch contact,
eight bulbs buffered by a couple of
standard logic gates, and a Texas
Instrument “microcomputer” chip.
These microcomputer chips were
some of the first “single-chip” controllers widely used in mass-produced
consumer products, and can be found
in a wide range of early 80s equipment
such as vending machines. They were
the predecessors of the modern PIC
microcontrollers.
Many people think microcontrollers
are a relatively new idea, when in
actual fact this game was using very
similar single-chip technology 25
years ago!
What does “PIC” stand for?
One of the most common questions
we are asked is “what do PIC and
PICAXE actually stand for?”
Back in 1975, General Instruments
Microelectronics Division developed a
small 8-bit controller (PIC1650) based
on the Harvard architecture, which
itself had been created as part of an
earlier inter-university Defence Department competition. Many sources
quote the PIC1650 controller as being
created primarily as a support input/
output device for the more powerful
CP1600 16-bit processor and so quote
PIC as standing for “Peripheral Interface Controller”.
However, a rare scanned copy of the
1977 General Instruments “Micro-electronics” catalog tells a different story.
Fig.1 shows the PIC1650 page from
this catalog, which lists the device as a
“Programmable Intelligent Computer”.
The datasheet clearly shows that this
device was the “first in breed” of all the
later PICmicro devices, even though
is was only available in masked ROM
version using NMOS technology.
In the early 80s, a venture capital group purchased 85% of the GI
Microelectronics Division, including
the Arizona manufacturing plant, and
formed the Microchip company as it
is known today. This new company
combined the original PIC1650 techsiliconchip.com.au
“Super Simon” came a year after the original “Simon” game and featured twoplayer support.
A disassembled “Super Simon”, revealing the TI microcontroller (the larger 28pin chip) and not much more.
nology with EPROM memory to create
the one-time-programmable PICmicro “C” series parts known today.
Later they added erasable EEPROM
memory to create the PIC16C84, then
the 16F84, and subsequently all of the
“F” (FLASH) series parts.
Therefore, PIC can stand for either
January 2005 77
Fig.2: the circuit diagram for “Simon Says” is a PICAXE incarnation of the
game. As with the original, a single-chip micro handles all the smarts but
LEDs and a piezo sounder replace the incandescent bulbs and speaker.
“Peripheral Interface Controller” or
“Programmable Intelligent Computer”
– take your pic(k)! PICAXE is easier
to explain; it is simply a brand name
based on a play of words!
The new Simon game
The circuit diagram for the PICAXE
version of the game is shown in Fig.2.
As you can see, it’s very straightforward indeed, consisting of just the
micro, four LEDs, a piezo sounder,
five pushbutton switches and a few
resistors.
PC board assembly is also quite
straightforward. Use the overlay diagram in Fig.3 as a guide to component
placement. Take care with the orientation of the four LEDs, which must have
their flat (cathode) sides positioned as
shown. Also, make sure the notched
(pin 1) end of the PICAXE micro faces
the serial link socket. Before soldering
(1). Wait for the player to press a switch
to start the game.
(2). Generate a sequence of random
numbers, ranging from 0-3 for the
four LEDs. In this case, I will use 100
steps; many more than the seven or
eight I can normally repeat in a game!
These numbers are stored using the
write command in the PICAXE-18A’s
separate data memory, which actually
has space for up to 256 steps.
(3). Get the microcontroller to play
back the numbers. To do this, the
micro must know how many steps to
play back in each round of the game.
A variable called topstep will be used
to remember the number of steps. If
topstep = 1, one step will be played
back, if topstep = 2, two steps will be
played back, and so on.
(4). When the player presses a switch,
the microcontroller must light the
correct LED for that switch and then
compare the switch press to see if it
is in sequence. The micro must therefore count the number of switches the
the battery clip leads, thread them
through the adjacent hole to provide
strain relief.
Power your completed project only
from a 3 x AA alkaline cell (4.5V) battery pack or regulated 5V DC supply.
Take particular care that you have the
power leads around the right way,
otherwise you’ll destroy the PICAXE!
Programming introduction
The programming task for the Simon
game is fairly complicated but is a
good example of how to “remember”
sequences using the separate data
memory (available in all the “A” and
“X” series PICAXE micros).
When approaching a complicated
problem like this, it is essential to
break the overall task down into small,
manageable chunks and then put the
whole program together at the end.
The following tasks were identified:
Table 1: Resistor Colour Codes
o
o
o
o
o
No.
2
1
1
4
78 Silicon Chip
Value
10kΩ
22kΩ
4.7kΩ
330Ω
4-Band Code (1%)
brown black orange brown
red red orange brown
yellow violet red brown
orange orange brown brown
5-Band Code (1%)
brown black black red brown
red red black red brown
yellow violet black brown brown
orange orange black black brown
siliconchip.com.au
Parts List
1 Simon PC board
1 3.5mm stereo socket
1 miniature pushbutton switch
(SW5)
4 pushbutton switches (SW1 –
SW4)
1 battery clip
1 3 x AA battery holder
1 18-pin IC socket
1 miniature piezo transducer
Semiconductors
1 PICAXE-18A microcontroller
1 5mm green LED
1 5mm red LED
1 5mm yellow LED
1 5mm blue LED
Fig.3: follow this diagram when assembling the board. Take particular care
with the orientation of all the LEDs, the PICAXE micro and the power input
leads.
Capacitors
1 100nF (0.1µF) MKT (code
100n or 104)
Resistors (0.25W 5%)
2 10kΩ
1 4.7kΩ
1 22kΩ
4 330Ω
1 10kΩ trimpot (VR1)
Also required (not in kit)
PICAXE Programming Editor
software (v4.1.0 or later)
PICAXE download cable (part
AXE026)
3 AA alkaline cells
Obtaining kits and software
This is what the completed PC board looks like. Power comes from an external
4.5V battery pack consisting of three AA alkaline cells.
player has pressed. These are accumulated in the playerstep variable.
(5). When the player reaches the end
of the sequence, the microcontroller
must acknowledge the success, add
one to the value of topstep and then
repeat the process from (3) above. If
the player gets the sequence wrong,
a buzzer will sound and the game
will reset.
Program
The full program listing is shown
siliconchip.com.au
in the accompanying panel. Although
the program is quite complex, we’ve
included it here as an example of
what can be achieved with PICAXE
microcontrollers.
Full comments are given in the
program but a brief explanation is
also included below. Note: to save
typing the program in manually, you
can download it from the SILICON CHIP
web site at www.siliconchip.com.au.
Section 1 in the program is a loop
that lights all four LEDs, generates a
The design copyright for this
project is owned by Revolution
Education Ltd. Complete kits (part
AXE106K) for this project are
available from authorised PICAXE
distributors – see www.microzed.
com.au or phone Microzed on (02)
6772 2777.
The PICAXE Programming editor
software can be downloaded free
of charge from www.picaxe.co.uk
or ordered on CD (part BAS805).
random number and then waits for a
switch to be pressed to start the game.
By including the random command
within the loop, it is constantly varying and so no two games will be the
same.
Section 2 uses a for…next loop
to store 100 random numbers in the
micro’s memory. As the PICAXE random command only works on word
variables, it is called using the variable randword. However, as we only
January 2005 79
Simon Says PICAXE BASIC Program
' *** Define the variables used ***
symbol randword = w0
'random number (word)
symbol randbyte = b0
'random number (byte, part of w0)
symbol value = b2
'switch value 0-1-2-3
symbol playerstep = b3
'position of player in game
symbol freq = b4
'sound variable
symbol topstep = b5
'number of steps in sequence
symbol counter = b6
'general purpose counter
symbol speed = b7
'playback speed
' *** Section 1 **********************
' Wait for any switch to be pushed
init:
let pins = %00001111
random randword
if input0 = 1 then preload
if input1 = 1 then preload
if input6 = 1 then preload
if input7 = 1 then preload
goto init
'light all LEDs
'randomise
'check switches
' *** Section 2 ****************************
' Load EEPROM data memory with 100 numbers
preload:
let pins = %00000000
for counter = 0 to 100
'LEDs off
'for..next loop
let value = 0
random randword
'get random number
if randbyte > 180 then set0
if randbyte > 120 then set1
if randbyte > 60 then set2
set3: let value = value + 1
set2: let value = value + 1
set1: let value = value + 1
set0:
write counter,value
next counter
'1+1+1 = 3
'1+1 = 2
'1
'0
'save in data memory
'next loop
' *** Section 3 ****************************
' This section plays back a sequence
let pins = %00000000
let topstep = 1
playback:
readadc 2,speed
for counter = 1 to topstep
read counter,value
gosub beep
pause 300
next counter
'LEDs off
'reset step number to 1
'read speed value from preset
'for...next loop
'get value
'make the noise
'short delay
'loop
' *** Section 4 **************************************
' Now the user responds
playerstep = 1
' If playerstep is greater than topstep then all done
80 Silicon Chip
gameloop:
if playerstep > topstep then success
read playerstep,value
'recall correct value
loop:
if input7 = 1 then pushed0 'wait for switch press
if input0 = 1 then pushed1
if input1 = 1 then pushed2
if input6 = 1 then pushed3
goto loop
' Now check correct value depending on which switch was pressed
pushed0:
if value <> 0 then fail
let playerstep = playerstep + 1
gosub beep
goto gameloop
pushed1:
if value <> 1 then fail
let playerstep = playerstep + 1
gosub beep
goto gameloop
pushed2:
if value <> 2 then fail
let playerstep = playerstep + 1
gosub beep
goto gameloop
pushed3:
if value <> 3 then fail
let playerstep = playerstep + 1
gosub beep
goto gameloop
' Failed so make noise and jump back to start
fail:
let pins = %0000000
'all LEDs off
sound 7,(80,100)
'make a noise
sound 7,(50,100)
goto init
'back to start
' Succeeded so add another step to sequence and loop
success:
pause 100
'short delay
let pins = %00001111
'all LEDs on
sound 7,(120,50)
'success beep
let pins = %00000000
'all LEDs off
pause 100
'short delay
let topstep = topstep + 1
'add another step
goto playback
'loop again
' *** Section 5 ****************
'Sub-procedure to light correct LED and make beep
beep:
high value
freq = value + 1 * 25
sound 7,(freq,speed)
low value
return
'switch on LED
‘generate sound freq.
'play sound
'switch off LED
'return
siliconchip.com.au
require a byte value, we later use the
variable randbyte (one half of randword). We only require the numbers
0-3 (for the four LEDs) but randbyte
can contain the value 0-255 and so we
carry out a simple comparison test to
get the four desired values.
Section 3 switches all four LEDs off
and then uses a for..next loop to play
back the sequence (up to the variable
topstep). The “beep” sub-procedure in
section 5 is used to light the appropriate LED and make a sound for each
step. Note that the sound is different
for each LED to aid memory during
the game. The length of the beep is
determined by the setting of trimpot
VR1, which can therefore be used to
increase or decrease the speed of the
game.
Section 4 first resets the player’s
position to 1. A test is then carried
out to see if the player has completed
all the required steps. If all steps have
been done, the “success” section of the
code flashes all four LEDs, adds one
more step to the topstep value and then
loops back to section 3.
If there are still steps to do, the
correct target value is retrieved from
memory for comparison. The program
then enters a loop, waiting for a switch
to be pressed.
When a switch is pressed it is compared to the target value retrieved from
memory. If the values are the same,
everything is correct and so the LED
is lit via the “beep” sub-procedure,
the players position is increased by
one and the program loops back for
another switch press.
If the value is incorrect, the “fail”
section of the code makes a noise and
then resets the game.
Summary
Single-chip controllers are not new,
as this game was using them 25 years
ago! However, electronics has changed
dramatically since then and modern
microcontrollers are much cheaper
and easier to use than the original
micros.
Modern microcontrollers such as
the PICAXE reduce large complex
circuits down to simple, clean designs
and dramatically reduce the cost of
these products. LED technology has
improved and no game would ever be
manufactured now with bulbs due to
cost, safety and power consumption.
Microcontrollers are here to stay! SC
Want cheap, really
bright LEDs?
We have the best value, brightest LEDs
available in Australia! Check these out:
Luxeon 1, 3 and 5 watt
All colours available, with
or without attached
optics, as low as
$10 each
Low-cost 1 watt
Like the Luxeons, but much lower cost.
•Red, amber, green, blue
and white: Just $6 each!
Lumileds Superflux
These are 7.6mm square and can be
driven at up to 50mA continuously.
•Red and amber: $2 each
•Blue, green and cyan: $3 each
Asian Superflux
Same as above, but much
lower cost.
•Red and amber: Just 50 cents each!
•Blue, green, aqua and white: $1 each.
Go to www.ata.org.au or call
us on (03)9419 2440.
Superbright Lumileds - Indoor & Outdoor LED light fitting range
D HIGH BRIGHTNESS D LONG LIFE D FULLY DIMMABLE D ENERGY EFFICIENT
The range of LUMILED downlight fittings shown here have been designed for domestic, display, marine,
mobile home and caravan applications. All fittings use Lumileds, which are:
- Long life (typical 100,000 hours) - High efficiency, low power, low voltage - Vibration proof
The OPLLGW series
White powder coated.
This series is a ceiling
type gimballed fitting
and require a 57mm
diameter cutout
(MR11 size).
The OPLLBL series
Black powder coated.
This series is a standalone type for use
indoors or outdoors,
are fully weatherproof
and able to be fully
submerged for pond
application.
The OPLLBR series
Solid Brass. This
series is a standalone type for use
indoors or outdoors,
are fully weatherproof and able to be
fullysubmerged for
pond application.
Visit us at: www.prime-electronics.com.au
PRIME
ELECTRONICS
siliconchip.com.au
The OPLLFG series
Gold outer rim with
chrome inner finish.
This series is a ceiling
type fixed fitting and
require a 51mm
diameter cutout
(MR11 size).
The OPLLGC series
Brushed Stainless
Steel finish. This
series is a ceiling type
gimballed fitting and
require a 57mm
diameter cutout
(MR11 size).
The OPLLGG series
Brushed Gold Finish
This series is a ceiling
type gimballed fitting
and require a 57mm
diameter cutout (MR11
size).
Email us: sales<at>prime-electronics.com.au
BRISBANE SHOWROOM
22 Campbell Street
Bowen Hills QLD 4006
Telephone: (07) 3252 3762
Facsimile: (07) 3252 5778
SOUTHPORT SHOWROOM
11 Brickworks Cntr,
Warehouse Rd
Southport QLD 4215
Telephone: (07) 5531 2599
Facsimile: (07) 5571 0543
SYDNEY
185 Parramatta Road
Homebush NSW 2140
Telephone: (02) 9704 9000
Facsimile: (02) 9746 1197
January 2005 81
|