Difference between revisions of "Compiling PIC projects"

From LinkSprite Playgound
Jump to: navigation, search
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[File:Mplab.png]]
+
==C compiler==
 
 
 
 
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.
+
The most popular free C compiler for PIC project is cc5xfree. You can download from:
  
 +
*[http://www.bknd.com/cc5x/index.shtml CC5X]
  
  
==IDE==
+
You can also download from:
Download and install Microchip's [http://en.wikipedia.org/wiki/Integrated_development_environment IDE] called [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en019469&part=SW007002 MPLAB].
 
  
[http://devupdates.microchip.com/mplab/Files/installer.html MPLABX] is Microchip's new cross-platform IDE and compilers for Windows, Linux, and Mac.
+
*[http://www.linksprite.com/pub/wiki/Component_breakout/SerLCD/cc5xfree.zip CC5X]
  
==C compiler==
 
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.
 
  
* [http://www.microchip.com/C18 C18 Compiler for PIC 18F]
+
[[File:Cc5x.JPG]]
* [http://www.microchip.com/C30 C30 Compiler for PIC 24F/33F]
 
  
{|class="wikitable" border="1"
+
==C compiler handbook==
| '''Project'''
 
| '''PIC'''
 
| '''Compiler'''
 
|-
 
| #twatch
 
| 18F67J60
 
| C18
 
|-
 
| USB IR Toy
 
| 18F2550
 
| C18
 
|-
 
| Flash Destroyer
 
| 18F2550
 
| C18
 
|-
 
| Logic Sniffer
 
| 18F24J50
 
| C18
 
|-
 
| Bus Pirate
 
| 24FJ64GA002
 
| C30
 
|-
 
| Web Platform
 
| 33FJ128GP204
 
| C30
 
|}
 
  
==Non-distributables==
+
*[http://www.linksprite.com/pub/wiki/Component_breakout/SerLCD/cc5x-33.pdf  CC5X handbook]
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.
 
  
{|class="wikitable" border="1"
+
==Pic Kit 3==
| '''Source'''
 
| '''Used in'''
 
| '''Open Alternatives'''
 
|-
 
| [http://www.microchip.com/tcpip "free" TCP/IP stack] ([http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2896 old versions] now available)
 
| #twatch, Web Platform
 
| [http://dangerousprototypes.com/category/uip/ uIP stack port]
 
|-
 
| [http://www.microchip.com/mdd "free" FAT32 file system]
 
| Web Platform
 
| [http://www.roland-riegel.de/sd-reader/index.html 1] [http://www.larwe.com/zws/products/dosfs/index.html DosFS] [http://elm-chan.org/fsw/ff/00index_e.html FatFs]
 
|-
 
| [http://www.microchip.com/usb "free" USB stack]
 
| <s>USB IR Toy</s>, Logic Sniffer
 
| The JTR-Honken USB stack is now running on the USB IR Toy firmware v20+
 
|}
 
  
==Compiling==
+
You can download the PITkit3 programmer software from [http://www.linksprite.com/pub/wiki/Component_breakout/SerLCD/PICkit3_1.0.0.0SetupA.exe]
#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==
+
[[File:Pickit3.JPG | 500px]]
  
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:
+
==Notes==
  
# To configure the end address in MPLAB X, go to ''File -&gt; Project Properties'' and select the configuration (usually ''Conf: default'') from the list on the left.
+
The position and size of the supported config identifiers should be
# Select a PIC programmer device from the list on the right; if you don't actually have any of the devices, select ''PICKit3''.
+
defined. This enables the identifiers to be used in #pragma config
# Click ''Apply''.
+
statements in an application.
# 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 -&gt; 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).
+
    #pragma config_def [=] value
  
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).
+
  value:
 +
  0x0001:  FOSC in bit 0,1  : 0 - 3, LP, XT, HS, RC
 +
  0x0002:  FOSC in bit 0,1,2 : 0 - 7, LP, XT, HS
 +
  0x0004:  FOSC in bit 0    : 0, 1
 +
  0x0008:  FOSC in bit 0,1,4 : 0 - 7, LP, XT, HS
  
===Exporting in MPLAB 8===
+
  0x0010:  WDTE in bit 2: off (0), on (1)
 +
  0x0020:  WDTE in bit 3: off (0), on (1)
  
[[Image:Mplab-export_001.png ]]
+
  0x0100: PWRTE in bit 3 (inverted):    on (0), off (1)
 +
  0x0200:  PWRTE in bit 4 (inverted):    on (0), off (1)
 +
  0x0400:  PWRTE in bit 3 (not inverted): off (0), on (1)
  
 +
  0x1000:  BODEN in bit 6  : off (0), on (1)
  
#In MPLAB 8, go to ''File-&gt;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===
+
Example: #pragma config_def 0x1111  // 0x0001 | 0x0010 | 0x0100 | 0x1000
  
{|class="wikitable" border="1"
+
    FOSC in position 0,1
| '''Project'''
+
    WDTE in position 2
| '''Required?'''
+
    PWRTE in position 3 (0=on)
| '''End address'''
+
    BODEN in position 6
| '''Config bits?'''
 
| '''EEPROM?'''
 
|-
 
| #twatch
 
| yes
 
| 0x1dbbf
 
| yes
 
| -
 
|-
 
| Bus Pirate v3 (bootloader v4.x)
 
| yes
 
| 0xa7fa
 
| no
 
| -
 
|-
 
| Logic Sniffer
 
| yes
 
| (default)
 
| no
 
| -
 
|-
 
| USB Infrared Toy
 
| no
 
| (default)
 
| yes
 
| optional
 
|-
 
| Web Platform
 
| no
 
| 0×153fe
 
| yes
 
| -
 
|-
 
| Flash Destroyer
 
| 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&nbsp;*&nbsp;''n''&nbsp;–&nbsp;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&nbsp;X wants to have ''0xa6ff'' (preferred) or ''0xa7ff'' instead.
+
NOTE: THIS PRAGMA IS NORMALLY FOUND IN THE CHIP HEADER FILE AND
 +
      SHOULD NOT BE USED IN THE APPLICATION SOURCE CODE.

Latest revision as of 09:00, 9 December 2012

C compiler

The most popular free C compiler for PIC project is cc5xfree. You can download from:


You can also download from:


Cc5x.JPG

C compiler handbook


Pic Kit 3

You can download the PITkit3 programmer software from [1]

Pickit3.JPG


Notes

The position and size of the supported config identifiers should be defined. This enables the identifiers to be used in #pragma config statements in an application.

   #pragma config_def [=] value
  value:
  0x0001:  FOSC in bit 0,1   : 0 - 3, LP, XT, HS, RC
  0x0002:  FOSC in bit 0,1,2 : 0 - 7, LP, XT, HS
  0x0004:  FOSC in bit 0     : 0, 1
  0x0008:  FOSC in bit 0,1,4 : 0 - 7, LP, XT, HS
  0x0010:  WDTE in bit 2: off (0), on (1)
  0x0020:  WDTE in bit 3: off (0), on (1)
  0x0100:  PWRTE in bit 3 (inverted):     on (0), off (1)
  0x0200:  PWRTE in bit 4 (inverted):     on (0), off (1)
  0x0400:  PWRTE in bit 3 (not inverted): off (0), on (1)
  0x1000:  BODEN in bit 6  : off (0), on (1)


Example: #pragma config_def 0x1111 // 0x0001 | 0x0010 | 0x0100 | 0x1000

   FOSC in position 0,1
   WDTE in position 2
   PWRTE in position 3 (0=on)
   BODEN in position 6

NOTE: THIS PRAGMA IS NORMALLY FOUND IN THE CHIP HEADER FILE AND

     SHOULD NOT BE USED IN THE APPLICATION SOURCE CODE.