serout portc.6, 2, [“LED Chosen: “, #new, 10, 13]
The program pauses to allow the PC to get the data. I
just threw this in as a precaution since some PCs can run a
little slow.
supply five volts and ground throughout the breadboard. Both
the RS232 and LED module have pins that plug into the power
rails so I save more jumpers. Okay, it goes beyond being lazy.
If I had a dollar for every mis-wired jumper that left me pulling
my hair out blaming my code, I could probably retire.
Pause 100
HYPERTERMINAL
Now the LEDs are controlled with simple HIGH and
LOW commands. The previous LED value is stored in the
variable “old” and the LED is turned off with a LOW signal
on that pin.
low old
A HIGH signal on the “new” LED value just received
turns the selected LED on.
high new
The “old” variable is made to match the “new” variable so
the next time through, the program will shut off the lit LED.
old = new
The last step is to jump to the top of the program at
the “main” label so it can all be done again.
goto main
HARDWARE
I cheated a little on the hardware setup shown in
Figure 3. I like to build most of my projects on breadboards, so I developed a bunch of breadboard modules. I
used three of them here which made the setup go faster.
You can easily build the same setup
with discrete components.
The PIC16F876A is plugged directly into the breadboard and has the resonator and pull-up resistor installed
with it. The RS232 interface circuit is
one of the breadboard modules which
is shown connected to the serial cable.
The LEDs are another breadboard
module and the connection header
lines up perfectly with the PORT B pins
of the PIC, saving me jumper wires.
The PIC gets its five-volt power from
the breadboard rails which are connected to one of my breadboard power
modules. This makes it easy to connect
an AC adapter to the breadboard.
The power module has pins that
line up with the breadboard rails to
⇒ FIGURE 7. The final working screen
showing the communication lines the
PIC sent out and my response.
Setting up Hyperterminal for proper communication
takes a few steps. The first step is to open Hyperterminal
and you will be asked to open a new connection. Actually,
this is the first step in Windows 98. If you use XP or some
other version of Window’s Hyperterminal, you’ll be asked
for a phone number and other information before you get
to the screen in Figure 4. Just enter a bogus phone number
and follow through until you get to the screen shown.
The screen in Figure 4 sets up the connection file
name. Enter the connection name you want and click “OK.”
Then the connection setup window will pop up asking for
your connection method, as shown in Figure 5 (you might
have to go through a few more bogus entry screens). From
the selection window, choose the serial port you want to
connect to. In my case, it was COM1.
Click “OK” and you’ll be asked to choose your
connection format. Figure 6 shows the setup as 9600 bits
per second, eight data bits, no parity, and one stop bit. You
also want to make the flow control selection “none.” After
you click on “OK,” you’re ready to receive data.
The final working screen is shown in Figure 7. It shows
the communication lines the PIC has sent out and shows
my response, as the PC user, three different times. The last
one chose to turn on the fourth LED, as shown lit in the
hardware picture of Figure 3. The best way to start is to get
everything connected and start the Hyperterminal connection. Then turn off the PIC circuit and back on so the “Enter
which LED to light (0-7):” shows up on the terminal screen.
March 2006 81