Mplab Xc8 Getting Started Guide
Mplab Xc8 Getting Started Guide
Xc8
Getting Started
Guide
CREATION OF A PROJECT IN
MPLAB X IDE:
This section describes how to create a project in MPLAB X
IDE using the MPLAB XC8 C Compiler.
The process is explained in the following steps:
Step 1 sets the project type.
Step 2 selects the target device.
Step 3 selects the device header.
Step 4 selects the tool to run the project code.
Step 5 is only applicable to some debugger tool selections.
Step 6 selects the tool to compile the source code.
Step 7 specifies the project name and path.
Step 8 completes creation of the project.
To differentiate the current project in the IDE (when multiple projects exist)
as the main project, click Set as main project.
Foundation Code:
The code presented here is actually a small program that could be the
basis for all of your MPLAB XC8 projects. Although it could be
construed as trivial, the code is entirely valid, and compiles and
executes, as required
The code creation process is explained in the following linked steps:
Step 1 creates a new source file.
Step 2 enters a suitable name for the source file.
Step 3 adds skeleton code to the new file.
Step 4 saves your work.
This initial code can be used to start every project built with MPLAB
XC8. C. Every C program must have one, and only one, function called
main(); however, the exact prototype for this function can vary from
compiler to compiler. For all MPLAB XC compilers, you may use the
prototype shown above. Since main() returns an int, there must be a
return statement with a return value specified. The value 0 indicates
that main() returned successfully.
The inclusion of the header file, , allows code in this source file to
access compiler- or device-specific features. Since such access is
commonplace, you will need to include it into virtually all of your
source files.
COMPILATION:
As mentioned previously, the new program is a valid C program. This
means it can be compiled. This section explains how to build code.
MPLAB X IDE knows which compiler to execute when building your
source code, but options can be used to alter how the compiler
operates. The default options are acceptable for most projects. If you
do need to adjust the compiler options, you can do so from the Project
Properties dialog. Open this dialog using the top button on the left in
the project dashboard, as seen in Figure 1-11. From this dialog you
can also change other project attributes, such as the device or
compiler associated with your project.
There are several ways to execute the compiler. There are buttons on
the toolbar to enable quick access to the different build operations,
but you can also access these from the Run and Debug menus. Some
operations only build your code; others build and then execute your
code. Both the build and run steps can be made in either a release or
10
debug mode.
Debug mode operations enable the debug executive on your device.
This allows access to debugging features like breakpoints. For the
debug executive to be active, it must utilize some of the devices
memory that normally would be available for your code. Debug builds
ensure that this memory is reserved for the debug executive.
Release mode operations do not allow any debug features to be used,
but all the device memory is available for your project. This is the
build mode you would use to produce a production image suitable for
products you intend to release.
11
12