New XC8 Projects
Which XC8 Compiler Version?
You need to change to using the Microchip Code Configurator.
Old peripheral libraries can still be installed in theory, although we ran into compile issues when we tried to use. Better to make the move to the new setup and code usage examples provided by the Microchip Code Configurator.
Uses C99 by default which breaks various things. Its not very hard to convert your code for C99, or if you really want to you can set a V2 project to use C90 and avoid some of the changes needed.
For old code projects it just works so why change from it. Moving to V2 will cause issues if using the now old microchip peripheral libraries.
If you are used to V1.## and don’t need to use V2.## and want an easy life then you can of course just stay with V1, but V2 is the future man…
New XC8 V2 Projects
Converting Old Code to C99 for XC8 V2.00
C90 / C99
C99 is new, breaks several old things (e.g. #asm).
Select the one you want to use in:
Project properties > XC8 Global Options > C standard
Project properties > XC8 Global Options > XC8 linker > Runtime > Link in C library
New XC8 V1.## Projects
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.
This is basically the optimization level setting and for debugging you are often going to want it set to ‘Free’ to effectively disable optimization even if you have a paid for version, so that you can breakpoint and step through code without any problems.
Project Properties > XC8 Global Options > XC8 Linker > Link in peripheral library: Yes (if you are using the old peripheral libraries)
Other things to consider
You may want to add the C99 typedefs to your project:
//----- STDINT.H TYPE DEFINITIONS ----- #ifndef uint8_t typedef unsigned char uint8_t; #endif #ifndef int8_t typedef signed char int8_t; #endif #ifndef uint16_t typedef unsigned short uint16_t; #endif #ifndef int16_t typedef signed short int16_t; #endif #ifndef uint32_t typedef unsigned long uint32_t; #endif #ifndef int32_t typedef signed long int32_t; #endif
See this assembler issue here: http://electronics-design.net/embedded-programming/microchip-pic/pic18/xc8-compiler/assembler-3
See this peripheral libraries issue here: http://electronics-design.net/embedded-programming/microchip-pic/pic18/xc8-compiler/issues-xc8-compiler/xc8-peripheral-library-support-is-missing-for-the
If you get errors for interrupt function formatting etc double check you’ve got XC8 selected for the project and not C18!