Humidity sensor - H1
Microchip development tools
Setting up a Microchip PIC development environment,
using open source or free tools
For now, I only need to be able to develop on PIC18 or PIC16.
Microchip has some tools that allows anybody to setup the development tools, including IDE, C compilers, libraries...
I might upset some people, but Windows is still one of the best all-rounder operating system. And it is the platform I use on my everyday computer. So I need tools that run on Windows OS.
The home "server" is also running as my Home Theatre, on an Mac mini. It is running Mac OS X, which is based on Unix. I just installed MAMP to get all required features.
The PIC projects will use the following tools:
- MPLAB X, the new IDE from Microchip. It runs on Windows, Linux or Mac. It provides a nice environment to code, make, compile, program, debug...
- MPLAB C18 Compiler, available free from Microchip. This is the C compiler. The only limitation is that it runs on Windows platform only and optimizations and extended instructions are disabled. This is not an issue for most of open source projects.
- SDCC Toolchain, if you want a C compiler that runs on Linux, Mac or Windows. You need SDCC and Gputils to integrate with MPLAB X.
- A programmer and/or Debugger. I use a PICkit2 clone that I made a while ago. Any programmer supported by MPLAB will do: MPLAB ICD 3 in-circuit debugger, PICkit™ 2 or 3, and MPLAB PM3

Setting up the Microchip Application Libraries and Compiler include path
Microchip provides a bunch of libraries, the Microchip Application Libraries, which are very handy to use in projects. The only issue is to make sure that it is setup and available to the compiler. I always had trouble with the libraries and moving projects around. Projects had to be reconfigured every time, and it was a pain to maintain. I decided on a setup that would only use relative path.
The C18 projects project are setup in a dedicated folder. The root of the folder contains a folder for each project, and 2 additional folders: MAL for the Microchip libraries, and Libraries for my own libraries.

When you install the Microchip Application Libraries, install them in its own folder. It makes it easier to look and work with provided application examples. Once installed, the Microchip folder contains all libraries we need. Just copy its content into the MAL folder.
Now MPLAB X has to be configured to tell the compiler where to look for libraries. By using the approach above, it is easy to use relative path in the configuration, making it much easier to export and copy projects across.
In MPLAB X, go into the project properties, and open the Conf / C18 (Global Options) / mcc18 / General window. In the Include directories, make sure you have the following 3 entries: .; ../Libraries/Include; ../MAL/Include
This will tell the compiler to check for libraries first in the folder of the project (.), then your own libraries (../Libraries/Include) and then the Microchip Application Libraries (../MAL/Include)
It only uses relative path, so the whole development environment is easily migrated.

