New XC8 Projects

Is your chosen PIC18 properly supported by XC8 V2 & MCC?

You want it to be!

The MCC release note lists the supported devices, under section “Supported devices”.
The Release Note is available on the MCC page (microchip.com/mcc) >> Documentation >> For Current Release >> MCC Release Notes

If its not then ideally select a PIC that is. Otherwise you will have to use an old version of MPLAB and XC8 V1 to be able to have the peripheral libraries. This is the response we we’re given by Microchip Support regarding this:

Refer this MAPS webinar: https://www.youtube.com/watch?v=lU4azxsfV00

If your device is not supported , then you could use one of the devices supported by MCC to generate code for various peripherals, and then port this code to your device (Note: Porting code from one device to another device may require changes to the MCC generated code).

Which XC8 Compiler Version?

XC8 V2.# and above

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.

XC8 V1.#

For old code projects it just works so why change from it.  Moving to V2 will cause issues if using the now old unsupported 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 you need to use an old version of MPLAB that supports it. From Microchip tech support:

The legacy peripheral library is not recommend for new designs, since we are no longer supporting it or maintaining it.

However, if you want to use the Legacy Plib you can install MPLAB X IDE v4.xx version from www.microchip.com/archives and use MPLAB XC8 v1.34 compiler from this link: https://ww1.microchip.com/downloads/en/DeviceDoc/xc8-v1.34-full-install-windows-installer.exe

Legacy Peripheral Library was removed in the following version of compiler: MPLAB XC8 v1.35

We are focusing our efforts to develop and enhance the Microchip Code Configurator (MCC).

Create MPLAB X Project

Run MPLAB X IDE

Menu > File > New Project

Categories: Microchip Embedded

Projects: Standalone Project

Select the device

Select the debugging tool

Select the Compiler to use

Set project name and “Set as main project”

Add Source Code Files

Add your initial project files to the projects “ProjectName.X” directory.

Right click the project > Add Existing Item > Select the files

Drag them into the Header Files and Source File folders.

Setting Up Debug / Release Mode

Old MPLAB allowed you to use this macro in code:

__DEBUG

to detect if a debug or release mode was selected. It was just built in, but its not in MPLAB X.

So add this to a global header file when debugging:


#ifndef __DEBUG
	#define __DEBUG						//<<<<< COMMENT OUT FOR RELEASE
#endif

Compiler Settings

IMPORTANT – ENSURE YOU CHECK THE BASIC COMPILER SETUP OPTIONS TO HELP ENSURE YOU DON’T GET CAUGHT UP IN STUPID BUGS

New XC8 V1.## Projects

See our page here.

New XC8 V2 Projects

Converting Old Code to C99 for XC8 V2.00: See our page here

MCC

Use the MPLAB Code Configurator to setup all your peripherals, uC settings etc.

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

USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

Your email address will not be published. Required fields are marked *