Write programs for PICs in C using SDCC and Code::Blocks on Linux
From Curuxa
If you prefer to use graphical development environments to write and compile your PIC programs in C on Linux, a good choice is Code::Blocks. These are the instructions:
System requirements
Compilation
Setup Code::Blocks
These steps have to be done only once.
- Open Code::Blocks
- Go to Settings->Compiler and debugger...
- Selected compiler->SDCC
- Click on Set as default
- Click on tab Toolchain executables
- Make sure Compiler's installation directory has the correct path. It's usually /usr/bin
Create a project
- Open Code::Blocks
- File->New->Project
- Category-> All categories
- Choose Empty project
- Click Go
- Follow the instructions. On the last section you have to choose...
- Compiler: SDCC Compiler
- Uncheck Create Debug configuration
- Check Create Release configuration
- Ignore the warnings about warning flags and optimization flags
- File->New->Empty file
- Save the new file (for example) as MyProgram.c into your project's directory
- Write your program in C-language using SDCC syntax. See its documentation. Each Main Board and Module has some sample code you can use
- Go to Project->Build options
- Click on tabs Compiler settings->Compiler flags and the check [CPU] Microchip PIC 14-bit ... [-mpic14]
- Go to tab Other options and write the parameter we have to send SDCC to choose your PIC model. For example if you are using a PIC16F887, you have to write -p16f887. Remember to put a dash at the beginning
- Close that window
- Now you can compile your program. Go to Build->Build
Now you've got a .hex file placed in [your_project_dir]/bin/Release. You can program/burn it into the microcontroller.