PIC C Documentation


Online documentation and tools information


First Release, at last!

Introduction


PIC C is a C compiler for the Microchip PIC Microcontroller family. It takes a modified C source code file and gnerates an assembley language file. It is mostly ANSI C style syntax but it needs "kludges" to work.

At the moment this program will only compile, at a later date an assembler will be added.

This has been my most extensive project to date, it commenced in July 1997 and has only just been completed. The reason for the long development time has been threefold.

  1. I had to finish the final year of my degree!
  2. The original PIC C code generator, produced a code output that was compatible with the parallax assembler which uses a Pseudo 8051 syntax. I had to re-write it.
  3. I am a bit lazy when it comes to completing projects. I also like HTML.

The original Readme gives an overview of the original source code upon which this version has been based. I have made an update and it is here.

Features List


The current features list is as follows:
  • It uses the majority of Microchip assembler commands.
  • A standard header file for MPASM and other assemblers is used.
  • Routines to set the IO Ports are complete but need testing.
  • Routines to read and write to memory and the EEPROM have being written.
  • Only 8 bit chars are implemented. This is suitable for display strings.
  • Serial I/O routines are likely to be included.
  • Supports for, if while and do loops and other C constructs. Functions work.
  • Supports pointers, case statements and I/O commands.
  • Assembler output compatible with the included assembler.
  • An assembler is now included so that once your C Code compiles successfully, you can assemble it.
  • A GUI for the Amiga Version is in development, a windows version is being investigated.


Limitations


It only supports 8 bit datatypes at the moment.
Recursion can not be supported due to the PICs H/W stack.
there are still some bugs.

TODO


Well as of the 15th July 1999 there is still a fair bit of work to do. Below is a brief summary.
  • Write stack handling routines in assembler.
  • Clean up the code output to be compatible with the Assembler.
  • Integrate support for the Assembler.
  • Write more I/O routines.

The assembler

The assembler I intend to use is PICAsm by Timo Rossi . This assembler supports a number of PIC devices and is the Assembler that I have been using on my Amiga. I hope to add a version of the assembler here at a later date.

Using PIC C


A short section on compiling and Using PIC C.

Compiling PIC C


To Compile PIC C you need any ANSI C Compiler. There is a makefile provided in the Source directory but if this does not work just compile all of the .c files into 1 executable called pic_c. There is also a Dice makefile included. Note that Dice is an Amiga c compiler.
There will be a few compiler warnings, just ignore these. it should compile with no errors. I have succesfully compiled it using GCC on the Amiga and Unix platforms and on a PC.

Using PIC C


From a Command Line (or DOS box for Window users), type PIC_C (or whatever you called the executable) and it will produce the following output;
usage: pic_cc [-R] [-t] [-DSYM[=VALUE]] files
Where -R is compiler debug.
-t adds the C source into the assembler.
-D defines a value.
Compiled on Mar 31 1999, at 21:51:01
. Version 0.03

To compile a file type:

pic_cc file.c
This will produce file.s, which is passed to the assembler.
Note The -R flag is for Compiler Debug purposes only and is not for general use.


NOTE


One thing to point out is that the C compiler uses the old style K&R syntax, as it was written 5 years before ANSI standardisation. Any book on C will explain the differences. Just beware of this. It would be nice to change it at a later date.
All the source code now uses ANSI syntax, but it the Compiler body will need to be modified to work with ANSI syntax properly. Once I have a working code generator, I will do this.

Feedback and Contact details.

Any suggestions and code snippets in Assembler will be greatly recieved. Contact me at this address.
This program will be available for the PC under MS-DOS and the Amiga, are there any other platforms you would like to see supported? Let me know. Any suggestions or ommissions?
You will be able to use the supplied assembler or at a later date MPASM via a command line option.

By Ian Stedman, July 1999