Page 171 - PDA Robotics Using Your Personal Digital Assistant to Control Your Robot
P. 171
PDA 07 5/27/03 8:44 AM Page 147
Chapter 7 / Programming the PIC16F876 Microcontroller
If the file CCSC.INI exists in the same directory as CCSC.EXE, then
command line parameters are read from that file before they are
processed on the command line. For example, to compile the source
code and generate a .HEX file for PDA Robo, we would type the fol-
lowing from the PICC directory.
CCSC +FM +P C:\PROGRA~1\PICC\PDABOT.C
The Source Code
This section explains in detail the C language constructs used in the
source code of the program running on the PIC16F876. I have
offloaded most of the processing to the PDA so the code on the micro-
controller is very straightforward. To quote Albert Einstein, “Make
things as simple as possible, but not simpler.” The software waits for
a command from the PDA, signaling each motor to rotate forward,
reverse, or stop and a command prompting PDA Robot to send the
range data to the PDA. For example, the PDA can instruct the craft to
turn by sending two commands, a “motor 1 forward” command and a
“motor 2 reverse” command. This section describes an optimization to
the code and includes the HEX listing that can be copied to a file and
burned to the PIC16F876.
The following is the code listing for pdabot.c.
// PDABOT.C
//
// Software for the PIC16F876 used to controlPDA Robot
//
// Author: Douglas H Williams
// PDA Robotics: McGraw-Hill 2003
//
#include <16f876.h>
//
// We are using a 20 MHz oscillator so set the clock accordingly
//
#use delay(clock=20000000)
//
// Set pins B0 & B1 as our RS232 port which are connected to the
// MCP2150 IrDA Protocol Stack Controller
//
#use rs232(baud=115200, xmit=PIN_B1, rcv=PIN_B0, stream=PDA)
147