Compiling PIC projects
You don't need a Microchip programmer to develop firmware for most of our PIC microcontroller-based projects. You can use Microchip's free development tools and upload code with the bootloader.
Microchip's tools are all Windows-only, but there are beta version available for Linux and Mac.
MPLABX is Microchip's new cross-platform IDE and compilers for Windows, Linux, and Mac.
Some projects require a C compiler. We use Microchip's free demonstration compilers with MPLAB. The demo compilers have certain optimizations that expire after 60 days, but we don't use those anyway.
|USB IR Toy||18F2550||C18|
A problem we're still working around is Microchip's source code license. The source is freely available from the Microchip website, but they don't allow us to distribute it.
You need to download and install the Microchip source yourself. Drag the Dangerous Prototypes source folder into the install location (usually Microchip Solutions). We're working on alternatives, as listed below.
|Source||Used in||Open Alternatives|
|"free" TCP/IP stack (old versions now available)||#twatch, Web Platform||uIP stack port|
|"free" FAT32 file system||Web Platform||1 DosFS FatFs|
|"free" USB stack|| ||The JTR-Honken USB stack is now running on the USB IR Toy firmware v20+|
- Open the project in MPLAB
- Compile the project (down arrow stack of papers icon)
You may need to modify the compiler location when prompted, but MPLAB is getting better about making these changes automatically.
Export for bootloader
Some compiled firmware must be exported in order to work with the bootloader.
Exporting in MPLAB X
If you need to configure the program memory area end address (see table below), this needs to be done in the project's settings before compiling and exporting:
- To configure the end address in MPLAB X, go to File -> Project Properties and select the configuration (usually Conf: default) from the list on the left.
- Select a PIC programmer device from the list on the right; if you don't actually have any of the devices, select PICKit3.
- Click Apply.
- Select the PIC programming device (e.g., PICKit3) from list on the left.
- Select Memories to Program from the menu on the right.
- Set the option Auto select memories and ranges to Manually select memories and ranges.
- Tick the box for Program Memory and below that enter the end value (from the table below)
- Click OK to close the settings.
After configuring the end address (if required), build the project by selecting Run -> Clean and build main project (or select Clean and build from the project's context menu). This creates a .hex file in the build directory (the last few lines of the build output should mention its name and path).
You can also export the .hex file by selecting Export hex from the project's context menu (right-click the project's name in the project list to bring up the menu).
Exporting in MPLAB 8
- In MPLAB 8, go to File->Export...
- Make sure that Program Memory is checked and the Configuration Bits box matches the required setting
- Change the export end address if needed (see table below)
- Make sure INHX32 (Intel 32bit HEX) is selected on the File Format tab
- Click OK to export the firmware.
Project-specific export settings
|Project||Required?||End address||Config bits?||EEPROM?|
|Bus Pirate v3 (bootloader v4.x)||yes||0xa7fa||no||-|
|USB Infrared Toy||no||(default)||yes||optional|
|Bus Pirate v4||no||(default)||yes or no|
Note: If an end address is required but the value in the table above is not accepted, it may be that the value is required to be of the form (0x100 * n – 1). This means a hexadecimal value with the last two digits ff. You can try either the next smallest or next largest such value (next smallest is safer but costs up to about 250 bytes of program space). For example, for the Bus Pirate v3 the suggested end address is 0xa7fa, but MPLAB X wants to have 0xa6ff (preferred) or 0xa7ff instead.