SERVO 08.2014 47
flash an LED once a second, but now using everything
we’ve learned about the compare module. So, don’t let its
simplistic nature fool you; the journey is far more important
than the destination.
Notice how the program changes modes to alternately
set or clear the CCP1 pin. The same circuitry of Figure 7 is
also employed in Exercise 3 to flash that LED. In this case,
we’re using software generated interrupts only.
Exercise 3 is particularly interesting, as it uses an
outboard crystal to generate one second interrupts
independently of the PIC’s main internal system clock (as
shown in Figure 8). This could serve as the heart of a real
time clock. The seven-segment LED unit displays the digits
0 through 9, incrementing once per second.
When I ran it, I found that it lost four seconds in a
day — probably due to stray capacitance on the breadboard,
among other things. Wristwatch type (tuning fork)
crystals really do require careful circuit board layouts for
With that, we’re out of space, but certainly not finished
with further experiments and applications of the compare
module. If you take the time to review Figures 1 through
study the heavily commented source code, and actually run
the experiments, you should have a good grasp of the
compare module and be all set to continue on your own —
even further taming that daunting PIC datasheet! SV
Figure 8. Schematic
for Exercise 3.