XC16 is Microchip’s C compiler for the 16-bit dsPIC microcontrollers (PIC24, dsPIC30F, dsPIC33). I sometimes need to use it when I’m working in a live session in CrunchBang Linux.
First download the Linux installer for XC16
Then change directory into the downloads folder (/home/crunchbang/downloads/ in my case) and extract the installer from the tar archive:
cd downloads tar xvf xc16-v1.21-linux-installer.run.tar
Now, log in as root, install some dependencies, and run the installer:
sudo su apt-get update apt-get install lib32z1 ./xc16-v1.21-linux-installer.run
You will be asked to agree to a software license and to answer a few questions on installation options. The default options are mostly acceptable, but make sure you reject the pay options and time-limited premium license. The free time-unlimited version should be adequate for most purposes.
By default the compiler is installed in /opt/microchip/xc16/
To compile a program, here’s an example command line:
/opt/microchip/xc16/v1.21/bin/xc16-gcc main.c -mcpu=30F4011 -Wl,--script=p30F4011.gld
That produces a file called a.out. To convert the compiled program to hex format (i.e. “a.hex”), use the bin2hex tool, as follows: