
This code can be optimized by having the PDA simply send a byte that
represents the state of the pins. By doing this, we can replace the six “if”
commands used to set the pins and the state of the motor with the line:
OUTPUT_B(value);
If we convert the number to binary, you can see that we need the first
four bits, and the fifth bit can be used to represent a request for the
rangefinder data. So if the value is less than 64, we know it is a motor
command, and if higher, a request for the range.
010100 (binar y) = 20 (decimal) = Both motors moving for ward
101000 (binar y) = 40 (decimal) = Both motors moving Reverse
…
000000 (binar y) = 0 (decimal) = Both motors stopped
1000000 (binar y) = 64 decimal = The PDA has requested the range data.
The code preceding was written using Notepad and saved as pdabot.c
in c:\Program files\picc\pdabot. The next step is to invoke the com-
mand line compiler. When you use the following command in a com-
mand prompt from the picc directory, the +P flag instructs the com-
piler to leave the compilation window displayed when it is complete.
This allows you to see if any errors were detected in the code and on
what line the compiler was having the problem.
CCSC +FM +P C:\PROGRA~1\PICC\PDABOT\PDABOT.C
Figure 7.5 shows the command prompt with the CCSC command line
used to invoke the compiler and compiler the code to the .HEX file
that we will burn onto the PIC microcontroller.
The compiler displays a window, shown in Figure 7.6, indicating the
status of the compilation and information regarding the memory usage
of the device.
The following is the compiled hex listing for the above source code
that is loaded into the memory of the PIC16F876.
0000- 3000 008a 283f 0000 3008 00f7 1683 1406
0008- 1283 1806 2809 01af 17f7 281c 13f7 281c
0010- 1003 1806 1403 0caf 1777 281c 1377 0bf7
0018- 2810 082f 00f8 2829 3016 1bf7 3006 00f8
0020- 0bf8 2820 0000 0000 1bf7 280e 1b77 2816
0028- 2810 118a 120a 2862 302f 0084 0800 1903
0030- 283e 3006 00f8 01f7 0bf7 2834 0bf8 2833
0038- 307b 00f7 0bf7 283a 0b80 2831 3400 0184
Chapter 7 / Programming the PIC16F876 Microcontroller
151
PDA 07 5/27/03 8:44 AM Page 151