Confirming Pages
7.9 Method to Design a Microcontroller-Based System 311
6. Decide on a programming language. You can write the code in assembly lan-
guage or in a high-level language such as C or PicBasic Pro. We recommend
PicBasic Pro for most applications. Assembly language is a better option only
when extremely fast execution speed is required or if memory capacity is a
limiting factor. C might be a better choice if the solution requires complicated
calculations, algorithms, or data structures.
7. Draw the schematic. Draw a detailed schematic showing required compo-
nents, input and output interface circuitry, and wire connections. If using the
PIC16F84, Figure 7.4 serves as a good starting point.
8. Draw a program flowchart. A flowchart is a graphical representation of the
required functionality of your software. Figure 7.20 illustrates a set of build-
ing blocks that can be used to construct a flowchart. The flow control block
is used as a destination label for a goto branch or a loop (e.g., For . . . Next or
While . . . Wend ). The functional block represents one or more instructions that
perform some task. The decision block is used to represent logic decisions.
Design Example 7.2 illustrates how a typical flowchart is constructed.
9. Write the code. Implement the flowchart in software by writing code to cre-
ate the desired functionality.
10. Build and test the system. Compile your code into machine code and down-
load the resulting hex file to the microcontroller. This can be done using a pro-
gramming device available from the manufacturer (e.g., the PicStart Plus serial
programmer available from Microchip). Internet link 7.11 points to the detailed
list of steps required to create, compile, and download code using PicBasic
Pro, MPLAB software, and the PicStart Plus programmer. The procedure is
also presented and used in Lab Exercise 9. After downloading the code, assem-
ble the system hardware, including the microcontroller and interface circuitry.
Then, fully test the system for the desired functionality. We recommend you do
steps 9 and 10 incrementally as you build functionality, carefully testing each
addition before continuing. For example, make sure you can read and process
an input first. Then add and test additional inputs and incrementally add and
test output functionality. In other words, do not try to write the complete pro-
gram on the first attempt!
For more advice on designing, building, and testing microcontroller-based sys-
tems, including advice on how to select a power supply, see Section 7.10 .
Internet Lin
7.11How to
program a PIC
Lab Exercise
Lab 9Pro-
gramming a PIC
microcontroller—
part I
Figure 7.20 Software flowchart building blocks.
Y
N
flow control
label block
functional block
(set of instructions)
decision block
(If . . . Then . . . Else)
alc80237_ch07_258-345.indd 311alc80237_ch07_258-345.indd 311 12/01/11 12:52 PM12/01/11 12:52 PM