LED Dice coded in C targeted via XC8 C compiler for PIC microcontroller

As Christmas is now on the horizon, I thought it might be fun to design an electronic dice, to give as presents to your family, or just use whilst playing traditional family games during the holidays.

This dice project has seven LED’s which can display the possible outcomes of rolling the dice…in other words, 1, 2, 3, 4 , 5 or 6. A single button instigates the ‘rolling’ of the dice, as the outer six LED’s rotate to indicate motion. When the button is released, the dice value is displayed on the LEDS’s, flashing at a frequency of 2.5Hz.

Here are a few pic’s of the dice in action:



Here the dice prototype is in reset. All LED’s are off.


Here we have pressed the button and been returned the value of 3 for our roll of the dice.


Now we have pressed the button again and been returned the value of 5.


The LED’s rotate as the button is pressed.

The software is very simple. The rotating LED’s when the button is pressed uses a Timer0 interrupt routine to illuminate the six LED’s on the edge of the dice to indicate the rolling of the dice. When the button is released, the LED’s display the value of your roll of the dice.

Here is the C source code which was compiled using Microchip’s XC8 compiler, targeted at a 16f690 microcontroller. dice-c

For those of you who wish to construct this project, here is the circuit diagram (hand drawn). dice_circuit_diagram

Have fun and Merry Christmas!

This entry was posted in Other Tech on by .

About Phil Glazzard

Phil describes himself as an 'audio nut from an early age', and is the director of the company as well as our in-house repairs engineer and custom installer. He takes interest in all music forms and spends most of his free time playing the drums, or geeking it up with PIC microcontrollers. He can't resist a gadget.

Leave a Reply

Your email address will not be published. Required fields are marked *