Step 1: What You Need
- Printed circuit (find files in the next step)
- Copper board
- Circuit board acid
- 1mm drill
- Soldering tools
- 1x PIC12F675 microcontroller + socket
- 7x 5mm LEDs
- 7x 470ohm resistors (1/8 watt)
- 1x 10k resistor
- 1x Simple push button
- 1x 3V coin battery + battery holder(I couldn't find a battery holder so I made it myself)
Step 2: Making the PCB
- Print the circuit on a glossy paper with a laser printer without scaling.
- Cut some copper board and clear it with sandpaper.
- Put the printed circuit on it.
- Press the hot iron on the board.
- Remove the papers.
- Soak boards in acid and wait till visible copper disappears.
- Wash the board.
- Drill the holes.
- Clear the board with sandpaper.
Step 3: Soldering Components
- Solder 470ohm resistors on the board (the resistor that is drawn on the IC is 10k not 470ohm).
- Solder microcontroller socket on the board in correct direction.
- Solder the LEDs on the board. Note that the cathode side is hatched.
- Solder the 10k resistor (the resistor on the IC) on its place on the back side of the board.
- Solder the button on the back side of the board to the terminals marked with letter B.
- At last solder two wires to the + and - terminals for the power supply.
Step 4: Attaching the Battery Holder
Solder the power supply wires to the battery holder.
Now attach the battery holder to the board on the button using some flexible material like paper and glue.
Note that at last you must be able to push the button by pushing the battery holder.
Step 5: Programming
Don't forget to:
- Set oscillator to internal RC without CLKOUT (INTOSC no CLKOUT)
- Disable power-up timer
- Disable watchdog
- Set MCLR to input pin
- Disable brown-out reset
Step 6: Make Your Dice Ready to Use
Now put the battery into the dice, place it on the ground, and tap on its head to roll.
The dice will be turned off automatically after about a minute.
Step 7: Let's Take a Look at the Code
Here's the code:
INTCON = %10001000 'Watch for port change interrupt
OPTION_REG = %11000111 'Enable timer0 with 1:256 prescalar
GPIO = 0 'Turn off all LEDs
TRISIO = %101000 'GP3 and GP5 are input other are output
IOC = %100000 'Watch for GP5 change
Dim number As Byte
Dim ledoff As Word
Dim gpioval As Byte
End 'Go to low power mode
If INTCON.GPIF = %1 Then 'If button is pressed
If GP5 = %0 Then
GPIO = 0
number = TMR0 Mod 6 + 1 'make a random number according to timer0
If number = 1 Then gpioval = %000001
If number = 2 Then gpioval = %010000
If number = 3 Then gpioval = %010001
If number = 4 Then gpioval = %010100
If number = 5 Then gpioval = %010101
If number = 6 Then gpioval = %010110
ledoff = 0 'turn off all LEDs for a moment
INTCON.T0IE = %1
INTCON.GPIF = %0
If INTCON.T0IF = %1 Then 'timer0 interrupt
ledoff = ledoff + 1
If ledoff = 1000 Then 'turn off all LEDs after about a minute
GPIO = 0
ledoff = 0
INTCON.T0IE = %0
If ledoff = 15 Then GPIO = gpioval 'display the number
INTCON.T0IF = %0