Skip to main content Skip to local navigation

Interrupts, Bit Clearing and Setting in XC8

While testing out the PIC16F88 replacement for the PIC16F84 on the INSA microcontroller teaching board I ran into issues with two things not working as per the standard sources of examples (e.g. Microchip’s Developer Wiki):

  1. Interrupt Service Routines
  2. Bit setting, clearing via structures
Watch out for examples of Interrupt Service Routines for XC8.

Microchip’s Developer site examples need to be updated. They’re not necessarily valid for XC8 v2.0 (mid-2018)

These examples appear to have been written for versions of XC8 prior to version 2.0.   However, since mid-2018, the 2.0 version of the XC8 compiler uses new compiler technology to support both PIC and AVR processors.  This is a big change and it’s not surprising that the development has broken older examples.

It turns out that we need to rely more on the manual for the XC8 compiler for the time being, as pointed out on the Microchip forum:

ISRs are different in XC8 v2

Defining interrupt service routines is different when using the newest XC8 compiler (v2, as of mid-2018). (c/o Microchip’s Forum.)

In addition to making changes to how ISRs need to be set up so that the compiler understands it, it’s important to update how I do bit checking, clearing, setting, toggling. So rather than using structures (the nice way) I’ll go back to using tried-and-true manual masking as per this page.

 

Bit setting, clearing and toggling.

Manual masking for bit clearing, setting, toggling is the right way to do it. (source: https://bit.ly/2xKguDc)

So it’s back to using the official documentation for XC8:

  1. The XC8 (v2) manual for PIC micros
  2. The XC8 (v2) manual for AVR micros
  3. The Legacy XC8 user guide (not sure if this applies to v2)

Read the official manual, indeed!