⇒ FIGURE 1.
The connection setup.
requested. For the
hardware, the PIC16F876A
fits the job perfectly.
The PICBasic Pro
compiler offers two ways to
implement serial communication: the SEROUT and
SERIN commands, which
are the software implementation of serial “
bit-bang-ing” communication, and
the HSERIN and HSEROUT
commands, which implement the hardware serial
port on the PIC that runs in
the background.
What I mean by background is the hardware
serial port can send and
receive serial data while
a main loop of code is
also running at the same time. I felt
this was a little too advanced for
the beginner, so I’ll use the
SERIN/SEROUT here and save the
hardware commands for another
application.
standard PIC circuit connections with
a 4 MHz resonator and MCLR pull-up
resistor. The LEDs are connected to
Port B and are driven on with a high
signal from the individual Port B pins.
RS232 BASICS
PROJECT DESCRIPTION
The project I’ll present here may
be simple, but it’s also a building
block for bigger projects in the future.
I’m going to control a bank of eight
LEDs from the Hyperterminal terminal program found on most PCs
running Windows. The serial cable
will connect the PC’s serial port to an
RS232 interface circuit built into the
remote PIC/LED circuit. The interface
circuit will adjust the signal voltage
levels to what the PIC/PC need to see.
At some point, I’ll introduce this
same RS232 interface circuitry to program the PIC in-circuit via bootloader
mode, but for now, all programming
will be done with the EZPIC serial
port programmer.
Figure 1 shows what I’m trying to
describe. The PC connects to the
RS232 circuit through a straight-thru
nine-pin cable. The RS232 circuit uses
a standard MAX232 style chip with
built-in charge pump to match the
0-5V PIC signal and -12V to +12V PC
signal. The PIC16F876A has the
Serial communication can send
any data you want as long as it comes
in the form of bytes. It can take on
many forms, and one is called the
RS232 standard. In Figure 2, I show a
typical RS232 signal format. The first
pulse is low and that is called the
start bit. After that, eight bits are sent,
which is a byte of data. Following the
data is a high bit, which is the stop bit
or end-of-data indicator.
Every character a computer can
show has a numerical code associated
with it, and there are 256 different codes
(the maximum amount for eight bits).
This just means that there are 256
different characters that can be sent as
a byte inside a serial message. This
ASCII code table can
be found with a simple Google search.
This RS232
signal format I
described is known
as 8N1 or eight
⇒ FIGURE 2. RS232
signal format.
data bits, no parity check, and one
stop bit. Later, we’ll set up the
Hyperterminal program to receive
8N1 data at a speed of 9600 bits
per second.
Since the PC and PIC have to
communicate in the same language
to understand each other, the width of
the pulses is critical to determine if a
pulse is actually multiple 1s or 0s,
or a single bit. Timing is, therefore,
very important to the success of
communication.
Matching the bit rate between the
PC and PIC confirms the PIC and PC
are talking the same version of the
language. It’s like trying to watch an
American citizen speak with a British
citizen. They both speak English but
sometimes they need a little help
with interpretation.
SOFTWARE
The PICBasic Pro program is shown
in Listing 1, which is available on the
March 2006 79