Professional Documents
Culture Documents
This document provides information for a quick start. The MPLAB IDE software
contains extensive help manuals under Help menu.
Enter a name for your new project (blink). The project name and the project directory
name do not have to match but they will for this exercise.
Use the Browse button to select the path to the directory you just created. Click OK.
Once you have completed entering the code, select File>Save and save the file in the
project directory as: blink.c.
The editor is context sensitive. As soon as the file extension is known, it shows different
colors and emphasis for reserved words.
Figure 4: Project Window showing blink.c in source file and 18f458b.lkr in linker script
9. Set paths
Before building the project, you need to specify several paths for the MPLAB IDE to
follow to find the files. Click Project>Build Options…>Project to open the
Build Options dialog box. Select General tab if it is not on the top already. Fill up the
include path and library path as specified below (assuming C18 was installed at the
default location C:\mcc18).
Figure 6: The left button is Make and the right one is Build All
The difference between Make and Build All is that Make performs the minimum required
steps and Build All deletes everything except the source files and rebuilds the whole
project. Normally, Make is sufficient to update the product after you make changes to
the source files. You should always use Build All if you make changes in the project
windows or build options.
If your file is compiled successfully, the messages will read like:
If your file did not compile successfully, error messages will appear in the output
window. Always scroll back to the beginning of the output window to be sure that you
did not miss any messages.
Double click on the error message in the Output window will bring you to the error in the
source file. A green arrow in the gutter on the left of the source file window points to the
line where the error was found (It may not be the location where error occurs).
If the errors were found after compilation, it may not be able to link the error to a specific
location in the source. Correct all the syntax errors and rebuild the project. Warnings are
errors that were deemed not critical to produce a product. It is advised that you always
read the warning messages and attempt to clean them up.
Figure 9: Double click the error message will bring to the location of the error which is indicated
by a green arrow in the left gutter
Figure 10: The simulation toolbar with the buttons starting from left: Run, Halt (gray), Animate,
Step In, Step Over, Step Out, Reset
Rest the mouse cursor over a toolbar button to see the tool tip of the buttons’ function.
Rather than mouse over the name each time you want to see the value of a variable, you
can open a watch window. The watch window will remain on the screen and show the
current variable values when the program execution halts. Watch windows may be found
under the View menu.
Figure 11: The Watch window. The value of counter was changed and indicated in red
Add variables: i, counter and PORTB in the watch window. You may click in the blank
area just under the last “Symbol Name” and type in the name of the variable, or you may
use the pull-down menu selection on the top of the window to choose the variable then
click “Add” button. Both i and counter are variables in C program and you will find
them to the right of Add Symbol button. PORTB is a special function register; you have
to find it next to Add SFR button.
After the variable is added, the display format may be modified by right click on the line
and select “Properties…”. Here, you may change the displayed format to decimal from
hexadecimal.
The values in the watch window do not get updated when the program is running. Only
when the program execution halts will they get refreshed. The values are displayed in red
when its content changed.
Since i is an autovariable in function delay, you need to step into delay before the value
becomes valid. Otherwise, “Out of Scope” is shown as its value.
12.4 Breakpoint
By double clicking on a line of code, a stop sign with a ‘B’ appears in the gutter to
indicate the breakpoint. If you run the program, the execution halts when encountering a
breakpoint. The green arrow will rest on the stop sign. (When the execution halts, the
line with the stop sign is NOT executed yet.)
Figure 12: The source file window during simulation. The stop sign with ‘B’ in the gutter indicates
a breakpoint; the green arrow indicates the next statement to be executed.
Figure 13: The Programmer toolbar with buttons starting from the left: Blank Check, Read,
Program, Verify, Erase
The output window may contain the following messages but you may ignore
them.
Figure 14: The PICSTART output window. The PICSTART Plus Units in the lab can not be
upgraded and will always show these messages.
6. Insert the device to be programmed in the ZIF socket and lock the device. Make
sure the device is in the socket with proper orientation. Reversing the device
orientation is known to be a sure way to destroy it.
7. Rebuild the project after the connection between the programmer and PC is
properly established.
8. Click Erase button to erase the device
9. Click Program button to program the information currently loaded in the
MPLAB IDE into the device. The operation progress is indicated at the left corner
of the status bar. Results will be displayed in the Output window.
10. While programming and verification are going on, the orange ACTIVE LED of
PICSTART will stay on. Do not remove the device when the orange LED is on.
11. When programming is complete, the orange ACTIVE LED goes off and you may
remove the device from the programmer and insert it in the circuit for testing.
12. Always check the output window for possible errors in programming before
proceed with your testing.
Figure 15: The PICSTART Plus auto select of memory range in MPLAB IDE can be used to
determine the program memory usage
Follow the procedure before to select PICSTART Plus as the programmer. (You do not
need to enable the programmer.) Select Programmer>Settings… in the menu to get
the following dialog box. When “Auto select memory areas and range” is selected, the
program memory range is indicated in gray below. Write down the start address and end
address. The program memory range changes as you change the program source. It
would be a good idea to use a much higher end address in case you forgot to look for the
new value. The start address shall always be 200.
Figure 16: The Export dialog box where the memory range is specified