The clock never became much more than an idea in the back of my mind until I decided to make it
for my Senior Project to complete my
Electrical Engineering degree.
I wanted to use a microcontroller with
the lowest pin count possible. I figured I
could drive the LEDs with 14 I/O pins
using Charlieplexing (more on that later).
Two more I/O pins would be used to read
two pushbuttons used for setting the
I had already picked out the
microcontroller that I wanted to use. I had
been playing around with Microchip
products for a number of years, so I chose
the PIC16F627A. It was an 18-pin
controller with 16 I/O lines — the exact
number of I/O lines that I needed.
However, my professor insisted I add an alarm feature.
Now I needed to add a buzzer for the alarm and probably
a couple more pushbuttons to set it. Plus, one more LED
to indicate when the alarm was turned on would be
I decided to include another LED for a PM indicator,
so an alarm that was set for say, 6:00 AM wouldn’t sound
at 6:00 PM. I then considered that I would be running the
microcontroller with its internal oscillator that probably
wasn’t all that stable; the clock wouldn’t keep accurate
time. It would be much more precise to monitor the 60
Hz from the electric utility for the time base (refer to the
sidebar). How many more I/O pins would now be
Although Microchip has plenty of microcontrollers
that have more than enough I/O pins for this project, I
really didn’t want to increase the pin count of the
controller! Was it actually possible to drive 182 LEDs and
a buzzer, and monitor four pushbuttons and the line
frequency with only 16 I/O pins? Or, was my pride going
to get me into trouble (why couldn’t I just add a few pins)?
The buzzer would definitely need its own dedicated
I/O line. The LEDs would require 14 I/O pins. That would
leave only one pin to read the pushbuttons and monitor
the line frequency.
A couple of ideas occurred to me. I had the vague
notion that I could connect the pushbuttons and the 60
Hz signal through a resistor network to the I/O pin. An
analog input to detect changes in voltage could be used
to interpret the button combination currently being
pressed, and at the same time, monitor the 60 Hz line.
The other thought was to use four of the LED I/O pins to
strobe the buttons, and using diodes for isolation, connect
the buttons and 60 Hz together into the I/O pin.
A cursory look at the datasheet for the PIC16F627A
showed that it had all the necessary features to run the
clock. It had 16 I/O lines with high current capability for
direct LED drive, an internal oscillator, and analog input
capability. If the 1K bytes of program memory wasn’t
enough, either the PIC16F628A or PIC16F648A could be
used, which have 2K or 4K bytes of program memory,
respectively. Otherwise, they’re identical to the
Driving 182 LEDs with
Only 14 I/O Pins
Complementary LED drive — also known as
Charlieplexing — allows a large number of LEDs to be
controlled with a relatively small number of I/O pins as
previously mentioned. Charlieplexing is named after
Charlie Allen of Maxim Integrated.
He used this technique to create LED driver ICs for
Maxim in the 1990s (
www.maximintegrated.com/en/app-notes/ index.mvp/id/1880). The idea behind
Charlieplexing is simple: Given every possible
combination of two I/O ports, connect two LEDs between
them, with the two LEDs in parallel and in opposite
Another way to look at Charlieplexing is to consider a
standard 4x4 matrix of LEDs (Figure 1). There are four
rows and four columns, requiring a total of eight I/O lines
to control 16 LEDs. You’ll notice that each column has a
March 2018 23
Post comments on this article and find any associated files and/or downloads at
■ FIGURE 1. Standard 4x4 LED matrix.