CC5X C compiler for PICmicro


- math library
- installation and
  MPLAB support
- supported chips

FAQ red_ball.gif (129 bytes)


Frequent Asked Questions

The compiler does not work in MPLAB X.
MPLAB X support is now available. Click here for a description.

I get error message "Address above 0xFFFF is not supported by selected hex file".
The HEX file must be changed from INHX8M to INHX32 when using the new enhanced 14 bit core devices. This is done by using option: -fINHX32

I get error message "Duplicate chip definition".
It is not possible to use option -p in combination with #include CHIP_HEADER_FILE. It is recommended to use #pragma chip PICxxxxx or no chip definition in the source code to avoid this error. Only one chip definition is required. Option -p will override #pragma chip in the source code.

I get "System error" when installing CC5X.
System error is often caused by TMP/TEMP variable problems. The installation program read the TMP/TEMP environment variable during installation. The TMP (TEMP) variable should normally be defined. The failure could typically be caused by one of the following reasons:

  1. The environment variable is not defined

  2. The environment variable points to a non-existing folder/directory (wrong setup)

In a MSDOS window environment variables can be inspected by using command: SET

To inspect a environment variable TMP you can use: SET TMP

In Windows you can inspect environment variables from the following "path" (depends on the language on your computer):

Control Panel->System->Advanced->Environment Variables

IMPORTANT: If the path name of the environment variable use "extended" ASCII codes, then the encoding of these could be different in a MSDOS window and the remaining WINDOWS. An example of an extended ASCII character is ''. An extended ASCII character could look correct, but if the encoding is different, then the path is wrong when programs try to use it.

The problem with different ASCII character encoding can be solved by setting the TMP (TEMP) environment variable to another folder, or updating the path (editing it). The compiler installation program will use TMP to store temporary files which are deleted after the installation. In addition, information about the installation is stored to allow automatic uninstall, and also previous installation overwriting when installing a new version. When this information is missing, the CC5X folder and files have to be deleted manually to remove the compiler from the computer.

The address for some local variables and function parameters seem to be wrong.
The compiler allocates space for local variables and parameters at fixed static locations because a dynamic stack is too costly (much more code generated and slow program execution). Local variables and parameters may share the same static locations to achieve efficient and safe reuse of RAM space. However, local variables are not allocated if the function is not called. The valid call trees are from main() and the interrupt routine, either by a direct call or indirectly through another function.

The unallocated variables are truncated to the same location. When using command line option -V there will be a mark at the unallocated local variables (file <xxx>.VAR). By using the -wU command line option a warning is printed for each uncalled function.

The following pragma will remove all unused routines if placed in the beginning of the program:

 #pragma library 1

Also note that all extern functions are separate call trees when using relocatable assembly. This separate allocation requires more RAM space.

How do I solve the error message "Shared function 'xxx' contains local variables or parameters"?
This problem is not easy. The basic issue is that CC5X maps the local variables to static global locations. The PICmicros does not have a hardware stack, and emulating a stack in software would slow down execution too much, and generate too much code.

Using static locations is fast and efficient. However, at interrupt, there may be a collision if the same routine is called (from main and interrupt) because the local variables and parameters could be overwritten causing wrong results in the calculation in main. The local variables could be saved at interrupt, but this is not implemented, and there could be many locations to save. There could be other solutions that could be managed by the compiler, but there seem to be many difficulties with all of them.

Some application writers use "interrupt driven processing" where the interrupt function become large and takes time to process. This kind of program structure easily runs into the above problem. Another way to write the application is to let the interrupt function finish as fast as possible and leave to processing to the main routine. This could be done by flags (bit variables) that are set in the interrupt routine, and read and cleared in the main program. This program structuring also makes it easier to ensure that interrupts are not lost because little time is spent in the interrupt routine.

The error message can be changed to a warning by the following pragma statement. Note that this means that the earlier mentioned local variable and parameter overwriting must be avoided by careful code writing.

 #pragma sharedAllocation

The safer method is to duplicate routines that are called from both main and interrupt. For math functions you could use type casts to ensure that another math routine is called, or inline math (integer math only) in the interrupt routine, and a math function in main.

#pragma inlineMath 1
a = b * c; // inline math (no call) if integer operation
#pragma inlineMath 0

Another challenge is 'const' data which use a common routine to read the data. A solution is to access const data from interrupt using the #pragma return[] array described in Chapter 9.2 in the Users Manual, and in file 'c-goto.txt'.

I got error message: "OPTION ERROR: Duplicate file name or option error 'Files\bknd\CC5X' ".
MPLAB supplies the include files path as a command line option to CC5X. However, you need to add doublequotes if the path name contains spaces. The string should look like "C:\Program Files\bknd\CC5X".

How do I define the symbol ICD2_DEBUG ?
This symbol needs to be defined before the chip header file is included and processed because the ICD2 reservations are found in this file. MPLAB supplies the chip definition as a command line option, and this means that CC5X will use automatic include on the chip header file. Any manual include of the chip header file must be removed when using MPLAB. The symbol needs to be defined as a command line option: -DICD2_DEBUG

How do I define a new PICmicro?
CC5X comes with a lot of header files. New header files can be downloaded from this site. Besides, existing header files can be modified to suit new PICmicro devices.

How do I use code pages?
CC5X requires that you define which code page the functions should be located on. This is either done by a page type modifier or by #pragma codepage or #pragma location statements. CC5X will update the page bits automatically when a function is called (unless this updating is switched off).

How do I use RAM banks?
CC5X need to know which RAM bank a variable should be located in. This is either done by a bank type modifier or by using #pragma rambank statements. Local variables and function parameters are also located this way. It is also possible to locate variables directly on an address. CC5X will update the bank bits automatically (unless this updating is switched off).

Are there any known bugs?
The policy is to correct and document bugs as soon as they are reported. If the bug is serious enough, a new version will be released quite soon. This depends on how easy it is to find workarounds. The list of known bugs is available to users of the licensed editions.

The code generated for the switch statement looks wrong.
CC5X generates compact code, and it is sometimes difficult to understand the logic at first sight. The switch statement use a series of XORLW instructions and the test value at each XORLW does not correspond to the C code statements (case <n>:).

MPLAB prints the error message "The format of the file C:..\..\myprogram.HEX can not be read or written because its extension was not recognized". How can it be solved?
It is required to run a command using Start->Run. Note that parts of the path may have to be changed ("Program Files") depending on the language on your computer. The command is:

  regsvr32 "C:\Program Files\MPLAB IDE\dlls\MPProgram.dll"

What does "WARNING: String limit (64) in COD file exceeded" mean?
The COD file format has a weakness. The length of a file name including full path must not exceed 64 characters. This is often not enough when the project is located deeply in the folder structure. The cure is to move the project to a folder closer to the top (root).

I have problems using the compiler in the old MPLAB IDE.
Copying the MPLAB project files to a folder different from the one where the project was created may cause problems. Copying the source files and creating a new project is recommended. This also applies when renaming the folder path.

MPLAB does not supply source file path when starting the compiler, which means that the main C file and project files must reside on the same folder.

Before using MPLINK in combination with the compiler, please read compiler file LINKER.TXT, section "MPLAB SUPPORT". It is recommended to try the linker example found in LINKER.TXT first.


End line