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


Setup Code::Blocks

These steps have to be done only once.

  1. Open Code::Blocks
  2. Go to Settings->Compiler and debugger...
  3. Selected compiler->SDCC
  4. Click on Set as default
  5. Click on tab Toolchain executables
  6. Make sure Compiler's installation directory has the correct path. It's usually /usr/bin

Create a project

  1. Open Code::Blocks
  2. File->New->Project
  3. Category-> All categories
  4. Choose Empty project
  5. Click Go
  6. Follow the instructions. On the last section you have to choose...
    • Compiler: SDCC Compiler
    • Uncheck Create Debug configuration
    • Check Create Release configuration
  7. Ignore the warnings about warning flags and optimization flags
  8. File->New->Empty file
  9. Save the new file (for example) as MyProgram.c into your project's directory
  10. Write your program in C-language using SDCC syntax. See its documentation. Each Main Board and Module has some sample code you can use
  11. Go to Project->Build options
  12. Click on tabs Compiler settings->Compiler flags and the check [CPU] Microchip PIC 14-bit ... [-mpic14]
  13. 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
  14. Close that window
  15. 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.