• AVR Freaks

Hot!Learning in XC16 (XC8)

New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2020/10/22 14:17:15
  • Location: 0
  • Status: offline
2020/10/23 03:08:36 (permalink)

Learning in XC16 (XC8)

Hello, good morning everyone.

I'm currently used to programming in CCS, it's been 10 years since I have been programming in CCS (due to all this time and I was kind of addicted to it).

I have no difficulty, but I wanted to learn to program in XC8 and XC16, especially the XC16 due to most of the time programming in DSpic.

The question is, will I have a hard time learning XC16, due to so much time and being extremely used to CCS?

has anyone had this experience?

Thank you all
PS. I'm having trouble signing in to chrome, I only managed with firefox

4 Replies Related Threads

    Super Member
    • Total Posts : 3950
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: Learning in XC16 (XC8) 2020/10/23 09:14:55 (permalink)
    XC8, XC16 and CCS  are all C programming language compilers,
    and should all behave the same if program code is correctly written.
    In a microcontroller program you typically deal with hardware directly,
    and there are a lot of  different devices available,
    all with small or large differences.
    Thus compilers for microcontrollers come with a number of additional files and libraries,
    to help defining names and structures for registers and fields in microcontroller CPU and all the different Peripherals.
    With around thousand PIC10, PIC12, PIC16, PIC18, PIC24, dsPIC30 and dsPIC33  device types,
    there are an enormous number of details to take care of.
    XC8 and XC16  do this by providing a header file:  device support header, that is individual for every product type.
    Naming conventions in device support files provided with XC8 and XC16, may be different from similar tools provided together with other compilers.
    Device support header files provided with XC8 and XC16, correspond closely with Datasheet for the respective microcontrollers.
    When people talk or write about features of different compilers,
    or try to promote a compiler, it is often not about the compiler itself,
    but instead about add-ons or libraries that may be part of the package.
    There are XC8 and XC16 C Compiler User Guide documents installed in a /docs directory
    together with compiler program and support files.
    Super Member
    • Total Posts : 804
    • Reward points : 0
    • Joined: 2012/08/08 14:04:23
    • Location: Connecticut, USA
    • Status: offline
    Re: Learning in XC16 (XC8) 2020/10/23 09:54:41 (permalink)
    +1 (1)
    I actually do have this experience!
    I moved to the official Microchip tools about 6 years ago after using CCS for a time (the codebases here where I work were all CCS when I first started).
    Migrating code over might be a bit of an annoyance, depending on how much you are relying on CCS-specific features, but is definitely doable.  Learning XC8/XC16 shouldn't be too much trouble if you already know how to program in C.  Most of the knowledge will carry, but some things will be different.
    Like converting the CCS #FUSE directives over to using the #pragma config directives to set your config bits in XC:

    #FUSES FRC    //Use Internal FRC


    #pragma config FNOSC = FRC    //Use Internal FRC

    The names of the structures for setting/clearing individual bits in a register are slightly different:

    U2MODE.UARTEN = 1;


    U2MODEbits.UARTEN = 1;

    ISRs are also declared differently.  I think CCS may also automatically clear the interrupt flag inside the ISR (at least, none of the legacy CCS code I'm looking at clears the flag):

    void  TIMER4_isr(void)
    /*ISR CODE*/

    in XC16:

    void __attribute__ ((interrupt,no_auto_psv)) _T4Interrupt (void)
    /*ISR CODE*/
    IFS1bits.T4IF = 0;  //Make sure we clear the interrupt flag!

    Probably the most annoying bit might be if you use lots of the convenience functions in CCS.  One example would be for something like peripheral setup.  In CCS there was a convenience function "setup_compare()" that you could just provide arguments to:


    Something like this would not work unless you wrote a setup_compare() function of your own.
    In XC16, this would be a similar setup:

    OC3CON1bits.OCTSEL = 0b000;     //TIMER 2 IS SOURCE
    OC3CON1bits.ENFLT = 0b000;      //Faults Disabled
    OC3CON1bits.TRIGMODE = 1;
    OC3CON1bits.OCM = 0b110;        //Edge Aligned
    OC3CON2bits.OCMPINV = 0;        //non-inverted output
    OC3CON2bits.DCB = 0b00;
    OC3CON2bits.OC32 = 0;
    OC3CON2bits.OCMPINV = 0;
    OC3CON2bits.OCTRIG = 0;
    OC3CON2bits.OCTRIS = 0;
    OC3CON2bits.SYNCSEL = 0b01100;  //SYNC Timer2 (if SYNC is enabled)

    This could be shortened to:

    OC3CON1 = 0x000E;
    OC3CON2 = 0x000C;

    Basically, you would need to consult the device datasheet and/or create your own macros to reproduce the something like the setup_compare() function in XC16.
    Hope this helps, my knowledge of CCS may not be entirely accurate, as the CCS I worked with was a few versions out of date even when I first started using it about 6 years ago (v4.132 is the version I've got installed for building legacy firmware).
    post edited by KTrenholm - 2020/10/23 10:30:08
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2020/10/22 14:17:15
    • Location: 0
    • Status: offline
    Re: Learning in XC16 (XC8) 2020/10/25 14:34:54 (permalink)
    Thanks for the answer MYsil

    Thanks for the reply KTrenholm


    It was exactly what I expected to find ..... I partially use the CCS "facilities(convenience functions in CCS)". What gets me confused in the CCS is that some things end up being "obscure" in these "facilitators", an example of which are the "Errata" of the microcontroller, you do not know if the errata in the "facilitators" has already been applied or not. my next step is to acquire an XC8 book with my local language (Portuguese) and learn it for later application in XC16.
    post edited by Ortegahernandes - 2020/10/25 14:40:25
    Super Member
    • Total Posts : 493
    • Reward points : 0
    • Joined: 2014/01/23 17:27:06
    • Location: NJ
    • Status: offline
    Re: Learning in XC16 (XC8) 2020/10/26 07:41:10 (permalink)
    Amazon dot com is loaded with books for PIC written in Portuguese.  You shouldn't have any problems finding something useful.

    I don't need the world to know my name, but I want to live a life so all my great-grandchildren proudly remember me.
    Jump to:
    © 2020 APG vNext Commercial Version 4.5