Datasheet

PICkit™ 3 Debug Express
DS41370C-page 18 © 2009 Microchip Technology Inc.
3.1.3 Building and Programming the Lesson 1 Code
Build the lesson code in an executable memory image by selecting Project > Build All
in the MPLAB IDE. The memory image is stored in a .hex file in the project directory.
The results of the build will be shown in the Output window in the MPLAB IDE
workspace under the Build tab. The calls to the MCC18 compiler and Linker are
shown, along with any errors that may occur. If the build is successful, the Output
window will show BUILD SUCCEEDED, as in Figure 3-9.
FIGURE 3-9: MPLAB IDE OUTPUT WINDOW BUILD RESULTS
To program the code into the PIC18F45K20 microcontroller, the PICkit 3
Programmer/Debugger is used. Select the PICkit 3 as a programmer in the MPLAB IDE
with Programmer > Select Programmer
> 4 PICkit 3.
This will create a new tab in the Output window for the PICkit 3 programmer, where
messages from the programmer are displayed. The PICkit 3 will be initialized and
should report finding the PIC18F45K20 microcontroller on the demo board as shown
in Figure 3-10A.
The PICkit 3 must be configured to supply power to the demo board, if not, the PICkit
3 will not see the target (as evidenced by the error message in Figure 3-10A). Use
Programmer > Settings...
to display the window appearing shown in Figure 3-10B.
Navigate to the Power tab and use the slider bar to set the output voltage to 3.25V,
check the box labeled “Power target circuit from PICkit 3” and press the OK button.
Once power to the target is enabled, the device ID of the PIC18F45K20 will be
displayed (last line in Figure 3-10A).
Note: If an error that the include file p18f45k20.h cannot be found is generated,
this usually means that MPLAB C was installed without checking the Add
header file path to MCC_INCLUDE environment variable option during
setup. It is recommended to re-install MPLAB C with this option checked.