■ FIGURE 4. PIC-based
control system circuit.
design and offers a lot of
flexibility in the user interface,
it wasn’t really true to my
original intent to create a
drop-in replacement for the
multitude of electrical switch
boxes typically used to control
track switches. I decided to
take the decoder-driver circuit
from the PC-based system and
add a PIC microcontroller and
liquid crystal display (LCD) to
make a self-contained controller
(Figure 3). The controller
described here operates eight
track switches and can easily
be expanded to control 16
using the same basic operating
principles.
PIC Software
Development
The popular Microchip
PIC16F8761 forms the heart of
this project, and flowing through
that heart is the code in Listing 2
(file available on the Nuts &
Volts website). This code
performs the same three main
tasks that the PC-based software
performs and, in addition,
monitors three switch inputs
and drives the two-line by 24-
character parallel-mode LCD.
The three pushbutton
switches making up the user
interface include an up button
to increment the track switch
number, a down button to
decrement it, and an enter
button to move the selected
track switch. All three buttons
have a repeat action when held
down, to scroll through the
track switches or cause one
switch to move repeatedly (not
very useful, but fun to watch
for a few seconds). The code
determines which switch is
pressed by checking the value
of PORTB, which represents
the state of all eight Port B I/O
lines as one value. Pins PortB. 5
through PortB. 7 are unused and
always high, while PortB. 3 (the
enable output for the LCD) is
42
August 2008