8.7.1 set_sleep_mode Macro

Specify how the device is to behave in sleep mode.

Include

<avr/sleep.h>

Prototype

void set_sleep_mode(mode);

Remarks

This macro sets the appropriate bits in the device registers to specify how the device will behavein sleep mode. The mode argument can be the appropriate macros defined once you include <avr/sleep.h>, such as SLEEP_MODE_IDLE, SLEEP_MODE_PWR_DOWN, SLEEP_MODE_PWR_SAVE, SLEEP_MODE_STANDBY, etc.

Example

#include <xc.h>
#include <avr/sleep.h>
int main(void)
{
  set_sleep_mode(SLEEP_MODE_IDLE);
  cli();
  if (some_condition)
  {
    sleep_enable();
    sei();
    sleep_cpu();
    sleep_disable();
  }
  sei();
}