Pfad: Home =>
AVR overview =>
Applications => Dice ATtiny13
Tumbling dice with an ATtiny13
This application describes a cute, real tiny cube, a real rolling dice. It is a
small exercise for programming an AVR in assembler and a pretty give-away from
those that are knowing how to program and to solder electonic devices and for those
that love to play with a die.
That's all: seven LEDs, seven 100Ω resistors, a 10k resistor for the Reset
input, a pushbutton for starting the die and a small swith to prevent the battery
from unloading in long pauses between two games, two AAA batteries with a battery
case and a 100nF ceramic condensator. All in all parts for max six US-$. On the
right the LED numbers in the scheme.
The software for the timer is listed in HTML format here
or as Assembler source code here.
The software works as follows:
This is the layout of the PCB.
- Following the reset the LED ports are switched off (all LEDs on) and the
pull-up resistor on the pushbutton i9nput is switched on. Then a timing loop
is started. At its end the input on the pushbutton port is stored in the
flag register (tumbling on or off). The interrupts for the pushbutton input
are enabled. Then the timer is started and interrupts from the pushbutton
and the timer are enabled. Then the processor is send to sleep.
- The timer runs in CTC mode from 0 to 5 with a prescaler of 64
continously. On every restart of the timer a 16-bit-counter in R25:R24
advances by one.
- If the pushbutton gets pressed, an interrupt is triggered. The service
routine sets a flag in the flag register in R17.
- After waking the processor up it is checked if tumble mode is active. If
that is the case, and if the 16-bit-counter has reached a certain delay
value, the next die value is displayed and the tumble counter is decreased.
If that reaches zero, the tumble active flag is cleared.
- If tumbling is not active, the flag resulting from the pushbutton interrupt
is checked. If the flag is set, it is cleared, the current timer byte is
read (timer value), converted via a table to a die value and displayed. If
tumbling is enabled, the lower bits of the 16-bit-counter are converted
to the number of tumbles, stored in the tumble counter and tumbling is
- If the 16-bit-counter reaches a value of 20 seconds, the LEDs are
Linux users now have an easy life: they open the GIF image with Gwenview,
select Printing from the menue, in the print dialog they select Image
settings and Enlarge and type in 80 by 50 millimeters, insert a transparent
film sheet into the printer and start printing. All others have to downsize
the output on their printer in a trial-and-error mode until the image
has exactly these margins.
If the sheet is ready, we start to expose an exactly cutted piece of
foto-positive-PCB. We can use the sunlight, a UV lamp or the UV exposure
device described elsewhere on this webpage to expose the piece. The
transparent sheet should be placed on the piece so that the letters on it
are read in perfect shape.
The PCB piece is now devellopped in sodium hydroxide solution (12 g per litre).
Then the piece is flushed with water and smashed into our favoured etch
solution (I prefer iron-III-chloride). Looks really like already consumed,
but etches perfect. After a good have an hour this evolves:
With a drilling machine the 0.8, 1.0 and 3.0 mm holes in the PCB are excavated.
The component side now looks like this:
And so the components are assembled:
The complete PCB looks like this:
Now only the batteries are missing.
©2012 by http://www.avr-asm-tutorial.net