DIY
CIRCUITS
DIGITAL CLOCK
Programming PIC microcontrollers, part 3.
By Sparkle Labs
In parts 1 and 2 of our microcontroller primer (MAKE, Volume 04, page 158, “Microcontroller Programming,” and Volume 07, page 149, “Hello, World”), we got a PIC chip development system up and running, covered basic inputs and outputs, and left off by showing how to use a PIC chip by itself to control a simple pushbutton counter. In this article, we’ll show how to use a PIC along with other chips to make a digital clock.
Our two peripheral chips are the DS1305 Real Time Clock (RTC), which keeps track of the time, and the MAX7221, an LED display driver. Both are manufactured by Maxim Integrated Products, with datasheets available at maxim-ic.com. We’ll use the PDIP package versions, so they’ll fit into a breadboard.
Just like our microcontroller, these special-
purpose ICs have settable 8-byte registers that determine how they function. But peripheral chips don’t store and run programs on their own, so we can’t upload code to them and set their registers directly. Instead, we’ll program our microcontroller to tell these chips what to do. The chips’ datasheets explain how the microcontroller can communicate with them, as well as how they need to be connected into our circuit.
ICs exchange data over numerous communications protocols. Our clock will use Serial Peripheral Interface (SPI), a simple serial binary protocol that requires just four pins on the microcontroller, plus one more for each additional peripheral device. One pin sends data out to the peripheral(s), one pin receives data, a clock pin pulses high and low to mark each new send/receive cycle, and
Photograph by Sparkle Labs
134 Make: Volume 09
References:
Archives