Confirming Pages
336 CHAPTER 7 Microcontroller Programming and Interfacing
7.10 PRACTICAL CONSIDERATIONS
Throughout this chapter we’ve seen how to design and program microcontroller-
based systems. As with most things in the “real world,” when you actually construct
circuits and implement software, things don’t always work perfectly. Lab Exercises
9 through 11 provide experiences that will help you develop some of the skills
necessary to be successful. The best advice anyone could give concerning design-
ing a complicated microcontroller-based system is to follow a methodical design
procedure as documented and demonstrated in Section 7.9 . It also helps to have
and follow a detailed procedure for the specific development system you are using.
Internet Link 7.11 provides the detailed procedure necessary for working with
Microchip PIC microcontrollers programmed in PicBasic Pro, using the PicStart
Plus programming hardware.
7.10.1 PIC Project Debugging Procedure
The following check list and items of advice can be helpful when debugging soft-
ware and trying to get a PIC circuit to function properly:
1 . Before writing and testing the entire code for your project, always start with
a very simple program (e.g., the flash.bas program in Section 7.5.1 ) on your
PIC(s) to first make sure all necessary components and wiring are in place to
allow the PIC(s) to run.
2 . Once the PIC is known to be running properly, incrementally add and test por-
tions of your code, one functional component at a time. In other words, modu-
larize your software and independently develop and test each module (i.e.,
don’t write the entire program at once, expecting it to work).
3 . Use LEDs to indicate status and location within your program when it is run-
ning and to indicate input and output states.
4 . Be aware of the different characteristics of the I/O pins on the PIC. Refer to
Section 7.8 to see how to properly interface to the different pins for different
purposes.
5 . Be aware that PicBasic Pro commands totally occupy the processor while they
are running (e.g., the line after a SOUND command is not reached or processed
until the SOUND command has completely finished its action).
6 . If you are using a PIC with no internal oscillator (e.g., the PIC16F84), make
sure your circuit includes the proper clock crystal and capacitor components. If
you are using a PIC with an internal oscillator (e.g., the PIC16F88), make sure
you have included the necessary initialization code (e.g., see the code template
for the PIC16F88 available in Internet Link 7.17).
7 . Make sure you carefully select all of the configuration bit settings when down-
loading code to a PIC, so the oscillator, timers, and selected pin functions are
defined properly. This can be done manually each time a PIC is reprogrammed
(as documented in Internet Link 7.11), or you can define all of the settings in
your code as described in Internet Link 7.18.
Internet Lin
7.11How to
program a PIC
Internet Lin
7.17PIC16F88
code template
7.18Setting
configuration bits
in code
alc80237_ch07_258-345.indd 336alc80237_ch07_258-345.indd 336 12/01/11 12:52 PM12/01/11 12:52 PM