Electronic – PIC16: How does one enter sleep mode using C

pic

The datasheet of my PIC16 refers to the "SLEEP instruction". I'm programming the PIC16 in C using MPLAB X and the XC8 compiler.

How can I execute a SLEEP instruction on my PIC16 using C?

Best Answer

You can use this macro:

SLEEP();  

This macro is used to put the device into a low-power standby mode.

If you search for the definition of SLEEP() in the header files, you'll find:

#define SLEEP()     asm("sleep")

asm(); is a statement which allows you to inline assembly instructions into your C code.