Sleep Mode Setup in MPLAB® XC Compilers

Last modified by Microchip on 2024/01/17 22:15

 

The MPLAB® XC compilers offer macros to invoke Sleep mode. Below is an example for each C compiler showing the sleep macro function for that compiler. Please note that they are case sensitive.

 /*******************************************************************************
  *          Enter Sleep mode
  * This macro issues the SLEEP instruction to shut down the system oscillator
  * and enter low power operating mode.
  ******************************************************************************/


#if defined(__XC8__)
       SLEEP();

#elif defined(__XC16__)
       Sleep();
       /* or */
        __builtin_pwrsav(0);
        Idle();

       /* or */
        __builtin_pwrsav(1);

#elif defined(__XC32__)
       /* Wait instruction */
        _wait();
#endif