C Programming with the Microchip PIC
Links Mentioned
APP-II
APP-IV
SDCC
GPUTILS
APP-II Tutorial

Links
Home
AWC

Microchip
 


Home
PIC C Programming
A C Program
Compiling


If you don't like assembly language, you might be tempted to switch to a high level language like C. I've often said that the PIC 16F family is not well-suited for C. However, there are C compilers available and they do work. This tutorial will show you how to get started with the open source SDCC compiler and our APP-II board. I'll assume you know C already -- this tutorial just covers the SDCC and APP-II specific issues. I'm also assuming you know how to download a hex file to the APP-II. If you don't, then you need to start with the APP-II tutorial or read the manual before you proceed.

If you just want to use C with a microcontroller, check out our APP-IV. Based on the Atmel ATmega chip, the APP-IV uses GNU C, which is very powerful and well-supported. However, if you are determined to use a PIC, you can still get the job done.

The SDCC compiler can target many different processors, including the APP-II's PIC16F873. There is not a lot of library support (although we supply headers and code for the APP-II specific parts). If you are used to using C, you may find SDCC a bit odd for several reasons:

bulletSDCC has several unique storage specifiers
bulletBy default SDCC does not put variables on the stack so functions are not reentrant
bulletSDCC seeks to overlay variables to reduce memory consumption
bulletSDCC's PIC support is considered "beta quality" -- although I have found it works well enough

Here's what you need to get started:

bullet SDCC
bullet GPUTILS
bulletAPP-II Support Files

Be sure to get the versions of SDCC and GPUTILS that match your operating system (Win32 if you are using Windows). If you are running Windows and you don't have Cygwin, you might consider it since it makes your Windows machine look pretty much like Linux (which is a good thing for development). You can download Cygwin at http://www.cygwin.com.

If you are using Windows, you can skip GPUTILS and use the MPASM and MPLINK tools from Microchip, if you prefer.

Once you have all the tools installed, you are ready to write some code.

By the way, if you are interested in SDCC with the 8051 -- its native processor -- be sure to read http://www.awce.com/gp8051.htm.

Home Next