PICBASIC PRO COMPILER
The PICBASIC PRO Compiler (referred to as the PBP hereafter) provides all the func- tions needed to program almost the entire family of PIC microcontrollers in a BASIC- like environment. This means that it allows you to write programs that read the inputs and write to the outputs in a simple and easy to learn way. It means that communications are simplified and the time it takes to get an application running is reduced many fold. It means that the programs are easier to follow and to debug (though debugging can get quite complicated even on these seemingly simple devices). The compiler sup- ports only integer math, but that is not a big handicap when we are working with these limited microprocessors. You need to select a much more powerful microprocessor if
mathematics is a major need for your application. In our particular case, where we are running encoded DC motors, this inhibits the implementation of the differential func- tion in the PID loop, as you will see later on.
It also means that the programs that are developed are longer than assembly language programs and slower in their execution than assembly language programs. There are also complications that have to do with the use of interrupts that have to be addressed, but these are beyond the scope of this book.
All the exercises and examples provided in the text are based on the PBP compiler. We will not go over the detailed instructions for using each of the PBP instructions in the text. It is expected and will be assumed that you will have purchased the software and thus will have the manual for the compiler in hand. However, there are some commands that can be complicated to implement and we will spend time on these.
The compiler is kept current by microEngineering Labs for the latest MCUs released by the Microchip Technologies Corporation. The LAB-X1 uses the 16F877A MCU, and it is the MCU of choice though other MCUs that have a general pin-for-pin compatibility with this MCU may also be used. All the experiments and exercises in this book will use the PIC 16F877A only. The compiler addresses almost all the capa- bilities of this MCU, and we will cover the use of all the devices that are provided on the LAB-X1 board. (The 18F4331 is used for the encoder attached motors only.)
Detailed instructions for installing the software on your PC are provided in the compiler book. It is not necessary to install the software from a DOS prompt. It is much easier to install it under Windows with the Install.exe or equivalent file pro- vided in each package.
The software can be set up so that one mouse click will transfer the program from the editor to the PIC microcontroller and run the program in the PIC. In order to do this you have to add a couple of functional codes to the programmer operating system. These codes tell the programmer to load the program and execute it. Installing the software was covered in detail in Chapter 2.
A SIMPLE EXAMPLE PROGRAM USING PIC BASIC
A program that makes the LEDs blink on and off is usually the first program written by beginners. The purpose of the program is not to blink the LEDs but rather to allow you to go through the programming procedures in a simple and straightforward way and get a result that is easy to verify. Once you have the LEDs blinking, you will know that you have followed all the steps necessary to write and execute a program. Larger, more complicated programs may be much more difficult to write and debug, but they are no more difficult to compile, load, and run.
Following are the keystrokes for writing and running the Blink the LEDs program: