Setting a new project
(After following the steps here)
Project Properties > XC8 global options > XC8 Compiler > Select ‘Optimizations’
Speed (or disable optimizations?) & Debug checkboxes
Set as needed (off and on is good for debugging)
Address qualifiers – CAN BE VERY IMPORTANT!!!!
If you are using anything that requires locating in specific memory locations set this to ‘Require’, e.g. variables used in assembler, etc. This is not the default setting as it can cause horribly confusing bugs until you realize it is the cause.
Upgrading A Project From XC8 V1.## to XC8 V2.## and use C99
https://microchipdeveloper.com/xc8:moving-to-xc8-2-0
V2.00 of the XC8 compiler is quite different to V1.## versions, various things are broken / change:
- Uses C99 instead of C90 (you can still use C90 if you want to – see https://microchipdeveloper.com/xc8:moving-to-xc8-2-0 )
If you don’t want to implement this C99 changes
This guide is based on moving up to C99, but you can avoid having to do some of the changes if you want to use the older C90 standard.
If you want to continue using #asm, old style interrupt definitions and other C90 based C things then you can simply select C90 instead of C99: Properties > XC8 Global Options > C Standard.
Upgrading A Project From XC8 V1.## to XC8 V2.## and use C99
Change Project Settings
Project properties > Conf > Select XC8 v2.## compiler
Project properties > XC8 Global Options > C standard > C99
Project properties > XC8 Global Options > XC8 Linker > Link in C Library > C99
Include Files
Replace your device specific header file:
#include <p18f23k22.h>
With this generic file:
#include <xc.h>
This header file is typically included into each C source file you write. It is a generic header file that will include other device- and architecture-specific header files when you build your project.
ASM code
Remove these:
#asm
#endasm
Add this before and after each line of assembly
asm(" ");
An example:
asm("GLOBAL _uc_asm_irq_temp");
asm("GLOBAL _uc_asm_irq_temp1");
//Reset timer for next rollover
asm("movff TMR0L,_uc_asm_irq_temp"); //read_current_timer_value (read low byte loads high byte)
asm("movff TMR0H,_uc_asm_irq_temp1");
asm("movlw 0x6b");
asm("addwf _uc_asm_irq_temp,f,c"); //(1 = file register, 0 = access ram)
asm("movlw 0xf0");
asm("addwfc _uc_asm_irq_temp1,f,c"); //(1 = file register, 0 = access ram)
asm("movff _uc_asm_irq_temp1,TMR0H"); //Store new value (high byte first)
asm("movff _uc_asm_irq_temp,TMR0L");
Interrupt Functions
Change the definitions in your .c and .h files from this format:
void interrupt interruptisrh (void);
void interrupt low_priority interruptisrl (void);
To this:
void __interrupt() interruptisrh (void);
void __interrupt(low_priority) interruptisrl (void);
near variables
For any variables defined as near add a double underscore in front of the near directive, so from this:
near static unsigned char uc_asm_irq_temp; // near qualifier specifies access RAM
near static unsigned char uc_asm_irq_temp1;
To this:
__near static unsigned char uc_asm_irq_temp; // near qualifier specifies access RAM
__near static unsigned char uc_asm_irq_temp1;
Possible errors
error: (2047) 24-bit floating point types are not supported when compiling in C99
Project properties > XC8 Global Options > XC8 Linker > Memory Model > Size of float 32bit
MPLAB Code Configurator
You really have to use the graphical “MPLAB Code Configurator” instead of the old peripheral libraries – even though they can still be installed we ran into compile issues when we tried to use some.
For how to use see here
Peripheral Libraries
Seems you really have to use the graphical “MPLAB Code Configurator” instead of the old peripheral libraries – even though they can still be installed we ran into compile issues when we tried to use.