28.12.2014 Views

Nuts & Volts

Nuts & Volts

Nuts & Volts

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

⇒ FIGURE 1.<br />

The connection setup.<br />

requested. For the<br />

hardware, the PIC16F876A<br />

fits the job perfectly.<br />

The PICBasic Pro<br />

compiler offers two ways to<br />

implement serial communication:<br />

the SEROUT and<br />

SERIN commands, which<br />

are the software implementation<br />

of serial “bit-banging”<br />

communication, and<br />

the HSERIN and HSEROUT<br />

commands, which implement<br />

the hardware serial<br />

port on the PIC that runs in<br />

the background.<br />

What I mean by background<br />

is the hardware<br />

serial port can send and<br />

receive serial data while<br />

a main loop of code is<br />

also running at the same time. I felt<br />

this was a little too advanced for<br />

the beginner, so I’ll use the<br />

SERIN/SEROUT here and save the<br />

hardware commands for another<br />

application.<br />

PROJECT DESCRIPTION<br />

The project I’ll present here may<br />

be simple, but it’s also a building<br />

block for bigger projects in the future.<br />

I’m going to control a bank of eight<br />

LEDs from the Hyperterminal terminal<br />

program found on most PCs<br />

running Windows. The serial cable<br />

will connect the PC’s serial port to an<br />

RS232 interface circuit built into the<br />

remote PIC/LED circuit. The interface<br />

circuit will adjust the signal voltage<br />

levels to what the PIC/PC need to see.<br />

At some point, I’ll introduce this<br />

same RS232 interface circuitry to program<br />

the PIC in-circuit via bootloader<br />

mode, but for now, all programming<br />

will be done with the EZPIC serial<br />

port programmer.<br />

Figure 1 shows what I’m trying to<br />

describe. The PC connects to the<br />

RS232 circuit through a straight-thru<br />

nine-pin cable. The RS232 circuit uses<br />

a standard MAX232 style chip with<br />

built-in charge pump to match the<br />

0-5V PIC signal and -12V to +12V PC<br />

signal. The PIC16F876A has the<br />

standard PIC circuit connections with<br />

a 4 MHz resonator and MCLR pull-up<br />

resistor. The LEDs are connected to<br />

Port B and are driven on with a high<br />

signal from the individual Port B pins.<br />

RS232 BASICS<br />

Serial communication can send<br />

any data you want as long as it comes<br />

in the form of bytes. It can take on<br />

many forms, and one is called the<br />

RS232 standard. In Figure 2, I show a<br />

typical RS232 signal format. The first<br />

pulse is low and that is called the<br />

start bit. After that, eight bits are sent,<br />

which is a byte of data. Following the<br />

data is a high bit, which is the stop bit<br />

or end-of-data indicator.<br />

Every character a computer can<br />

show has a numerical code associated<br />

with it, and there are 256 different codes<br />

(the maximum amount for eight bits).<br />

This just means that there are 256<br />

different characters that can be sent as<br />

a byte inside a serial message. This<br />

ASCII code table can<br />

be found with a simple<br />

Google search.<br />

This RS232<br />

signal format I<br />

described is known<br />

as 8N1 or eight<br />

⇒ FIGURE 2. RS232<br />

signal format.<br />

data bits, no parity check, and one<br />

stop bit. Later, we’ll set up the<br />

Hyperterminal program to receive<br />

8N1 data at a speed of 9600 bits<br />

per second.<br />

Since the PC and PIC have to<br />

communicate in the same language<br />

to understand each other, the width of<br />

the pulses is critical to determine if a<br />

pulse is actually multiple 1s or 0s,<br />

or a single bit. Timing is, therefore,<br />

very important to the success of<br />

communication.<br />

Matching the bit rate between the<br />

PC and PIC confirms the PIC and PC<br />

are talking the same version of the<br />

language. It’s like trying to watch an<br />

American citizen speak with a British<br />

citizen. They both speak English but<br />

sometimes they need a little help<br />

with interpretation.<br />

SOFTWARE<br />

The PICBasic Pro program is shown<br />

in Listing 1, which is available on the<br />

March 2006 79

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!