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