The Build Process
Links Mentioned
N/A

Links
Home
AWC

 


Home
PIC C Programming
A C Program
Compiling


The APP-II support files include a sample makefile, so if you have a make program (for example, the one that Cygwin includes) you can use it. If you are using gputils, copy makefile-gp to makefile. If you want to use the Microchip tools, copy makefile-mchip instead. Simply change the target name (and any directories necessary) in the file. Don't use an extension in the target name, so if your program name is myprog.c, just set target to myprog. If you don't want to use make, just issue the following command from a command prompt or a shell:

sdcc -mpic14 -p16f873 -Wl -sapp2.lkr myprog.c

 Here, myprog.c is your program source, and app2.lkr is the file from the APP-II support files. You also need app2.h and app2lib.h from the support  files, of course.

This generates a hex file and you can program it into the APP-II in the usual way.

If you want to use the Microchip tools, your build process will be a bit more complex. Be sure to get the latest programs from Microchip since some older versions of MPLINK won't correctly handle SDCC's output. Here's a typical build script:

sdcc -S -mpic14 -p16f873 myprog.c
mpasmwin /o /q myprog.asm
mplink /o myprog.hex myprog.o app2.lkr

In the end, you have a working hex file either way.

Here is some information about PIC programming from the SDCC manual:

The linker organizes allocation for the code page and RAM banks. It does not have intimate knowledge of the code flow. It will put all the code section of a single asm file into a single code page. In order to make use of multiple code pages, separate asm files must be used. The compiler treats all functions of a single C file as being in the same code page unless it is non static. The compiler treats all local variables of a single C file as being in the same RAM bank unless it is an extern.

To get the best follow these guide lines:

1. Make local functions static, as non static functions require code page selection overhead.

2. Make local variables static as extern variables require RAM bank selection overhead.

3. For devices that have multiple code pages it is more efficient to use the same number of files as pages, [use 2 separate files for the APP-II]. This way the linker can put the code for each file into different code pages and the compiler can allocate reusable variables more efficiently and there's less page selection overhead. And as for any 8 bit micro (especially for PIC 14 as they have a very simple instruction set) use 'unsigned char' where ever possible instead of 'int'.

For the interrupt function, use the keyword 'interrupt' with level number of 0 (PIC14 only has 1 interrupt so this number is only there to avoid a syntax error - it ought to be fixed). E.g.:

      void Intr(void) interrupt 0 { T0IF = 0; /* Clear timer interrupt */ }

So there you have it. C programming on the APP-II!

 

Back Home