Common Macros in the MPLAB XC8 Compiler

Last modified by Microchip on 2023/11/09 09:13

Within the MPLAB® XC8 compiler are several common macros to make creating an application easier. These are automatically included when the xc.h header file is included in the project. MPLAB Code Configurator (MCC) will automatically include the xc.h header file.

Some common macros include:

  • SLEEP(): This will generate the code to put the device into sleep / low power mode when the program executes this macro at compile time.
  • NOP(): This will generate an assembly NOP instruction at the specific location of the macro. This makes it easy to add a single cycle delay without inserting assembly code.
  • CLRWDT(): This macro will generate a clear watchdog command without having to insert assembly code.
  • _ _DATE_ _: A double underscore in front and after "DATE" will create the macro to return a string of data with the date the code was compiled. i.e. "May 21 2019"
  • XC8 VERSION: This macro will return the version of the compiler used.