Low-Cost Microcontrollers
Enable Electronic “Microdice (μDice)”
by Marc McComb
A few months back, one of the engineers at
Microchip came up with a simple little design
using a low-cost, Baseline PIC16F57
microcontroller (MCU). The idea used
inexpensive parts such as LEDs and p
ush-buttons to create an electronic dice board,
which the engineer nicknamed microdice, or
“μDice.” A basic concept was used for the design
— push a button and a value between 1 and 6 is displayed on seven LEDs connected
to one of the ports. There is nothing overly complex about the circuit, and the real fun
happens when developing the firmware. Recently, I sat down with one of the μDice boards
we made and developed some firmware ideas that are detailed in this article.
Hardware
First, let’s talk about the hardware
involved with this project. The
PIC16F57 is a 28-pin MCU with 2K
instructions of Flash program memory.
The project makes use of the three
general-purpose input/output ports
(A, B, and C), as well as an eight-bit
timer (Timer0).
Taking a closer look at the
schematic in Figure 1, the lower two
PORTA pins connect to two pushbuttons (SW1 and SW3) that are pulled
up to V+. Each pushbutton is used to
roll one of two LED die displays
connected to PORTB and PORTC.
The MCU recognizes a pushbutton
press when that particular pin is driven
to ground or a logic LOW. RA3 is
connected to a buzzer
used to generate a
clicking sound while
the pushbuttons are
pressed, to simulate
the “shaking” of dice.
The remaining pins are
connected as recommended in the
datasheet for the PIC16F57.
This application does not require
precise timing. Therefore, the MCU
uses an RC oscillator by connecting a
10 K resistor and 1,000 pF capacitor in
parallel to the OSC1/CLKIN pin (the
PIC16F57 will need to be configured
for RC oscillator mode in the
firmware). SW2 on the schematic
connects to the MCLR/Vpp pin. PIC
MCUs have the ability to have an
externally-triggered RESET generated
by driving the MCLR/Vpp pin to
ground. On any RESET, the firmware
code restarts execution from the
beginning.
PHOTO 1. The board.
Note: The Microchip name and logo,
MPLAB, and PIC are registered trademarks of Microchip Technology, Inc., in
the USA and other countries. In-Circuit
Serial Programming, ICSP, and PICkit
are trademarks of Microchip Technology,
Inc., in the USA and other countries. All
other trademarks mentioned herein are
property of their respective companies.
Finally, notice the P1
header connected to
various pins on the
MCU. This implements
an in-circuit serial
programming (ICSP)
configuration, which
allows the firmware to
46
January 2008