<avr/power.h>: Power Reduction Management

#include <avr/power.h>

Power Reduction Register

Many AVRs contain a Power Reduction Register (PRR) or Registers (PRRx) that allow you to reduce power consumption by disabling or enabling various on-board peripherals as needed.

There are many macros in this header file that provide an easy interface to enable or disable on-board peripherals to reduce power. See the table below.

Note:
Not all AVR devices have a Power Reduction Register (for example the ATmega128). On those devices without a Power Reduction Register, these macros are not available.

Not all AVR devices contain the same peripherals (for example, the LCD interface), or they will be named differently (for example, USART and USART0). Please consult your device's datasheet, or the header file, to find out which macros are applicable to your device.

Select your controller:

Clock Prescale

Some of the newer AVRs contain a System Clock Prescale Register (CLKPR) that allows you to decrease the system clock frequency and the power consumption when the need for processing power is low. Below are two macros and an enumerated type that can be used to interface to the Clock Prescale Register.

Note:
Not all AVR devices have a Clock Prescale Register. On those devices without a Clock Prescale Register, these macros are not available.
typedef enum {
  clock_div_1 = 0,
  clock_div_2 = 1,
  clock_div_4 = 2,
  clock_div_8 = 3,
  clock_div_16 = 4,
  clock_div_32 = 5,
  clock_div_64 = 6,
  clock_div_128 = 7,
  clock_div_256 = 8,
  clock_div_1_rc = 15,	// ATmega128RFA1 only
} clock_div_t;

__inline__ clock_prescale_set(x) {
  uint8_t tmp = _BV(CLKPCE);
  __asm__ __volatile__ (
"	in	__tmp_reg__,__SREG__	\n"
"	cli				\n"
"	sts	%1, %0			\n"
"	sts	%1, %2			\n"
"	out	__SREG__, __tmp_reg__	\n"	// no outputs
  :"d" (tmp), "M" (_SFR_MEM_ADDR(CLKPR)), "d" (x)
  :"r0");
}

#define clock_prescale_get() (clock_div_t)(CLKPR & (uint8_t)((1<<CLKPS0)|(1<<CLKPS1)|(1<<CLKPS2)|(1<<CLKPS3)))
Clock prescaler setting enumerations.

clock_prescale_set(x)

Set the clock prescaler register select bits, selecting a system clock division setting. They type of x is clock_div_t.

clock_prescale_get()

Gets and returns the clock prescaler register setting. The return type is clock_div_t.