GETTING STARTED WITHPICs
THE LATEST IN PROGRAMMING MICROCONTROLLERS
■ BY CHUCK HELLEBUYCK
PIC HARDWARE INTERFACE
PROGRAMMING MICROCHIP’S PICS IS A LOT OF FUN, especially if you have a nice
development board with all the connections pre-wired for you. My BasicBoard,
built around the 40 pin Atom chip (16F877A with Atom bootloader installed),
was designed just for that purpose. A beginner could get a lot of programming
in before they ever have to build custom circuitry around their PIC micro-controller. What I’ve found from reader feedback is a lot of people are looking
for a little guidance with those custom circuits. I’m more than willing to help.
Let’s start with the basics. A PIC
needs four main connections to
run: Vdd (typically 5V), ground (Vss),
MCLR pull-up resistor, and an
oscillator. Some PICs offer an internal
oscillator option and also an internal
MCLR pull-up. That reduces the
connections down to Vdd and ground
(Vss). I’ll let you explore the data
sheets for that information and stick
with the four connections as shown in
Figure 1. I also throw in a standard
7805 regulator to produce the five-volt power. There are loads of other
five-volt regulators you could choose,
but the 7805 is so robust and cheap, I
still like to use it.
This is a great way to show an error
mode. Have one LED the color red and
the other LED green. When the pin 0 in
high and pin 1 is low, the green LED is
lit possibly to indicate everything is
running properly. When something
goes wrong — such as a sensor signal
lost or some other known problem —
then the I/O is reversed making pin 0
low and pin 1 high. This will light the red
LED and turn off the green LED.
Now take this concept a little
further and drive four LEDs from three
I/O pins as shown in Figure 3B. This
saves I/O pins and allows you to
control each LED individually. Table 1
shows how to light the various LEDs.
SWITCHES
High Side LED
LED On: High 0
LED Off: Low 0
Low Side LED
LED On: Low 0
LED Off: High 0
LEDS
These days, just about every project will have at least one LED connected to an I/O pin even if it’s just to indicate that the PIC is running. As simple
as that sounds, there are several ways
to do it. Most PIC I/O pins can supply
25 ma or sink 25 ma, so driving an LED
directly is pretty easy, as shown in
Figure 2. I show both a high side drive
and a low side drive. The high side supplies the power to the anode through a
current limiting resistor and the low
side supplies the cathode ground path.
Both work equally well, they just take a
little different code setup as shown.
Another
■ FIGURE 2 LED option is
to drive two
LEDs from
the same two
I/O pins, as
shown in
Figure 3A.
■ FIGURE 1
12 November 2006
Switches are another area that
initially seems straightforward, but get
more complicated when you look at the
hardware options. Switches can be high
side or low side activation that either
pulls an I/O pin high or
low, but there is a little
glitch to switches called
switch bounce. Inside a
momentary push button
switch, or most switches
for that matter, is a spring
steel conductor that
completes the connection
between two pins. When
you press the switch,
the spring metal contact
Green/Red Strategy
Pin0: High Pin1: Low Green on/Red off
Pin0: Low Pin1: High Green off/Red on
■ FIGURE 3