This repository includes code examples to use with SDCC, an open source compiler for 8-bit microcontrollers. The examples can help beginners who usually find problems like which headers to include, which parameters to use when compiling, etc.
The examples are structured by microcontroller architecture. For a particular architecture, the examples can be followed in order as a tutorial. The basic concepts explained on the first examples are not explained again on more advanced ones.
On each example folder there is a Makefile
so you can compile the example by simply running make
. The actual compiler command will be shown so you can learn about the options passed to the compiler.
There are README files on each example with explanations of the code and indications on the hardware required to test it.
The architectures included are:
pic14/
: PIC16F microcontrollers which have a 14-bit instruction bus, hence pic14. Examples for PIC16F886, but small modifications needed to use other PICs. As of this writing, the pic14 port of SDCC is unstable and can even be considered as broken.pic16/
: PIC18F microcontrollers which have a 16-bit instruction bus, hence pic16. Examples for PIC18F2550, but small modifications needed to use other PICs. As of this writing, the pic16 port of SDCC is unstable but it can be used carefully.
To compile these examples SDCC is required. gputils is also required for PIC ports.
There are packages of both on repositories of distributions like Debian and Ubuntu. Despite being an easy way to install them, the packages are usually outdated and installing the latest stable versions is strongly recommended. These instructions are for Ubuntu 12.04 LTS, 14.04 LTS and 16.04 LTS, but the process should be very similar for other distros, hopefully just changing the dependencies install.
Before intalling gputils and SDCC, these dependencies are needed:
$ sudo apt-get install bison flex g++ libboost-dev texinfo
(probably similar packages for other distros)
gputils needs to be compiled before installing. Needs to be installed before SDCC.
- Go to gputils source files page
- Download the latest stable version and extract it. Be careful not to download Release Candidate (RC) files.
- Inside
gputils-x.x.x
folder, run./configure && make && sudo make install
. - If everything went fine, check that
gpasm -v
works and returns the version number you expect.
Up to SDCC 3.4.0, the precompiled version of SDCC worked fine on the Ubuntu 12.04 LTS and 14.04 LTS versions, but from 3.5.0 on, SDCC needs to be compiled because the precompiled files depend on GLIBCXX_3.4.20 which is not available on those Ubuntu versions.
- Go to SCCC source files page.
- Download the latest stable version and extract it. Be careful not to download Release Candidate (RC) files.
- Inside
sdcc-x.x.x
folder, run./configure && make && sudo make install
. - If everything went fine, check that
sdcc -v
works and returns the version number you expect.
- Go to gputils files page
- Download the latest stable version. Be careful not to download Release Candidate (RC) files.
- Just execute the exe file and follow the installer.
- If everything went fine, check that
gpasm -v
works and returns the version number you expect.
- Go to SCCC source files page: 32-bit or 64-bit.
- Download the latest stable version. Be careful not to download Release Candidate (RC) files.
- Just execute the exe file and follow the installer.
- If everything went fine, check that
sdcc -v
works and returns the version number you expect.
This repository is tested automatically on on Travis-CI using the latest 3 SDCC and latest 2 gputils releases to make sure that every example is built without errors on those SDCC and gputils combinations (SDCC and gputils are downloaded and installed on the Travis instance automatically). The generated code is not tested (e.g. simulator), but at least this makes sure that the examples can be compiled.
On the SDCC Wiki you can find other tutorials that can help you.
Any kind of collaboration like more examples, examples for more architectures, corrections, comments, etc. are very welcome. Feel free to open an issue or fork and pull request.