A LED Dice Using A PIC 16F84

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 14

m A die (plural dice, from Old French dé, from

Latin datum "something which is given or played´) is a


small throwable object with multiple resting attitudes,
used for generating random numbers or
other symbols.

m A traditional die is a cube (often with corners slightly


rounded), with each of its six faces showing a different
number. The design as a whole is aimed at each die
providing one randomly determined integer, in the
range from one to six, with each of those values being
equally likely.
Four colored dice showing all possible six sides
m ëe will design an electronic simulation of 2 dice,
implemented using LEDs. A single push button will
control the rolling of the dice in the following manner;
x ëhen the button is pushed for a short period (say less that 0.5
sec), the dice turn on, and display the result of the last roll.
x If the button is pushed for greater than about 0.5 Seconds,
both dice are cleared then roll independently, eventually
slowing, and stopping after the button is released.
x In all cases, the result is displayed for 50 seconds, and then
the dice turns itself off.
m
Opposing Corner dots (1) and (3)
appear simultaneously.
m Opposing Corner dots (2) and (4)
appear simultaneously.
m Middle dots (5) and (6) appear
simultaneously.
m The Central dot (7) operates
independently.

The good thing that this means is


that we can present a single die
display using only 4 output pins
on the micro. To display 2
separate dies, we only needed 8
pins.
m Driving LEDs with a
PIC microcontroller is a
simple exercise.
Because the outputs
can drive 50mA, we
can drive the LED
directly with a series
current limiting resistor
to protect the LED. The
diagram shows typical
connection details.
m A single push button
interface into a PIC can be
implemented simply by
connecting a push button
between the supply voltage,
(VCC) and an input that
provides an interrupt. The
figure provides an example.
Note that the input is held
µlow¶ by a 4k7 resistor to
ensure that random noise
picked up on the input pin
does not cause an input to
be recorded.
m In our circuit, the
microprocessor
consumes
approximately 7uA
while it is in its standby
µsleep¶ mode.
m The current
consumption will
increase to about
120mA during
operation
m First, the word that we want to write is loaded into the
µë¶ register, then the µë¶ register is written to Port B.
m ëe can use this sequence of operations to output the
bit pattern to display a dice roll of 6. From the
schematic diagram, we can see that the first die is
attached to Port A, bits 0 ± 3 in the following way;
m Port A(0) - Centre LED
m Port A(1) - Corner LEDs (1) and (3).
m Port A(2) - Corner LEDs (2) and (4).
m Port A(3) - Middle LEDs (5) and (6).
m To display the pattern for a 6, all corner LEDs, and
all middle LEDs are on, but the centre LED is off.
This equates to bit pattern of b¶00001110¶. So, to
display a 6, we simply execute the instructions:
m MOVLë B¶00001110¶
m MOVëF PortA
m Similarly, to display a 1 (the centre LED), we
would use;
m MOVLë B¶00000001¶
m MOVëF PortA
m In order to wake up from sleep mode, we need to
have an µinterrupt¶ occur. Interrupts can be caused
from a variety of sources, but they always signal some
external change.
m The LED Dice project that we are building has the
pushbutton connected to bit 1 of Port B (PB0). This pin
is also functions as an µinterrupt¶ input. ëhen the
voltage level on this pin changes, an interrupt is
generated, causing the PIC to stop whatever it was
doing, and to do something else. It is this interrupt that
causes the PIC to wake up from it¶s sleep mode.
m In our project, the easiest method that we can use to
generate a random number is to sample the internal
timer (TMR0), which is constantly incrementing at ¼ of
the clock speed (about 256KHz), and store it in a
variable continuously, as long as the button is held
down.
m Our PIC 16F84 microprocessor has 68 memory
locations that are able to be used as variables. To
define a variable, we simply declare a constant that
refers to a particular memory location, and store
numbers in that memory location as required.
u   

Tep Lascieras
Manalo, Daryl Jayson I.
Boyet Noche
Oblea, Jayson
Vivas, Jeff

You might also like