กก

C Compiler For PIC18Fxxxx MCUs - P18CC

by Mengjin Su


กก

Welcome to this web page! It introduces you a C compiler that supports PIC18Fxxxx series MCUs from Microchip. The greatest feature of P18CC is that it can support extended instruction set that the new PIC18Fxxxx devices have. In most situations, using/enabling extended instruction set will let your code smaller and faster! Plus, it can support recursive function call (that means a function can call itself!).

P18CC support those basic data types: char(8-bit integer), int(16-bit integer) and long(32-bit integer). Plus, it supports 'struct' and 'union' to define customized data.

Following preprocessors are supported in P18CC:

                #if expression

                #else

                #endif

                #ifdef symbol

                #ifndef symbol

                #pragma symbol  expression

                #define  symbol   expression

                #define  symbol(par1,par2,...)   expression

                #include  "filename"

                #include  <filename>

 

How to use P18CC

[1] Install the compiler

Unzip and extract all file, and then put them into a folder (e.g. P18CC). And then put the path into the environment, like

C:>\set path=%path%;C:\P18CC

[NOTE, you can make batch file (filename with extension '.bat') to set the path].

In this folder, you should see following files:

            p18cc.exe        - P18CC compiler

            p18as.exe        - PIC18 assembler/linker

            crt0.s                - library routines

            pic18.h             - PIC18Fxxxx header file

            device.cfg     - PIC18Fxxxx MCU config file

            examples(folder)  - a folder that contains some example codes

 

[2] Compiling command:

   p18cc  <options>  filename1.c filename2.c ...

After compiling, if no error detected, assembly code(file) will be generated for each source file, ended with '.s'. The assembly code is very readable, and you can check what result exactly is.

where the options are:

        -X                                               enable extended instruction set

        -L                                                generate assembly code in LIB mode

        -s                                                short jump instruction needed (default = long jump instruction)

        -S                                               for 'small' RAM memory devices (e.g. MCU that has no more

                                                           than 256 bytes RAM).  It usually will generate faster and smaller code.

        -Dsymbol<=xxxx>                      define symbol (with or without value)

 

[3] Assembling and linking

  p18as <options> filename1.s  filename2.s  ...

where the options are:

      -device_name(mandatory)            specify PIC device (for example:   -pic18f452)

      -code=xxxx                                    code start address (default = 0x0000), no space allowed

      -data=xxxx                                     RAM data start address (default = 0x0002)

      -sp=xxxx                                        specify stack pointer initial value.

      -X                                                  using 'extended instruction set' library

 

Resources used by Compiler

P18CC will use following registers for compilation:

WREG PRODL PRODH FSR0L FSR0H FSR1L FSR1H FSR2L FSR2H TABLAT TBLPTRL TBLPTRH TBLPTRU STATUS BSR

Users should pay great attention when accessing any of those register in the code.

Further more, RAM location 0x0000 and 0x0001 (first two locations in bank0) are reserved for compilation,  holding function return value (lower 16 bits) and temporary values. User should never use these location for any purpose. Index registers (FSR0L/FSR0H, FSR1L/FSR1H and FSR2L/FSR2H) are used by compiler for indirect addressing. Among them FSR2L and FSR2H are use as software stack pointer.

 

How to access Flash ROM

Accessing ROM is a special operation and very necessary  in embedded programming since non-volatile data are usually stored in ROM area and need to be accessed using different instruction in most MCUs. In P18CC, there is a built-in function, __rom__(), to handle the job. The following cases are examples of  using it:

      char a, b, *p;

      ...

      a = __rom__ (p);

      b = __rom__ ((unsigned char *)1000);

 

Check examples for details

The P18CC package comes with some examples of how to use P18CC. It shows some details of coding (e.g how to declare interrupt service routine). It will greatly save you a lot of time and efforts to pick it up for you testing.

 

Free version of P18CC

The free version of P18CC is full functional, except it only supports MCUs that have no more than 256 bytes of RAM and it will support extended instruction set. It's ideal for those 'small' PIC devices (e.g. PIC18F1220).  Click here to get free version of  P18CC. You can download and distribute it freely. Suggestions and comments are very welcome by sending emails to '[email protected]'!

กก

Hosted by www.Geocities.ws

1