Silicon Chip – July 2019

(Frankie) #1

siliconchip.com.au Australia’s electronics magazine July 2019 103


The basic idea of this game is to sim-
ulate and display a two-horse race. It
has three different modes: trot, canter
and gallop.
The race is shown on a 4-line, 20-col-
umn alphanumerical LCD screen. The
image of each horse is formed using
eight custom characters, and their legs
are animated as they run. See the ad-
jacent screen grab and video.
The circuit is built around an AT-
mega8A microcontroller and the afore-
mentioned LCD. In all the three modes,
the speed of both horses varies auto-
matically and randomly as they run
across the display.
This is done using pseudorandom
numbers generated by the microcon-
troller, based on an internal timer val-
ue. The random numbers provided by
the timer are used to change the speed
of each horse.
Thus during the race, the leading
horse is sometimes Horse 1 and some-
times Horse 2, and the winner is un-
predictable until one horse reaches
the finish line (block 20 of the LCD).
To begin the game, switch the unit
on. The piezo generates a beep, and
two horses appear on the left side of
the LCD, and to the right, the message
“Press Button” appears on the first two
lines, with “Mode: Trot” on lines 3 and



  1. A momentary press of mode switch
    S3 changes the mode.
    With the desired mode selected,


press play button S2 to allow the two
horses to start running towards the op-
posite end of the LCD.
You will hear a sound similar to
hoofbeats coming from the piezo
sounder. Once the leading horse reach-
es the finish line, another sound is
made and at the same time, there is a
one-second pause to show a snapshot
of the winner.
This is followed by a display of the
results which includes the name of the
winning horse and the distance (num-
ber of LCD blocks) covered by each
horse (eg, Horse 1: 20; Horse 2: 16).
A tie is possible, in which case both
horses are listed as winning. After two
seconds, the display changes to show
the welcome message again and you
can play another game.
The circuit can be powered by a 5V

Horse racing game


DC power supply such as a USB charg-
er or plugpack. You can see a video of
the prototype in operation at: https://
youtu.be/SDTrEUfTreM
The software was written in BASIC
and compiled using BASCOM for AVR
microcontrollers. The source code (Tri-
ple-mode Horse Race Game.bas) and
HEX file can be downloaded from the
SILICON CHIP website.
Mahmood Alimohammadi,
Tehran, Iran. ($65)
Editor's note: the circuit for this entry
is virtually identical to that of the Du-
al-mode Digital Dice, by the same au-
thor, published in the November 2018
issue. The larger LCD screen and soft-
ware are the main differences.
Constructors may wish to add a
1N5819 in series with the supply for
reverse polarity protection.
Free download pdf