Please note: This is copied from my personal wiki for documentation. Few parts are copied from web and may have a few typo.
Traditionally the bulk of development on PICs, both by professionals and enthusiasts, has been done in assembly language. In part this was due to performance requirements, and part due to the lack of any real alternatives. However, with the increase in the power of available PICs and the availability of several high level languages for PICs, it is becoming increasingly appropriate to consider HLLs for PIC projects.
While C compilers have been available to professional programmers for some time, their cost has limited their use by enthusiasts. Now, through the open source development model, free tools are becoming available.
Here I have used such a tool called SDCC (Small Device C Compiler). SDCC supports both 14 and 16 bit core PICs, here we will configure both, but will use 14 bit as our project will use PIC16F series.
I shall use PikDev IDE for coding and gpsim for simulating the code. These will come later.
I shall discuss only sdcc here. Others will follow in later posts.
- SDCC 2.8.0
- gputils 0.13.5 beta
- gpasm 0.22.0
SDCC does not operate in isolation, and when targeted on PIC devices it makes use of the gputils tools to provide the back end of the compilation process. The simplest tool chain is shown below.
Due to sdcc’s constant development, it is best to build it from the sources rather than to install a pre-built binary package which will very quickly become out of date.
- Firstly gcc is to be checked.
$ gcc -v gcc version 4.3.0 20080428 (Red Hat 4.3.0-8 ) (GCC)
- The source (sdcc-src-2.8.0.tar.bz2) can be downloaded from sourceforge.net. The link is here.
- I tried the rpm from fedora repo. It makes a executable named “sdcc-sdcc”. Buildng from source, however
- Compiling sdcc from the source code is easy. We will remove the features we don’t want and configure it for our purpose.
- In the top level of the source tree run this:
./configure --disable-mcs51-port --disable-gbz80-port --disable-z80-port \ --disable-avr-port --disable-ds390-port -disable-ds400-port --disable-hc08-port \ --disable-xa51-port
Building PIC16 libraries
The next step is to build some function libraries that come with sdcc. The next few command will build these.
This will install the pic16 libraries.
cd <sdcc_src>/device/lib/pic16 make libio su -c “make install”
Building PIC14 libraries
Now we will make the pic14 libraries.
cd <sdcc_src>/device/lib/pic configure make make install # moves libs to device/lib/build/pic... or so
Now we move to upper directory
cd .. # now you are in device/lib make install # to move the library into an -I'ncluded path
And we’re done building sdcc.
SDCC detailed tool chain
Now we can compile our c programmes using sdcc.