4.6 Project Example. MICROCHIP MICROCHIP SW006022-1
Annonce
Annonce
XC16 Toolchain and MPLAB X IDE
4.6
PROJECT EXAMPLE
In this example, you will create an MPLAB X IDE project with two C code files.
4.6.1
Run the Project Wizard
In MPLAB X IDE, select File>New Project to launch the wizard.
1. Choose Project: Select “Microchip Embedded” for the category and “Standalone Project” for the project. Click Next> to continue.
2. Select Device: Select the dsPIC30F6014. Click Next> to continue.
3. Select Header: There is no header for this device so this is skipped.
4. Select Tool: Choose a development tool from the list. Tool support for the selected device is shown as a colored circle next to the tool. Mouse over the circle to see the support as text. Click Next> to continue.
5. Select Compiler: Choose a version of the XC16 toolchain. Click Next> to continue.
6. Select Project Name and Folder: Enter a project name, such as
MyXC16Project. Then select a location for the project folder. Click Finish to complete the project creation and setup.
Once the Project Wizard has completed, the Project window should contain the project tree. For more on projects, see the MPLAB X IDE documentation.
4.6.2
Add Files to the Project
To add the C code files tmp6014.c and traps.c to the project:
1. Right click on the “Source Files” folder in the project tree. Select “Add Existing
Item” to open the Select Item dialog.
2. Go to the directory:
C:\Program Files\Microchip\xc16\vx.xx\support\templates\c where vx.xx is the version number.
3. Click the file tmp6014.c. Then shift-click the file traps.c. Click Select.
When you are done, the project tree should now have the Source Files folder open, containing to the two added files.
2012-2014 Microchip Technology Inc.
DS50002071E-page 85
MPLAB
®
XC16 C Compiler User’s Guide
4.6.3
Set Build Options
Select File>Project Properties or right click on the project name and select “Properties” to open the Project Properties dialog.
1. Under “Conf:[default]>XC16 (Global Options)”, select “xc16-gcc”.
2. Select “Preprocessing and messages” from the “Option Categories”. Enter the following path for “C Include Dirs”:
C:\Program Files\Microchip\xc16\vx.xx\support\dsPIC30F\h where vx.xx is the version number.
3. Under “Conf:[default]>XC16 (Global Options)”, select “xc16-ld”.
4. Select “Diagnostics” from the “Option Categories”. Then enter a file name to
“Generate map file”, i.e., example.map.
5. Click OK on the bottom of the dialog to accept the build options and close the dialog.
4.6.4
Build the Project
Right click on the project name, “MyXC16Project”, in the project tree and select “Build” from the pop-up menu. The Output window displays the build results.
If the build did not complete successfully, check these items:
1. Review the previous steps in this example. Make sure you have set up the language tools correctly and have all the correct project files and build options.
2. If you modified the sample source code, examine the Build tab of the Output window for syntax errors in the source code. If you find any, click on the error to go to the source code line that contains that error. Correct the error, and then try to build again.
4.6.5
Output Files
View the project output files by opening the files in MPLAB X IDE.
1. Select File>Open File. In the Open dialog, find the project directory.
2. Under “Files of type” select “All Files” to see all project files.
3. Select File>Open File. In the Open dialog, select “example.map”. Click Open to view the linker map file in an MPLAB X IDE editor window. For more on this file, see the linker documentation.
4. Select File>Open File. In the Open dialog, return to the project directory and then go to the dist>default>production directory. Notice that there is only one hex file,
“MyXC16Project.X.production.hex”. This is the primary output file. Click Open to view the hex file in an MPLAB X IDE editor window. For more on this file, see the
Utilities documentation.
There is also another file, “MyXC16Project.X.production.cof” or “MyXC16Project.X.production.elf”. This file contains debug information and is used by debug tools to debug your code. For information on selecting the type of debug file, see
Section 4.5.1 “XC16 (Global Options)”.
DS50002071E-page 86
2012-2014 Microchip Technology Inc.
XC16 Toolchain and MPLAB X IDE
4.6.6
Further Development
Usually, your application code will contain errors and not work the first time. Therefore, you will need a debug tool to help you develop your code. Using the output files previously discussed, several debug tools exist that work with MPLAB X IDE to help you do this. You may choose from simulators, in-circuit emulators or in-circuit debuggers, either manufactured by Microchip Technology or third-party developers.
Please see the documentation for these tools to learn how they can help you. When debugging, you will use Debug>Debug Project to run and debug your code. Please see
MPLAB X IDE documentation for more information.
Once you have developed your code, you will want to program it into a device. Again, there are several programmers that work with MPLAB X IDE to help you do this. Please see the documentation for these tools to see how they can help you. When programming, you will use “Make and Program Device Project” button on the debug toolbar. Please see MPLAB X IDE documentation concerning this control.
2012-2014 Microchip Technology Inc.
DS50002071E-page 87
MPLAB
®
XC16 C Compiler User’s Guide
NOTES:
DS50002071E-page 88
2012-2014 Microchip Technology Inc.
Download
Annonce