This documentation was generated automatically from the AVR Studio part description file ATmega406.pdf.

AD CONVERTER

12-bit resolution Sigmal-Delta ADC with +/-1 LSB Accuracy. 512 us conversion time.

VADMUX - The VADC multiplexer Selection Register

sfrb VADMUX = 0x7C;

VADMUX0 - Analog Channel and Gain Selection Bits

#define VADMUX0 0

The value of these bits selects which combination of analog inputs are connected to the ADC. These bits also select the gain for the differential channels. See Table 92 for details. If these bits are changed during a conversion, the change will not go in effect until this conversion is complete (ADIF in ADCSR is set).

VADMUX1 - Analog Channel and Gain Selection Bits

#define VADMUX1 1

The value of these bits selects which combination of analog inputs are connected to the ADC. These bits also select the gain for the differential channels. See Table 92 for details. If these bits are changed during a conversion, the change will not go in effect until this conversion is complete (ADIF in ADCSR is set).

VADMUX2 - Analog Channel and Gain Selection Bits

#define VADMUX2 2

The value of these bits selects which combination of analog inputs are connected to the ADC. These bits also select the gain for the differential channels. See Table 92 for details. If these bits are changed during a conversion, the change will not go in effect until this conversion is complete (ADIF in ADCSR is set).

VADMUX3 - Analog Channel and Gain Selection Bits

#define VADMUX3 3

The value of these bits selects which combination of analog inputs are connected to the ADC. These bits also select the gain for the differential channels. See Table 92 for details. If these bits are changed during a conversion, the change will not go in effect until this conversion is complete (ADIF in ADCSR is set).

VADCH - VADC Data Register High Byte

sfrb VADCH = 0x79;

VADCH0 - ADC Data Register High Byte Bit 0

#define VADCH0 0

VADCH1 - ADC Data Register High Byte Bit 1

#define VADCH1 1

VADCH2 - ADC Data Register High Byte Bit 2

#define VADCH2 2

VADCH3 - ADC Data Register High Byte Bit 3

#define VADCH3 3

VADCL - VADC Data Register Low Byte

sfrb VADCL = 0x78;

VADCL0 - ADC Data Register Low Byte Bit 0

#define VADCL0 0

VADCL1 - ADC Data Register Low Byte Bit 1

#define VADCL1 1

VADCL2 - ADC Data Register Low Byte Bit 2

#define VADCL2 2

VADCL3 - ADC Data Register Low Byte Bit 3

#define VADCL3 3

VADCL4 - ADC Data Register Low Byte Bit 4

#define VADCL4 4

VADCL5 - ADC Data Register Low Byte Bit 5

#define VADCL5 5

VADCL6 - ADC Data Register Low Byte Bit 6

#define VADCL6 6

VADCL7 - ADC Data Register Low Byte Bit 7

#define VADCL7 7

VADCSR - The VADC Control and Status register

sfrb VADCSR = 0x7A;

VADCCIE - VADC Conversion Complete Interrupt Enable

#define VADCCIE 0

When this bit is written to one and the I-Bit in SREG is set, the V-ADC Conversion Complete Interrupt is activated

VADCCIF - VADC Conversion Complete Interrupt Flag

#define VADCCIF 1

This bit is set when a V-ADC conversion completes and the data registers are updated.V-ADC Conversion complete Interrupt is executed if the VADCCIE bit and the I-bit in S-REG are set. VADCCIF is cleared by hardware when executing the corresponding interrupt handling vector. Alternatively, VADCCIF is cleared by writing a logical one to the flag. Beware that if doing a Read-Modify-Write on VADCSR, a pending interrupt can be disabled.

VADSC - VADC Satrt Conversion

#define VADSC 2

Write this bit to one to start a new conversion of the selected channel. VADSC will read as one as long as the conversion is not finished. When the conversion is complete, it returns to zero. Writing zero to this bit has no effect.

VADEN - VADC Enable

#define VADEN 3

Writing this bit to one enables V-ADC Conversion. By writing it to zero, the V-ADC is turned off. Turning the V-ADC off while a conversion is in progress will terminate this conversion

EXTERNAL INTERRUPT

The external interrupts are triggered by the INT7:0 pins. Observe that, if enabled, the interrupts will trigger even if the INT7:0 pins are configured as outputs. This feature provides a way of generating a software interrupt. The external inter-rupts can be triggered by a falling or rising edge or a low level. This is set up as indicated in the specification for the Exter-nal Interrupt Control Registers - EICRA (INT3:0) and EICRB (INT7:4). When the external interrupt is enabled and is configured as level triggered, the interrupt will trigger as long as the pin is held low. Note that recognition of falling or rising edge interrupts on INT7:4 requires the presence of an I/O clock, described in ?Clock Systems and their Distribution? on page 29. Low level interrupts and the edge interrupt on INT3:0 are detected asynchronously. This implies that these inter-rupts can be used for waking the part also from sleep modes other than Idle mode. The I/O clock is halted in all sleep modes except Idle mode. Note that if a level triggered interrupt is used for wake-up from Power Down Mode, the changed level must be held for some time to wake up the MCU. This makes the MCU less sensitive to noise. The changed level is sampled twice by the watchdog oscillator clock. The period of the watchdog oscillator is 1 µs (nominal) at 5.0V and 25°C. The frequency of the watchdog oscillator is voltage dependent as shown in the Electrical Characteristics section. The MCU will wake up if the input has the required level during this sampling or if it is held until the end of the start-up time. The start-up time is defined by the SUT fuses as described in ?Clock Systems and their Distribution? on page 29. If the level is sampled twice by the watchdog oscillator clock but disappears before the end of the start-up time, the MCU will still wake up, but no interrupt will be generated. The required level must be held long enough for the MCU to complete the wake up to trigger the level interru

EICRA - External Interrupt Control Register

sfrb EICRA = 0x69;

ISC00 - External Interrupt Sense Control 0 Bit 0

#define ISC00 0

The External Interrupt 0 is activated by the external pin INT0 if the SREG I-flag and the corresponding interrupt mask are set.The value on the INT0 pin is sampled before detecting edges.If edge or toggle interrupt is selected,pulses that last longer than one clock period will generate an interrupt.Shorter pulses are not guaranteed to generate an interrupt.If low level interrupt is selected,the lowlevel must be held until the completion of the currently executing instruction to generate an interrupt.

ISC01 - External Interrupt Sense Control 0 Bit 1

#define ISC01 1

The External Interrupt 0 is activated by the external pin INT0 if the SREG I-flag and the corresponding interrupt mask are set.The value on the INT0 pin is sampled before detecting edges.If edge or toggle interrupt is selected,pulses that last longer than one clock period will generate an interrupt.Shorter pulses are not guaranteed to generate an interrupt.If low level interrupt is selected,the lowlevel must be held until the completion of the currently executing instruction to generate an interrupt.

ISC10 - External Interrupt Sense Control 1 Bit 0

#define ISC10 2

The External Interrupt 1 is activated by the external pin INT1 if the SREG I-flag and the corresponding interrupt mask are set.The value on the INT1 pin is sampled before detecting edges.If edge or toggle interrupt is selected,pulses that last longer than one clock period will generate an interrupt.Shorter pulses are not guaranteed to generate an interrupt.If low level interrupt is selected,the lowlevel must be held until the completion of the currently executing instruction to generate an interrupt.

ISC11 - External Interrupt Sense Control 1 Bit 1

#define ISC11 3

The External Interrupt 1 is activated by the external pin INT1 if the SREG I-flag and the corresponding interrupt mask are set.The value on the INT1 pin is sampled before detecting edges.If edge or toggle interrupt is selected,pulses that last longer than one clock period will generate an interrupt.Shorter pulses are not guaranteed to generate an interrupt.If low level interrupt is selected,the lowlevel must be held until the completion of the currently executing instruction to generate an interrupt.

ISC20 - External Interrupt Sense Control 2 Bit 0

#define ISC20 4

The External Interrupt 1 is activated by the external pin INT1 if the SREG I-flag and the corresponding interrupt mask are set.The value on the INT1 pin is sampled before detecting edges.If edge or toggle interrupt is selected,pulses that last longer than one clock period will generate an interrupt.Shorter pulses are not guaranteed to generate an interrupt.If low level interrupt is selected,the lowlevel must be held until the completion of the currently executing instruction to generate an interrupt.

ISC21 - External Interrupt Sense Control 2 Bit 1

#define ISC21 5

The External Interrupt 1 is activated by the external pin INT1 if the SREG I-flag and the corresponding interrupt mask are set.The value on the INT1 pin is sampled before detecting edges.If edge or toggle interrupt is selected,pulses that last longer than one clock period will generate an interrupt.Shorter pulses are not guaranteed to generate an interrupt.If low level interrupt is selected,the lowlevel must be held until the completion of the currently executing instruction to generate an interrupt.

ISC30 - External Interrupt Sense Control 3 Bit 0

#define ISC30 6

The External Interrupt 1 is activated by the external pin INT1 if the SREG I-flag and the corresponding interrupt mask are set.The value on the INT1 pin is sampled before detecting edges.If edge or toggle interrupt is selected,pulses that last longer than one clock period will generate an interrupt.Shorter pulses are not guaranteed to generate an interrupt.If low level interrupt is selected,the lowlevel must be held until the completion of the currently executing instruction to generate an interrupt.

ISC31 - External Interrupt Sense Control 3 Bit 1

#define ISC31 7

The External Interrupt 1 is activated by the external pin INT1 if the SREG I-flag and the corresponding interrupt mask are set.The value on the INT1 pin is sampled before detecting edges.If edge or toggle interrupt is selected,pulses that last longer than one clock period will generate an interrupt.Shorter pulses are not guaranteed to generate an interrupt.If low level interrupt is selected,the lowlevel must be held until the completion of the currently executing instruction to generate an interrupt.

EIMSK - External Interrupt Mask Register

sfrb EIMSK = 0x1D;

INT0 - External Interrupt Request 0 Enable

#define INT0 0

When the INT0 bit is set (one)and the I-bit in the Status Register (SREG)is set (one),the external pin interrupt is enabled. The Interrupt Sense Control0 bits 1/0 (ISC01 and ISC00)in the External Interrupt Control Register A (EICRA)define whether the external interrupt is activated on rising and/or falling edge of the INT0 pin or level sensed.Activity on the pin will cause an interrupt request even if INT0 is configured as an output.The corresponding interrupt of External Interrupt Request 0 is executed from the INT0 interrupt vector.

INT1 - External Interrupt Request 1 Enable

#define INT1 1

When the INT1 bit is set (one)and the I-bit in the Status Register (SREG)is set (one),the external pin interrupt is enabled. The Interrupt Sense Control1 bits 1/0 (ISC11 and ISC10)in the External Interrupt Control Register A (EICRA)define whether the external interrupt is activated on rising and/or falling edge of the INT1 pin or level sensed.Activity on the pin will cause an interrupt request even if INT1 is configured as an output.The corresponding interrupt of External Interrupt Request 1 is executed from the INT1 interrupt vector.

INT2 - External Interrupt Request 1 Enable

#define INT2 2

When the INT2 bit is set (one)and the I-bit in the Status Register (SREG)is set (one),the external pin interrupt is enabled. The Interrupt Sense Control1 bits 1/0 (ISC11 and ISC10)in the External Interrupt Control Register A (EICRA)define whether the external interrupt is activated on rising and/or falling edge of the INT1 pin or level sensed.Activity on the pin will cause an interrupt request even if INT1 is configured as an output.The corresponding interrupt of External Interrupt Request 1 is executed from the INT1 interrupt vector.

INT3 - External Interrupt Request 1 Enable

#define INT3 3

When the INT3 bit is set (one)and the I-bit in the Status Register (SREG)is set (one),the external pin interrupt is enabled. The Interrupt Sense Control1 bits 1/0 (ISC11 and ISC10)in the External Interrupt Control Register A (EICRA)define whether the external interrupt is activated on rising and/or falling edge of the INT1 pin or level sensed.Activity on the pin will cause an interrupt request even if INT1 is configured as an output.The corresponding interrupt of External Interrupt Request 1 is executed from the INT1 interrupt vector.

EIFR - External Interrupt Flag Register

sfrb EIFR = 0x1C;

INTF0 - External Interrupt Flag 0

#define INTF0 0

When an edge or logic change on the INT0 pin triggers an interrupt request,INTF0 becomes set (one).If the I-bit in SREG and the INT0 bit in EIMSK are set (one),the MCU will jump to the corresponding interrupt vector.The flag is cleared when the interrupt routine is executed.Alternatively,the flag can be cleared by writing a logical one to it.This flag is always cleared when INT0 is configured as a level interrupt.

INTF1 - External Interrupt Flag 1

#define INTF1 1

When an edge or logic change on the INT1 pin triggers an interrupt request,INTF1 becomes set (one).If the I-bit in SREG and the INT1 bit in EIMSK are set (one),the MCU will jump to the corresponding interrupt vector.The flag is cleared when the interrupt routine is executed.Alternatively,the flag can be cleared by writing a logical one to it.This flag is always cleared when INT0 is configured as a level interrupt.

INTF2 - External Interrupt Flag 2

#define INTF2 2

When an edge or logic change on the INT1 pin triggers an interrupt request,INTF1 becomes set (one).If the I-bit in SREG and the INT1 bit in EIMSK are set (one),the MCU will jump to the corresponding interrupt vector.The flag is cleared when the interrupt routine is executed.Alternatively,the flag can be cleared by writing a logical one to it.This flag is always cleared when INT0 is configured as a level interrupt.

INTF3 - External Interrupt Flag 3

#define INTF3 3

When an edge or logic change on the INT1 pin triggers an interrupt request,INTF1 becomes set (one).If the I-bit in SREG and the INT1 bit in EIMSK are set (one),the MCU will jump to the corresponding interrupt vector.The flag is cleared when the interrupt routine is executed.Alternatively,the flag can be cleared by writing a logical one to it.This flag is always cleared when INT0 is configured as a level interrupt.

PCICR - Pin Change Interrupt Control Register

sfrb PCICR = 0x68;

PCIE0 - Pin Change Interrupt Enable 0

#define PCIE0 0

When the PCIE0 bit is set (one) and the I-bit in the Status Register (SREG) is set (one), pin change interrupt 0 is enabled. Any change on any enabled PCINT7..0 pin will cause an interrupt. The corresponding interrupt of Pin Change Interrupt Request is executed from the PCI0 Interrupt Vector. PCINT7..0 pins are enabled individually by the PCMSK0 Register.

PCIE1 - Pin Change Interrupt Enable 1

#define PCIE1 1

When the PCIE1 bit is set (one) and the I-bit in the Status Register (SREG) is set (one), pin change interrupt 1 is enabled. Any change on any enabled PCINT15..8 pin will cause an interrupt. The corresponding interrupt of Pin Change Interrupt Request is executed from the PCI1 Interrupt Vector. PCINT15..8 pins are enabled individually by the PCMSK1 Register.

PCIFR - Pin Change Interrupt Flag Register

sfrb PCIFR = 0x1B;

PCIF0 - Pin Change Interrupt Flag 1

#define PCIF0 0

When a logic change on any PCINT7..0 pin triggers an interrupt request, PCIF0 becomes set (one). If the I-bit in SREG and the PCIE0 bit in PCICR are set (one), the MCU will jump to the corresponding Interrupt Vector. The flag is cleared when the interrupt routine is executed. Alternatively, the flag can be cleared by writing a logical one to it.

PCIF1 - Pin Change Interrupt Flag 1

#define PCIF1 1

When a logic change on any PCINT15..8 pin triggers an interrupt request, PCIF1 becomes set (one). If the I-bit in SREG and the PCIE1 bit in PCICR are set (one), the MCU will jump to the corresponding Interrupt Vector. The flag is cleared when the interrupt routine is executed. Alternatively, the flag can be cleared by writing a logical one to it.

PCMSK1 - Pin Change Enable Mask Register 1

sfrb PCMSK1 = 0x6C;

PCINT8 - Pin Change Enable Mask 8

#define PCINT8 0

PCINT9 - Pin Change Enable Mask 9

#define PCINT9 1

PCINT10 - Pin Change Enable Mask 10

#define PCINT10 2

PCINT11 - Pin Change Enable Mask 11

#define PCINT11 3

PCINT12 - Pin Change Enable Mask 12

#define PCINT12 4

PCINT13 - Pin Change Enable Mask 13

#define PCINT13 5

PCINT14 - Pin Change Enable Mask 14

#define PCINT14 6

PCINT15 - Pin Change Enable Mask 15

#define PCINT15 7

PCMSK0 - Pin Change Enable Mask Register 0

sfrb PCMSK0 = 0x6B;

PCINT0 - Pin Change Enable Mask 0

#define PCINT0 0

PCINT1 - Pin Change Enable Mask 1

#define PCINT1 1

PCINT2 - Pin Change Enable Mask 2

#define PCINT2 2

PCINT3 - Pin Change Enable Mask 3

#define PCINT3 3

PCINT4 - Pin Change Enable Mask 4

#define PCINT4 4

PCINT5 - Pin Change Enable Mask 5

#define PCINT5 5

PCINT6 - Pin Change Enable Mask 6

#define PCINT6 6

PCINT7 - Pin Change Enable Mask 7

#define PCINT7 7

TIMER COUNTER 1

TCCR1B - Timer/Counter1 Control Register B

sfrb TCCR1B = 0x81;

CS10 - Clock Select1 bit 0

#define CS10 0

CS11 - Clock Select1 bit 1

#define CS11 1

CS12 - Clock Select1 bit 2

#define CS12 2

CTC1 - Clear Timer/Counter on Compare Match

#define CTC1 3

TCNT1H - Timer Counter 1 High Byte

sfrb TCNT1H = 0x85;

TCNT1H0 - Timer Counter 1 High Byte bit 0

#define TCNT1H0 0

TCNT1H1 - Timer Counter 1 High Byte bit 1

#define TCNT1H1 1

TCNT1H2 - Timer Counter 1 High Byte bit 2

#define TCNT1H2 2

TCNT1H3 - Timer Counter 1 High Byte bit 3

#define TCNT1H3 3

TCNT1H4 - Timer Counter 1 High Byte bit 4

#define TCNT1H4 4

TCNT1H5 - Timer Counter 1 High Byte bit 5

#define TCNT1H5 5

TCNT1H6 - Timer Counter 1 High Byte bit 6

#define TCNT1H6 6

TCNT1H7 - Timer Counter 1 High Byte bit 7

#define TCNT1H7 7

TCNT1L - Timer Counter 1 Low Byte

sfrb TCNT1L = 0x84;

TCNT1L0 - Timer Counter 1 Low Byte bit 0

#define TCNT1L0 0

TCNT1L1 - Timer Counter 1 Low Byte bit 1

#define TCNT1L1 1

TCNT1L2 - Timer Counter 1 Low Byte bit 2

#define TCNT1L2 2

TCNT1L3 - Timer Counter 1 Low Byte bit 3

#define TCNT1L3 3

TCNT1L4 - Timer Counter 1 Low Byte bit 4

#define TCNT1L4 4

TCNT1L5 - Timer Counter 1 Low Byte bit 5

#define TCNT1L5 5

TCNT1L6 - Timer Counter 1 Low Byte bit 6

#define TCNT1L6 6

TCNT1L7 - Timer Counter 1 Low Byte bit 7

#define TCNT1L7 7

OCR1AL - Output Compare Register 1A Low byte

sfrb OCR1AL = 0x88;

OCR1AL0

#define OCR1AL0 0

OCR1AL1

#define OCR1AL1 1

OCR1AL2

#define OCR1AL2 2

OCR1AL3

#define OCR1AL3 3

OCR1AL4

#define OCR1AL4 4

OCR1AL5

#define OCR1AL5 5

OCR1AL6

#define OCR1AL6 6

OCR1AL7

#define OCR1AL7 7

OCR1AH - Output Compare Register 1A High byte

sfrb OCR1AH = 0x89;

OCR1AH0

#define OCR1AH0 0

OCR1AH1

#define OCR1AH1 1

OCR1AH2

#define OCR1AH2 2

OCR1AH3

#define OCR1AH3 3

OCR1AH4

#define OCR1AH4 4

OCR1AH5

#define OCR1AH5 5

OCR1AH6

#define OCR1AH6 6

OCR1AH7

#define OCR1AH7 7

TIMSK1 - Timer/Counter Interrupt Mask Register

sfrb TIMSK1 = 0x6F;

TOIE1 - Timer/Counter1 Overflow Interrupt Enable

#define TOIE1 0

OCIE1A - Timer/Counter1 Output Compare Interrupt Enable

#define OCIE1A 1

TIFR1 - Timer/Counter Interrupt Flag register

sfrb TIFR1 = 0x16;

TOV1 - Timer/Counter1 Overflow Flag

#define TOV1 0

OCF1A - Timer/Counter1 Output Compare Flag A

#define OCF1A 1

GTCCR - General Timer/Counter Control Register

sfrb GTCCR = 0x23;

PSRSYNC - Prescaler Reset

#define PSRSYNC 0

PSRASY

#define PSRASY 1

TSM - Timer/Counter Synchronization Mode

#define TSM 7

WAKEUP TIMER

WUTCSR - Wake-up Timer Control Register

sfrb WUTCSR = 0x62;

WUTP0 - Wake-up Timer Prescaler Bit 0

#define WUTP0 0

The WUTP2, WUTP1 and WUTP0 bits determine the Wake-up Timer prescaling when the Wake-up Timer is enabled. The different prescaling values and their corresponding time-out periods are shown in the datasheet.

WUTP1 - Wake-up Timer Prescaler Bit 1

#define WUTP1 1

The WUTP2, WUTP1 and WUTP0 bits determine the Wake-up Timer prescaling when the Wake-up Timer is enabled. The different prescaling values and their corresponding time-out periods are shown in the datasheet.

WUTP2 - Wake-up Timer Prescaler Bit 2

#define WUTP2 2

The WUTP2, WUTP1 and WUTP0 bits determine the Wake-up Timer prescaling when the Wake-up Timer is enabled. The different prescaling values and their corresponding time-out periods are shown in the datasheet.

WUTE - Wake-up Timer Enable

#define WUTE 3

When the WUTE is set (one) the Wake-up Timer is enabled, and the WUTE is cleared (zero) the Wake-up Timer function is disabled.

WUTR - Wake-up Timer Reset

#define WUTR 4

When WUTR is written to one, the Wake-up Timer is reset, and starts counting from zero. The WUTR bit is automatically cleared to zero after the reset has been performed.

WUTCF - Wake-up timer Calibration Flag

#define WUTCF 5

The WUTCF bit is set after every 256 Slow RC OScillator clocks (2 ms @ 131 kHz)

WUTIE - Wake-up Timer Interrupt Enable

#define WUTIE 6

When the WUTIE bit and the I-bit in the Status Register are set (one), the Wake-up Timer interrupt is enabled. The corresponding interrupt is executed if a Wake-up Timer overflow occurs, i.e., when the WUTIF bit is set .

WUTIF - Wake-up Timer Interrupt Flag

#define WUTIF 7

The bit WUTIF is set (one) when an overflow occurs in the Wake-up Timer. WUTIF is cleared by hardware when executing the corresponding interrupt handling vector. Alternatively, TOV0 is cleared by writing a logic one to the flag. When the SREG I-bit, WUTIE (Wake-up Timer Interrupt Enable), and WUTIF are set (one), the Wake-up Timer interrupt is executed.

BATTERY PROTECTION

BPPLR - Battery Protection Parameter Lock Register

sfrb BPPLR = 0xF8;

BPPL - Battery Protection Parameter Lock

#define BPPL 0

BPPLE - Battery Protection Parameter Lock Enable

#define BPPLE 1

BPCR - Battery Protection Control Register

sfrb BPCR = 0xF7;

CCD

#define CCD 0

DCD

#define DCD 1

SCD

#define SCD 2

DUVD

#define DUVD 3

CBPTR - Current Battery Protection Timing Register

sfrb CBPTR = 0xF6;

OCPT0

#define OCPT0 0

OCPT1

#define OCPT1 1

OCPT2

#define OCPT2 2

OCPT3

#define OCPT3 3

SCPT0

#define SCPT0 4

SCPT1

#define SCPT1 5

SCPT2

#define SCPT2 6

SCPT3

#define SCPT3 7

BPOCD - Battery Protection OverCurrent Detection Level Register

sfrb BPOCD = 0xF5;

CCDL0

#define CCDL0 0

CCDL1

#define CCDL1 1

CCDL2

#define CCDL2 2

CCDL3

#define CCDL3 3

DCDL0

#define DCDL0 4

DCDL1

#define DCDL1 5

DCDL2

#define DCDL2 6

DCDL3

#define DCDL3 7

BPSCD - Battery Protection Short-Circuit Detection Level Register

sfrb BPSCD = 0xF4;

SCDL0

#define SCDL0 0

SCDL1

#define SCDL1 1

SCDL2

#define SCDL2 2

SCDL3

#define SCDL3 3

BPDUV - Battery Protection Deep Under Voltage Register

sfrb BPDUV = 0xF3;

DUDL0

#define DUDL0 0

DUDL1

#define DUDL1 1

DUDL2

#define DUDL2 2

DUDL3

#define DUDL3 3

DUVT0

#define DUVT0 4

DUVT1

#define DUVT1 5

BPIR - Battery Protection Interrupt Register

sfrb BPIR = 0xF2;

SCIE

#define SCIE 0

DOCIE

#define DOCIE 1

COCIE

#define COCIE 2

DUVIE - Deep Under-voltage Early Warning Interrupt Enable

#define DUVIE 3

SCIF

#define SCIF 4

DOCIF

#define DOCIF 5

COCIF - Charge Over-current Protection Activated Interrupt Flag

#define COCIF 6

DUVIF - Deep Under-voltage Early Warning Interrupt Flag

#define DUVIF 7

FET

FCSR -

sfrb FCSR = 0xF0;

PFD - Precharge FET disable

#define PFD 0

The PFD bit provides complete control of the Precharge FET. When the PFD bit is cleared (zero), the Precharge FET will be enabled. When the PFD bit is set (one), the Precharge FET will be disabled. This bit will be set when CURRENT_PROTECTION is set (one).

CFE - Charge FET Enable

#define CFE 1

When the CFE bit is cleared (zero), the Charge FET will be disabled regardless of the state of the Battery Protection circuitry. When this bit is set (one), the Charge FET state is determined by the Battery Protection circuitry. This bit will be cleared when CURRENT_PROTECTION is set (one).

DFE - Discharge FET Enable

#define DFE 2

When the DFE bit is cleared (zero), the Discharge FET will be disabled regardless of the state of the Battery Protection circuitry. When this bit is set (one), the Discharge FET state is determined by the Battery Protection circuitry. This bit will be cleared when CURRENT_PROTECTION is set (one).

CPS - Current Protection Status

#define CPS 3

The CPTS bit shows the status of the Current Protection. This bit is set (one) when the Current Protection Timer is activated, and is cleared (zero) when the hold-off time has elapsed.

PWMOPC - Pulse Width Modulation Modulation of OPC output

#define PWMOPC 4

When the PWMOPC is cleared (zero), the PFD bit and the battery protection circuitry controls the OPC output. When this bit is set (one), the OC output will be controlled by the PWM output from the 8-bit Timer/Counter0 and the battery protection circuitry.

PWMOC - Pulse Width Modulation of OC output

#define PWMOC 5

When the PWMOC is cleared (zero), the CFE bit and the battery protection circuitry controls the OC output. When this bit is set (one), the OC output will be controlled by the PWM output from the 8-bit Timer/Counter0 and the battery protection circuitry.

COULOMB COUNTER

CADCSRA - CC-ADC Control and Status Register A

sfrb CADCSRA = 0xE4;

CADSE - When the CADSE bit is written to one, the ongoing CC-ADC conversion is aborted, and the CC-ADC enters Regular Current detection mode.

#define CADSE 0

CADSI0 - The CADSI bits determine the current sampling interval for the Regular Current detection in Power-down mode. The actual settings remain to be determined.

#define CADSI0 1

CADSI1 - The CADSI bits determine the current sampling interval for the Regular Current detection in Power-down mode. The actual settings remain to be determined.

#define CADSI1 2

CADAS0 - CC_ADC Accumulate Current Select Bit 0

#define CADAS0 3

The CADAS bits select the conversion time for the Accumulate Current output. Please refer to table 45 in the manual.

CADAS1 - CC_ADC Accumulate Current Select Bit 1

#define CADAS1 4

The CADAS bits select the conversion time for the Accumulate Current output. Please refer to table 45 in the manual.

CADUB - CC_ADC Update Busy

#define CADUB 5

CADEN - When the CADEN bit is cleared (zero), the CC-ADC is disabled. When the CADEN bit is set (one), the CC-ADC will continuously measure the voltage drop over the external sense resistor RSENSE. In Power-down, only the Regular Current detection is active. In Power-off, the CC-ADC is always disabled.

#define CADEN 7

CADCSRB - CC-ADC Control and Status Register B

sfrb CADCSRB = 0xE5;

CADICIF - CC-ADC Instantaneous Current Interrupt Flag

#define CADICIF 0

The CADICIF bit is set (one) when a CC-ADC Instantaneous Current conversion is completed. The CC-ADC Instantaneous Current Interrupt is executed if the CADICIE bit and the I-bit in SREG are set (one). CADICIF is cleared by hardware when executing the corresponding Interrupt Handling vector. Alternatively, CADICIF is cleared by writing a logic one to the flag.

CADRCIF - CC-ADC Accumulate Current Interrupt Flag

#define CADRCIF 1

The CADACIF bit is set (one) after the Accumulate Current conversion has completed. The CC-ADC Accumulate Current Interrupt is executed if the CADAIE bit and the I-bit in SREG are set (one). CADACIF is cleared by hardware when executing the corresponding Interrupt Handling Vector. Alternatively, CADACIF is cleared by writing a logic one to the flag. he CADRCIF bit is set (one) when the absolute value of the result of the last CC-ADC conversion is greater than, or equal to, the compare values set by the CC-ADC Regular Charge/Discharge Current Level Registers. A positive value is compared to the Regular Charge Current Level, and a negative value is compared to the Regular Discharge Current Level. The CC-ADC Regular Current Interrupt is executed if the CADRCIE bit and the I-bit in SREG are set (one). CADRCIF is cleared by hardware when executing the corresponding Interrupt Handling vector. Alternatively, CADRCIF is cleared by writing a logic one to the flag.

CADACIF - CC-ADC Accumulate Current Interrupt Flag

#define CADACIF 2

The CADACIF bit is set (one) after the Accumulate Current conversion has completed. The CC-ADC Accumulate Current Interrupt is executed if the CADAIE bit and the I-bit in SREG are set (one). CADACIF is cleared by hardware when executing the corresponding Interrupt Handling Vector. Alternatively, CADACIF is cleared by writing a logic one to the flag. he CADRCIF bit is set (one) when the absolute value of the result of the last CC-ADC conversion is greater than, or equal to, the compare values set by the CC-ADC Regular Charge/Discharge Current Level Registers. A positive value is compared to the Regular Charge Current Level, and a negative value is compared to the Regular Discharge Current Level. The CC-ADC Regular Current Interrupt is executed if the CADRCIE bit and the I-bit in SREG are set (one). CADRCIF is cleared by hardware when executing the corresponding Interrupt Handling vector. Alternatively, CADRCIF is cleared by writing a logic one to the flag.

CADICIE - CAD Instantenous Current Interrupt Enable

#define CADICIE 4

The CADACT bits determine the conversion time for the Accumulate Current output as shown in Table 43.

CADRCIE - Regular Current Interrupt Enable

#define CADRCIE 5

When the CADACIE bit is set (one), and the I-bit in the Status Register is set (one), the CC-ADC Accumulate Current Interrupt is enabled.

CADACIE

#define CADACIE 6

CC-ADC Accumulate Current Interrupt Enable

CADICH - CC-ADC Instantaneous Current

sfrb CADICH = 0xE9;

CADICH0 - When the CADSE bit is written to one, the ongoing CC-ADC conversion is aborted, and the CC-ADC enters Regular Current detection mode.

#define CADICH0 0

CADICH1 - The CADSI bits determine the current sampling interval for the Regular Current detection in Power-down mode. The actual settings remain to be determined.

#define CADICH1 1

CADICH2 - The CADSI bits determine the current sampling interval for the Regular Current detection in Power-down mode. The actual settings remain to be determined.

#define CADICH2 2

CADICH3 - The CADACT bits determine the conversion time for the Accumulate Current output as shown in Table 43.

#define CADICH3 3

CADICH4 - The CADACT bits determine the conversion time for the Accumulate Current output as shown in Table 43.

#define CADICH4 4

CADICH5

#define CADICH5 5

CADICH6

#define CADICH6 6

CADICH7 - When the CADEN bit is cleared (zero), the CC-ADC is disabled. When the CADEN bit is set (one), the CC-ADC will continuously measure the voltage drop over the external sense resistor RSENSE. In Power-down, only the Regular Current detection is active. In Power-off, the CC-ADC is always disabled.

#define CADICH7 7

CADICL - CC-ADC Instantaneous Current

sfrb CADICL = 0xE8;

CADICL0 - When the CADSE bit is written to one, the ongoing CC-ADC conversion is aborted, and the CC-ADC enters Regular Current detection mode.

#define CADICL0 0

CADICL1 - The CADSI bits determine the current sampling interval for the Regular Current detection in Power-down mode. The actual settings remain to be determined.

#define CADICL1 1

CADICL2 - The CADSI bits determine the current sampling interval for the Regular Current detection in Power-down mode. The actual settings remain to be determined.

#define CADICL2 2

CADICL3 - The CADACT bits determine the conversion time for the Accumulate Current output as shown in Table 43.

#define CADICL3 3

CADICL4 - The CADACT bits determine the conversion time for the Accumulate Current output as shown in Table 43.

#define CADICL4 4

CADICL5

#define CADICL5 5

CADICL6

#define CADICL6 6

CADICL7 - When the CADEN bit is cleared (zero), the CC-ADC is disabled. When the CADEN bit is set (one), the CC-ADC will continuously measure the voltage drop over the external sense resistor RSENSE. In Power-down, only the Regular Current detection is active. In Power-off, the CC-ADC is always disabled.

#define CADICL7 7

CADAC3 - ADC Accumulate Current

sfrb CADAC3 = 0xE3;

CADAC24

#define CADAC24 0

CADAC25

#define CADAC25 1

CADAC26

#define CADAC26 2

CADAC27

#define CADAC27 3

CADAC28

#define CADAC28 4

CADAC29

#define CADAC29 5

CADAC30

#define CADAC30 6

CADAC31

#define CADAC31 7

CADAC2 - ADC Accumulate Current

sfrb CADAC2 = 0xE2;

CADAC16

#define CADAC16 0

CADAC17

#define CADAC17 1

CADAC18

#define CADAC18 2

CADAC19

#define CADAC19 3

CADAC20

#define CADAC20 4

CADAC21

#define CADAC21 5

CADAC22

#define CADAC22 6

CADAC23

#define CADAC23 7

CADAC1 - ADC Accumulate Current

sfrb CADAC1 = 0xE1;

CADAC08

#define CADAC08 0

CADAC09

#define CADAC09 1

CADAC10

#define CADAC10 2

CADAC11

#define CADAC11 3

CADAC12

#define CADAC12 4

CADAC13

#define CADAC13 5

CADAC14

#define CADAC14 6

CADAC15

#define CADAC15 7

CADAC0 - ADC Accumulate Current

sfrb CADAC0 = 0xE0;

CADAC00

#define CADAC00 0

CADAC01

#define CADAC01 1

CADAC02

#define CADAC02 2

CADAC03

#define CADAC03 3

CADAC04

#define CADAC04 4

CADAC05

#define CADAC05 5

CADAC06

#define CADAC06 6

CADAC07

#define CADAC07 7

CADRCC - CC-ADC Regular Charge Current

sfrb CADRCC = 0xE6;

CADRCC0 - When the CADSE bit is written to one, the ongoing CC-ADC conversion is aborted, and the CC-ADC enters Regular Current detection mode.

#define CADRCC0 0

CADRCC1 - The CADSI bits determine the current sampling interval for the Regular Current detection in Power-down mode. The actual settings remain to be determined.

#define CADRCC1 1

CADRCC2 - The CADSI bits determine the current sampling interval for the Regular Current detection in Power-down mode. The actual settings remain to be determined.

#define CADRCC2 2

CADRCC3 - The CADACT bits determine the conversion time for the Accumulate Current output as shown in Table 43.

#define CADRCC3 3

CADRCC4 - The CADACT bits determine the conversion time for the Accumulate Current output as shown in Table 43.

#define CADRCC4 4

CADRCC5

#define CADRCC5 5

CADRCC6

#define CADRCC6 6

CADRCC7 - When the CADEN bit is cleared (zero), the CC-ADC is disabled. When the CADEN bit is set (one), the CC-ADC will continuously measure the voltage drop over the external sense resistor RSENSE. In Power-down, only the Regular Current detection is active. In Power-off, the CC-ADC is always disabled.

#define CADRCC7 7

CADRDC - CC-ADC Regular Discharge Current

sfrb CADRDC = 0xE7;

CADRDC0 - When the CADSE bit is written to one, the ongoing CC-ADC conversion is aborted, and the CC-ADC enters Regular Current detection mode.

#define CADRDC0 0

CADRDC1 - The CADSI bits determine the current sampling interval for the Regular Current detection in Power-down mode. The actual settings remain to be determined.

#define CADRDC1 1

CADRDC2 - The CADSI bits determine the current sampling interval for the Regular Current detection in Power-down mode. The actual settings remain to be determined.

#define CADRDC2 2

CADRDC3 - The CADACT bits determine the conversion time for the Accumulate Current output as shown in Table 43.

#define CADRDC3 3

CADRDC4 - The CADACT bits determine the conversion time for the Accumulate Current output as shown in Table 43.

#define CADRDC4 4

CADRDC5

#define CADRDC5 5

CADRDC6

#define CADRDC6 6

CADRDC7 - When the CADEN bit is cleared (zero), the CC-ADC is disabled. When the CADEN bit is set (one), the CC-ADC will continuously measure the voltage drop over the external sense resistor RSENSE. In Power-down, only the Regular Current detection is active. In Power-off, the CC-ADC is always disabled.

#define CADRDC7 7

CELL BALANCING

CBCR - Cell Balancing Control Register

sfrb CBCR = 0xF1;

CBE1 - Battery Protection Parameter Lock

#define CBE1 0

CBE2 - Cell Balancing Enable 2

#define CBE2 1

CBE3 - Cell Balancing Enable 4

#define CBE3 2

CBE4 - Cell Balancing Enable 4

#define CBE4 3

CPU

SREG - Status Register

sfrb SREG = 0x3F;

SPH - Stack Pointer High

sfrb SPH = 0x3E;

SP8 - Stack pointer bit 8

#define SP8 0

SP9 - Stack pointer bit 9

#define SP9 1

SP10 - Stack pointer bit 10

#define SP10 2

SP11 - Stack pointer bit 11

#define SP11 3

SP12

#define SP12 4

SP13 - Stack pointer bit 13

#define SP13 5

SP14 - Stack pointer bit 14

#define SP14 6

SP15 - Stack pointer bit 15

#define SP15 7

SPL - Stack Pointer Low

sfrb SPL = 0x3D;

SP0 - Stack pointer bit 0

#define SP0 0

SP1 - Stack pointer bit 1

#define SP1 1

SP2 - Stack pointer bit 2

#define SP2 2

SP3 - Stack pointer bit 3

#define SP3 3

SP4

#define SP4 4

SP5 - Stack pointer bit 5

#define SP5 5

SP6 - Stack pointer bit 6

#define SP6 6

SP7 - Stack pointer bit 7

#define SP7 7

MCUCR - MCU Control Register

sfrb MCUCR = 0x35;

IVCE - Interrupt Vector Change Enable

#define IVCE 0

The IVCE bit must be written to logic one to enable change of the IVSEL bit.IVCE is cleared by hardware four cycles after it is written or when IVSEL is written.Setting the IVCE bit will disable interrupts.

IVSEL - Interrupt Vector Select

#define IVSEL 1

When the IVSEL bit is cleared (zero),the interrupt vectors are placed at the start of the Flash memory.When this bit is set (one),the interrupt vectors are moved to the beginning of the Boot Loader section of the flash.The actual address of the start of the boot flash section is determined by the BOOTSZ fuses.

PUD - Pull-up disable

#define PUD 4

When this bit is written to one,the pull-ups in the I/O ports are disabled even if the DDxn and PORTxn registers are configured to enable the pull-ups ({DDxn,PORTxn}=0b01).

JTD - JTAG Disable

#define JTD 7

MCUSR - MCU Status Register

sfrb MCUSR = 0x34;

PORF - Power-on reset flag

#define PORF 0

This bit is set if a power-on reset occurs. The bit is reset only by writing a logic zero to the flag. To make use of the reset flags to identify a reset condition, the user should read and then reset the MCUCSR as early as possible in the program. If the register is cleared before another reset occurs, the source of the reset can be found by examining the reset flags.

EXTRF - External Reset Flag

#define EXTRF 1

This bit is set if an external reset occurs. The bit is reset by a power-on reset, or by writing a logic zero to the flag.

BODRF - Brown-out Reset Flag

#define BODRF 2

This bit is set if an External Reset occurs. The bit is reset by a Power-on Reset, or by

WDRF - Watchdog Reset Flag

#define WDRF 3

This bit is set if a watchdog reset occurs. The bit is reset by a power-on reset, or by writing a logic zero to the flag.

JTRF - JTAG Reset Flag

#define JTRF 4

This bit is set if a reset is being caused by a logic one in the JTAG Reset Register selected by the JTAG instruction AVR_RESET. This bit is reset by a Power-on reset, or by writing a logic zero to the flag. ? Bit 3 - WDRF: Watchdog Reset Flag

FOSCCAL - Fast Oscillator Calibration Value

sfrb FOSCCAL = 0x66;

FCAL0 - Oscillator Calibration Value Bit0

#define FCAL0 0

FCAL1 - Oscillator Calibration Value Bit1

#define FCAL1 1

FCAL2 - Oscillator Calibration Value Bit2

#define FCAL2 2

FCAL3 - Oscillator Calibration Value Bit3

#define FCAL3 3

FCAL4 - Oscillator Calibration Value Bit4

#define FCAL4 4

FCAL5 - Oscillator Calibration Value Bit5

#define FCAL5 5

FCAL6 - Oscillator Calibration Value Bit6

#define FCAL6 6

FCAL7 - Oscillator Calibration Value Bit7

#define FCAL7 7

SMCR - Sleep Mode Control Register

sfrb SMCR = 0x33;

SE - Sleep Enable

#define SE 0

The SE bit must be written to logic one to make the MCU enter the sleep mode when the SLEEP instruction is executed.To

SM0 - Sleep Mode Select bit 0

#define SM0 1

These bits select between the five available sleep modes.

SM1 - Sleep Mode Select bit 1

#define SM1 2

These bits select between the five available sleep modes.

SM2 - Sleep Mode Select bit 2

#define SM2 3

These bits select between the five available sleep modes.

GPIOR2 - General Purpose IO Register 2

sfrb GPIOR2 = 0x2B;

GPIOR20 - General Purpose IO Register 2 bit 0

#define GPIOR20 0

GPIOR21 - General Purpose IO Register 2 bit 1

#define GPIOR21 1

GPIOR22 - General Purpose IO Register 2 bit 2

#define GPIOR22 2

GPIOR23 - General Purpose IO Register 2 bit 3

#define GPIOR23 3

GPIOR24 - General Purpose IO Register 2 bit 4

#define GPIOR24 4

GPIOR25 - General Purpose IO Register 2 bit 5

#define GPIOR25 5

GPIOR26 - General Purpose IO Register 2 bit 6

#define GPIOR26 6

GPIOR27 - General Purpose IO Register 2 bit 7

#define GPIOR27 7

GPIOR1 - General Purpose IO Register 1

sfrb GPIOR1 = 0x2A;

GPIOR10 - General Purpose IO Register 1 bit 0

#define GPIOR10 0

GPIOR11 - General Purpose IO Register 1 bit 1

#define GPIOR11 1

GPIOR12 - General Purpose IO Register 1 bit 2

#define GPIOR12 2

GPIOR13 - General Purpose IO Register 1 bit 3

#define GPIOR13 3

GPIOR14 - General Purpose IO Register 1 bit 4

#define GPIOR14 4

GPIOR15 - General Purpose IO Register 1 bit 5

#define GPIOR15 5

GPIOR16 - General Purpose IO Register 1 bit 6

#define GPIOR16 6

GPIOR17 - General Purpose IO Register 1 bit 7

#define GPIOR17 7

GPIOR0 - General Purpose IO Register 0

sfrb GPIOR0 = 0x1E;

GPIOR00 - General Purpose IO Register 0 bit 0

#define GPIOR00 0

GPIOR01 - General Purpose IO Register 0 bit 1

#define GPIOR01 1

GPIOR02 - General Purpose IO Register 0 bit 2

#define GPIOR02 2

GPIOR03 - General Purpose IO Register 0 bit 3

#define GPIOR03 3

GPIOR04 - General Purpose IO Register 0 bit 4

#define GPIOR04 4

GPIOR05 - General Purpose IO Register 0 bit 5

#define GPIOR05 5

GPIOR06 - General Purpose IO Register 0 bit 6

#define GPIOR06 6

GPIOR07 - General Purpose IO Register 0 bit 7

#define GPIOR07 7

CCSR - Clock Control and Status Register

sfrb CCSR = 0xC0;

ACS - Asynchronous Clock Select

#define ACS 0

The ACS bit is used to selected the source of the asynchronous clock for the Coulomb Counter ADC and Wake-up Timer. The Slow RC Oscillator is selected when this bit is cleared (zero). The 32 kHz Crystal Oscillator is selected when this bit is set (one).

XOE - 32 kHz Crystal Oscillator Enable

#define XOE 1

The XOE bit is used to enable the 32 kHz Crystal Oscillator before it is selected as clock source. This allows the Oscillator clock to stabilize prior to use. The 32 kHz Crystal Oscillator requires approximately two seconds to stabilize, this must be timed by the user software. This bit must remain set as long as the ACS bit is set, otherwise the 32 kHz clock to CC-ADC and Wake-up timer will be stopped.

DIDR0 - Digital Input Disable Register

sfrb DIDR0 = 0x7E;

VADC0D - When this bit is written logic one, the digital input buffer of the corresponding V_ADC pin is disabled.

#define VADC0D 0

VADC1D - When this bit is written logic one, the digital input buffer of the corresponding V_ADC pin is disabled.

#define VADC1D 1

VADC2D - When this bit is written logic one, the digital input buffer of the corresponding V_ADC pin is disabled.

#define VADC2D 2

VADC3D - When this bit is written logic one, the digital input buffer of the corresponding V_ADC pin is disabled.

#define VADC3D 3

PRR0 - Power Reduction Register 0

sfrb PRR0 = 0x64;

PRVADC - Power Reduction V-ADC

#define PRVADC 0

Writing a logic one to this bit shuts down the V-ADC. The V-ADC must be disabled before shut down.

PRTIM0 - Power Reduction Timer/Counter0

#define PRTIM0 1

Writing a logic one to this bit shuts down the Timer/Counter0 module. When the Timer/Counter0 is enabled, operation will continue like before the shutdown.

PRTIM1 - Power Reduction Timer/Counter1

#define PRTIM1 2

Writing a logic one to this bit shuts down the Timer/Counter1 module. When the, Timer/Counter1 is enabled, operation will continue like before the shutdown.

PRTWI - Power Reduction TWI

#define PRTWI 3

Writing a logic one to this bit shuts down the TWI by stopping the clock to the module. When waking up the TWI again, the TWI should be re initialized to ensure proper operation.

WATCHDOG

WDTCSR - Watchdog Timer Control Register

sfrb WDTCSR = 0x60;

WDP0 - Watch Dog Timer Prescaler bit 0

#define WDP0 0

WDP1 - Watch Dog Timer Prescaler bit 1

#define WDP1 1

WDP2 - Watch Dog Timer Prescaler bit 2

#define WDP2 2

WDE - Watch Dog Enable

#define WDE 3

When the WDE is set (one) the Watchdog Timer is enabled, and if the WDE is cleared (zero) the Watchdog Timer function is disabled. WDE can only be cleared if the WDTOE bit is set(one). To disable an enabled watchdog timer, the following procedure must be followed: 1. In the same operation, write a logical one to WDTOE and WDE. A logical one must be written to WDE even though it is set to one before the disable operation starts. 2. Within the next four clock cycles, write a logical 0 to WDE. This disables the watchdog

WDCE - Watchdog Change Enable

#define WDCE 4

WDP3 - Watchdog Timer Prescaler Bit 3

#define WDP3 5

WDIE - Watchdog Timeout Interrupt Enable

#define WDIE 6

WDIF - Watchdog Timeout Interrupt Flag

#define WDIF 7

TIMER COUNTER 0

The 8-bit Timer/Counter0 can select clock source from CK, prescaled CK, or an external pin. In addition it can be stopped as described in ?Timer/Counter0 Control Register - TCCR0? on page 35. The overflow status flag is found in ?The Timer/Counter Interrupt Flag Register - TIFR? on page 29. Control signals are found in the Timer/Counter0 Control Register - TCCR0. The interrupt enable/disable settings for Timer/Counter0 are found in ?The Timer/Counter Interrupt Mask Regis-ter - TIMSK? on page 28. When Timer/Counter0 is externally clocked, the external signal is synchronized with the oscillator frequency of the CPU. To assure proper sampling of the external clock, the minimum time between two external clock transitions must be at least one internal CPU clock period. The external clock signal is sampled on the rising edge of the internal CPU clock. The 8-bit Timer/Counter0 features both a high resolution and a high accuracy usage with the lower prescaling opportuni-ties. Similarly, the high prescaling opportuni ties make the Timer/Counter0 useful for lower speed functions or exact timing functions with infrequent actions

TCCR0A - Timer/Counter0 Control Register

sfrb TCCR0A = 0x24;

WGM00 - Clock Select0 bit 0

#define WGM00 0

WGM01 - Clock Select0 bit 1

#define WGM01 1

COM0B0

#define COM0B0 4

COM0B1

#define COM0B1 5

COM0A0 - Waveform Generation Mode

#define COM0A0 6

COM0A1 - Force Output Compare

#define COM0A1 7

TCCR0B - Timer/Counter0 Control Register

sfrb TCCR0B = 0x25;

CS00 - Clock Select0 bit 0

#define CS00 0

CS01 - Clock Select0 bit 1

#define CS01 1

CS02 - Clock Select0 bit 2

#define CS02 2

WGM02

#define WGM02 3

FOC0B - Waveform Generation Mode

#define FOC0B 6

FOC0A - Force Output Compare

#define FOC0A 7

TCNT0 - Timer Counter 0

sfrb TCNT0 = 0x26;

TCNT00 - Timer Counter 0 bit 0

#define TCNT00 0

TCNT01 - Timer Counter 0 bit 1

#define TCNT01 1

TCNT02 - Timer Counter 0 bit 2

#define TCNT02 2

TCNT03 - Timer Counter 0 bit 3

#define TCNT03 3

TCNT04 - Timer Counter 0 bit 4

#define TCNT04 4

TCNT05 - Timer Counter 0 bit 5

#define TCNT05 5

TCNT06 - Timer Counter 0 bit 6

#define TCNT06 6

TCNT07 - Timer Counter 0 bit 7

#define TCNT07 7

OCR0A - Output compare Register A

sfrb OCR0A = 0x27;

OCR0A0

#define OCR0A0 0

OCR0A1

#define OCR0A1 1

OCR0A2

#define OCR0A2 2

OCR0A3

#define OCR0A3 3

OCR0A4

#define OCR0A4 4

OCR0A5

#define OCR0A5 5

OCR0A6

#define OCR0A6 6

OCR0A7

#define OCR0A7 7

OCR0B - Output compare Register B

sfrb OCR0B = 0x28;

OCR0B0

#define OCR0B0 0

OCR0B1

#define OCR0B1 1

OCR0B2

#define OCR0B2 2

OCR0B3

#define OCR0B3 3

OCR0B4

#define OCR0B4 4

OCR0B5

#define OCR0B5 5

OCR0B6

#define OCR0B6 6

OCR0B7

#define OCR0B7 7

TIMSK0 - Timer/Counter Interrupt Mask Register

sfrb TIMSK0 = 0x6E;

TOIE0 - Overflow Interrupt Enable

#define TOIE0 0

OCIE0A - Output Compare Interrupt Enable

#define OCIE0A 1

OCIE0B - Output Compare Interrupt Enable

#define OCIE0B 2

TIFR0 - Timer/Counter Interrupt Flag register

sfrb TIFR0 = 0x15;

TOV0 - Overflow Flag

#define TOV0 0

OCF0A - Output Compare Flag

#define OCF0A 1

OCF0B - Output Compare Flag

#define OCF0B 2

PORTA

PORTA - Port A Data Register

sfrb PORTA = 0x02;

PORTA0 - Port A Data Register bit 0

#define PORTA0 0

PORTA1 - Port A Data Register bit 1

#define PORTA1 1

PORTA2 - Port A Data Register bit 2

#define PORTA2 2

PORTA3 - Port A Data Register bit 3

#define PORTA3 3

PORTA4 - Port A Data Register bit 4

#define PORTA4 4

PORTA5 - Port A Data Register bit 5

#define PORTA5 5

PORTA6 - Port A Data Register bit 6

#define PORTA6 6

PORTA7 - Port A Data Register bit 7

#define PORTA7 7

DDRA - Port A Data Direction Register

sfrb DDRA = 0x01;

DDA0 - Data Direction Register, Port A, bit 0

#define DDA0 0

DDA1 - Data Direction Register, Port A, bit 1

#define DDA1 1

DDA2 - Data Direction Register, Port A, bit 2

#define DDA2 2

DDA3 - Data Direction Register, Port A, bit 3

#define DDA3 3

DDA4 - Data Direction Register, Port A, bit 4

#define DDA4 4

DDA5 - Data Direction Register, Port A, bit 5

#define DDA5 5

DDA6 - Data Direction Register, Port A, bit 6

#define DDA6 6

DDA7 - Data Direction Register, Port A, bit 7

#define DDA7 7

PINA - Port A Input Pins

sfrb PINA = 0x00;

PINA0 - Input Pins, Port A bit 0

#define PINA0 0

PINA1 - Input Pins, Port A bit 1

#define PINA1 1

PINA2 - Input Pins, Port A bit 2

#define PINA2 2

PINA3 - Input Pins, Port A bit 3

#define PINA3 3

PINA4 - Input Pins, Port A bit 4

#define PINA4 4

PINA5 - Input Pins, Port A bit 5

#define PINA5 5

PINA6 - Input Pins, Port A bit 6

#define PINA6 6

PINA7 - Input Pins, Port A bit 7

#define PINA7 7

PORTB

PORTB - Port B Data Register

sfrb PORTB = 0x05;

PORTB0 - Port B Data Register bit 0

#define PORTB0 0

PORTB1 - Port B Data Register bit 1

#define PORTB1 1

PORTB2 - Port B Data Register bit 2

#define PORTB2 2

PORTB3 - Port B Data Register bit 3

#define PORTB3 3

PORTB4 - Port B Data Register bit 4

#define PORTB4 4

PORTB5 - Port B Data Register bit 5

#define PORTB5 5

PORTB6 - Port B Data Register bit 6

#define PORTB6 6

PORTB7 - Port B Data Register bit 7

#define PORTB7 7

DDRB - Port B Data Direction Register

sfrb DDRB = 0x04;

DDB0 - Port B Data Direction Register bit 0

#define DDB0 0

DDB1 - Port B Data Direction Register bit 1

#define DDB1 1

DDB2 - Port B Data Direction Register bit 2

#define DDB2 2

DDB3 - Port B Data Direction Register bit 3

#define DDB3 3

DDB4 - Port B Data Direction Register bit 4

#define DDB4 4

DDB5 - Port B Data Direction Register bit 5

#define DDB5 5

DDB6 - Port B Data Direction Register bit 6

#define DDB6 6

DDB7 - Port B Data Direction Register bit 7

#define DDB7 7

PINB - Port B Input Pins

sfrb PINB = 0x03;

PINB0 - Port B Input Pins bit 0

#define PINB0 0

PINB1 - Port B Input Pins bit 1

#define PINB1 1

PINB2 - Port B Input Pins bit 2

#define PINB2 2

PINB3 - Port B Input Pins bit 3

#define PINB3 3

PINB4 - Port B Input Pins bit 4

#define PINB4 4

PINB5 - Port B Input Pins bit 5

#define PINB5 5

PINB6 - Port B Input Pins bit 6

#define PINB6 6

PINB7 - Port B Input Pins bit 7

#define PINB7 7

PORTC

PORTC - Port C Data Register

sfrb PORTC = 0x08;

PORTC0 - Port C Data Register bit 0

#define PORTC0 0

PORTD

PORTD - Data Register, Port D

sfrb PORTD = 0x0B;

PORTD0

#define PORTD0 0

PORTD1

#define PORTD1 1

DDRD -

sfrb DDRD = 0x0A;

DDD0

#define DDD0 0

DDD1

#define DDD1 1

PIND - Input Pins, Port D

sfrb PIND = 0x09;

PIND0

#define PIND0 0

PIND1

#define PIND1 1

BOOT LOAD

The Boot Loader Support provides a real Read While Write self-programming mechanism for downloading and uploading program code by the MCU itself. This feature allows flexible application software updates controlled by the MCU using a Flash-resident Boot Loader program. The Boot Loader program can use any available data interface and associated proto-col to read code and write (program) that code into the Flash memory, or read the code from the program memory. The program code within the Boot Loader section has the capability to write into the entire Flash, including the Boot Loader Memory. The Boot Loader can thus even modify itself, and it can also erase itself from the code if the feature is not needed anymore. The size of the Boot Loader Memory is configurable with fuses and the Boot Loader has two separate sets of Boot Lock Bits which can be set independently. This gives the user a unique flexibility to select different levels of protection. Boot Loader Features: Read While Write self-programming. Flexibl Boot Memory size. High security (separate Boot Lock bits for a flexible protection). Separate fuse to select reset vector Optimized page (1) size. Code efficient algorithm Efficient read-modify-write suppor

SPMCSR - Store Program Memory Control Register

sfrb SPMCSR = 0x37;

SPMEN - Store Program Memory Enable

#define SPMEN 0

This bit enables the SPM instruction for the next four clock cycles. If written to one together with either RWWSRE, BLB-SET, PGWRT or PGERS, the following SPM instruction will have a special meaning, see description above. If only SPMEN is written, the following SPM instruction will store the value in R1:R0 in the temporary page buffer addressed by the Z pointer. The LSB of the Z pointer is ignored. The SPMEN bit will auto-clear upon completion of an SPM instruction, or if no SPM instruction is executed within four clock cycles. During page erase and page write, the SPMEN bit remain high until the operation is completed. Writing any other combination than ?10001?, "01001", "00101", "00011" or "00001" in the lower five bits will have no effec

PGERS - Page Erase

#define PGERS 1

If this bit is written to one at the same time as SPMEN, the next SPM instruction within four clock cycles executes page erase. The page address is taken from the high part of the Z pointer. The data in R1 and R0 are ignored. The PGERS bit will auto-clear upon completion of a page erase, or if no SPM instruction is executed within four clock cycles. The CPU is halted during the entire page write operation if the NRWW section is addressed.

PGWRT - Page Write

#define PGWRT 2

If this bit is written to one at the same time as SPMEN, the next SPM instruction within four clock cycles executes page write, with the data stored in the temporary buffer. The page address is taken from the high part of the Z pointer. The data in R1 and R0 are ignored. The PGWRT bit will auto-clear upon completion of a page write, or if no SPM instruction is exe-cuted within four clock cycles. The CPU is halted during the entire page write operation if the NRWW section is addressed.

BLBSET - Boot Lock Bit Set

#define BLBSET 3

If this bit is written to one at the same time as SPMEN, the next SPM instruction within four clock cycles sets Boot Lock bits, according to the data in R0. The data in R1 and the address in the Z pointer are ignored. The BLBSET bit will automatically be cleared upon completion of the lock bit set, or if no SPM instruction is executed within four clock cycles. An LPM instruction within three cycles after BLBSET and SPMEN are set in the SPMCR register, will read either the Lock-bits or the Fuse bits (depending on Z0 in the Z pointer) into the destination register. See ?Reading the Fuse and Lock Bits from Software? on page 235 for details

RWWSRE - Read While Write section read enable

#define RWWSRE 4

When programming (page erase or page write) to the RWW section, the RWW section is blocked for reading (the RWWSB will be set by hardware). To re-enable the RWW section, the user software must wait until the programming is completed (SPMEN will be cleared). Then, if the RWWSRE bit is written to one at the same time as SPMEN, the next SPM instruction within four clock cycles re-enables the RWW section. The RWW section cannot be re-enabled while Flash is busy with a page erase or a page write (SPMEN is set). If the RWWSRE bit is written while the Flash is being loaded, the Flash load operation will abort and the data loaded will be lo

SIGRD - Signature Row Read

#define SIGRD 5

If this bit is written to one at the same time as SPMEN, the next LPM instruction within three clock cycles will read a byte from the signature row into the destination register. see ?Reading the Signature Row from Software? in the datasheet for details. An SPM instruction within four cycles after SIGRD and SPMEN are set will have no effect. This operation is reserved for future use and should not be used.

RWWSB - Read While Write Section Busy

#define RWWSB 6

When a self-programming (page erase or page write) operation to the RWW section is initiated, the RWWSB will be set (one) by hardware. When the RWWSB bit is set, the RWW section cannot be accessed. The RWWSB bit will be cleared if the RWWSRE bit is written to one after a self-programming operation is completed. Alternatively the RWWSB bit will auto-matically be cleared if a page load operation is initiated.

SPMIE - SPM Interrupt Enable

#define SPMIE 7

When the SPMIE bit is written to one, and the I-bit in the Status Register is set (one), the SPM ready interrupt will be enabled. The SPM ready Interrupt will be executed as long as the SPMEN bit in the SPMCR register is cleared.

TWI

TWI: Simple yet powerful and flexible communications interface, only two bus lines needed. Both master and slave operation supported. Device can operate as transmitter or receiver. 7-bit address space allows up to 128 different slave addresses. Multi-master arbitration support Up to 400 kHz data transfer speed Slew-rate limited output drivers Noise suppression circuitry rejects spikes on bus lines Fully programmable slave address with general call support Address recognition causes wake-up when AVR is in sleep mode The Two-Wire Serial Interface (TWI) is ideally suited to typical microcontroller applications. The TWI protocol allows the systems designer to interconnect up to 128 different devices using only two bidirectional bus lines, one for clock (SCL) andone for data (SDA). The only external hardware needed to implement the bus is a single pull-up resistor for each of the TWI bus lines. All devices connected to the bus have individual addresses, and mechanisms for resolving bus contention are inherent in the TWI

TWBCSR - TWI Bus Control and Status Register

sfrb TWBCSR = 0xBE;

TWBCIP - TWI Bus Connect/Disconnect Interrupt Polarity

#define TWBCIP 0

TWBDT0 - TWI Bus Disconnect Time-out Period

#define TWBDT0 1

TWBDT1 - TWI Bus Disconnect Time-out Period

#define TWBDT1 2

TWBCIE - TWI Bus Connect/Disconnect Interrupt Enable

#define TWBCIE 6

TWBCIF - TWI Bus Connect/Disconnect Interrupt Flag

#define TWBCIF 7

TWAMR - TWI (Slave) Address Mask Register

sfrb TWAMR = 0xBD;

TWAM0

#define TWAM0 1

TWAM1

#define TWAM1 2

TWAM2

#define TWAM2 3

TWAM3

#define TWAM3 4

TWAM4

#define TWAM4 5

TWAM5

#define TWAM5 6

TWAM6

#define TWAM6 7

TWBR - TWI Bit Rate register

sfrb TWBR = 0xB8;

TWBR0

#define TWBR0 0

TWBR1

#define TWBR1 1

TWBR2

#define TWBR2 2

TWBR3

#define TWBR3 3

TWBR4

#define TWBR4 4

TWBR5

#define TWBR5 5

TWBR6

#define TWBR6 6

TWBR7

#define TWBR7 7

TWCR - TWI Control Register

sfrb TWCR = 0xBC;

TWIE - TWI Interrupt Enable

#define TWIE 0

When this bit is written to one, and the I-bit in SREG is set, the TWI interrupt request will be activated for as long as the TWINT flag is high.

TWEN - TWI Enable Bit

#define TWEN 2

The TWEN bit enables TWI operation and activates the TWI interface. When TWEN is written to one, the TWI takes control over the I/O pins connected to the SCL and SDA pins, enabling the slew-rate limiters and spike filters. If this bit is written to zero, the TWI is switched off and all TWI transmissions are terminated, regardless of any ongoing operation.

TWWC - TWI Write Collition Flag

#define TWWC 3

The TWWC bit is set when attempting to write to the TWI Data Register - TWDR when TWINT is low. This flag is cleared by writing the TWDR register when TWINT is high.

TWSTO - TWI Stop Condition Bit

#define TWSTO 4

Writing the TWSTO bit to one in master mode will generate a STOP condition on the 2-wire Serial Bus. When the STOP condition is executed on the bus, the TWSTO bit is cleared automatically. In slave mode, setting the TWSTO bit can be used to recover from an error condition. This will not generate a STOP condition, but the TWI returns to a well-defined unaddressed slave mode and releases the SCL and SDA lines to a high impedance state.

TWSTA - TWI Start Condition Bit

#define TWSTA 5

The application writes the TWSTA bit to one when it desires to become a master on the 2-wire Serial Bus. The TWI hard-ware checks if the bus is available, and generates a START condition on the bus if it is free. However, if the bus is not free, the TWI waits until a STOP condition is detected, and then generates a new START condition to claim the bus Master sta-tus. TWSTA is cleared by the TWI hardware when the START condition has been transmitted.

TWEA - TWI Enable Acknowledge Bit

#define TWEA 6

The TWEA bit controls the generation of the acknowledge pulse. If the TWEA bit is written to one, the ACK pulse is gener-ated on the TWI bus if the following conditions are met: 1. The device?s own slave address has been received. 2. A general call has been received, while the TWGCE bit in the TWAR is set. 3. A data byte has been received in master receiver or slave receiver mode. By writing the TWEA bit to zero, the device can be virtually disconnected from the 2-wire Serial Bus temporarily. Address recognition can then be resumed by writing the TWEA bit to one again

TWINT - TWI Interrupt Flag

#define TWINT 7

This bit is set by hardware when the TWI has finished its current job and expects application software response. If the I-bit in SREG and TWIE in TWCR are set, the MCU will jump to the TWI interrupt vector. While the TWINT flag is set, the SCL low period is stretched. The TWINT flag must be cleared by software by writing a logic one to it. Note that this flag is not automatically cleared by hardware when executing the interrupt routine. Also note that clearing this flag starts the operation of the TWI, so all accesses to the TWI Address Register (TWAR), TWI Status Register (TWSR), and TWI Data Register (TWDR) must be complete before clearing this flag

TWSR - TWI Status Register

sfrb TWSR = 0xB9;

TWPS0 - TWI Prescaler

#define TWPS0 0

Bits 1..0: These bits can be read and written, and control the bit rate prescaler. See ?Bit Rate Generator Unit? on page 165 for calculating bit rates.

TWPS1 - TWI Prescaler

#define TWPS1 1

Bits 1..0: These bits can be read and written, and control the bit rate prescaler. See ?Bit Rate Generator Unit? on page 165 for calculating bit rates.

TWS3 - TWI Status

#define TWS3 3

Bits 7..3: These 5 bits reflect the status of the TWI logic and the 2-Wire Serial Bus. The different status codes are described later in this chapter. Note that the value read from TWSR contains both the 5-bit status value and the 2-bit prescaler value. The application designer should consider masking the prescaler bits to zero when checking the Status bits. This makes status checking independent of prescaler setting. This approach is used in this datasheet, unless otherwise noted. If the prescaler setting remains unchanged in the application, the prescaler bits need not be masked. Instead, bit 1:0 in the values that TWSR is compared to can be modified to match the prescaler setting. This will yield more efficient co

TWS4 - TWI Status

#define TWS4 4

Bits 7..3: These 5 bits reflect the status of the TWI logic and the 2-Wire Serial Bus. The different status codes are described later in this chapter. Note that the value read from TWSR contains both the 5-bit status value and the 2-bit prescaler value. The application designer should consider masking the prescaler bits to zero when checking the Status bits. This makes status checking independent of prescaler setting. This approach is used in this datasheet, unless otherwise noted. If the prescaler setting remains unchanged in the application, the prescaler bits need not be masked. Instead, bit 1:0 in the values that TWSR is compared to can be modified to match the prescaler setting. This will yield more efficient co

TWS5 - TWI Status

#define TWS5 5

Bits 7..3: These 5 bits reflect the status of the TWI logic and the 2-Wire Serial Bus. The different status codes are described later in this chapter. Note that the value read from TWSR contains both the 5-bit status value and the 2-bit prescaler value. The application designer should consider masking the prescaler bits to zero when checking the Status bits. This makes status checking independent of prescaler setting. This approach is used in this datasheet, unless otherwise noted. If the prescaler setting remains unchanged in the application, the prescaler bits need not be masked. Instead, bit 1:0 in the values that TWSR is compared to can be modified to match the prescaler setting. This will yield more efficient c

TWS6 - TWI Status

#define TWS6 6

Bits 7..3: These 5 bits reflect the status of the TWI logic and the 2-Wire Serial Bus. The different status codes are described later in this chapter. Note that the value read from TWSR contains both the 5-bit status value and the 2-bit prescaler value. The application designer should consider masking the prescaler bits to zero when checking the Status bits. This makes status checking independent of prescaler setting. This approach is used in this datasheet, unless otherwise noted. If the prescaler setting remains unchanged in the application, the prescaler bits need not be masked. Instead, bit 1:0 in the values that TWSR is compared to can be modified to match the prescaler setting. This will yield more efficient co

TWS7 - TWI Status

#define TWS7 7

Bits 7..3: These 5 bits reflect the status of the TWI logic and the 2-Wire Serial Bus. The different status codes are described later in this chapter. Note that the value read from TWSR contains both the 5-bit status value and the 2-bit prescaler value. The application designer should consider masking the prescaler bits to zero when checking the Status bits. This makes status checking independent of prescaler setting. This approach is used in this datasheet, unless otherwise noted. If the prescaler setting remains unchanged in the application, the prescaler bits need not be masked. Instead, bit 1:0 in the values that TWSR is compared to can be modified to match the prescaler setting. This will yield more efficient c

TWDR - TWI Data register

sfrb TWDR = 0xBB;

TWD0 - TWI Data Register Bit 0

#define TWD0 0

TWD1 - TWI Data Register Bit 1

#define TWD1 1

TWD2 - TWI Data Register Bit 2

#define TWD2 2

TWD3 - TWI Data Register Bit 3

#define TWD3 3

TWD4 - TWI Data Register Bit 4

#define TWD4 4

TWD5 - TWI Data Register Bit 5

#define TWD5 5

TWD6 - TWI Data Register Bit 6

#define TWD6 6

TWD7 - TWI Data Register Bit 7

#define TWD7 7

TWAR - TWI (Slave) Address register

sfrb TWAR = 0xBA;

TWGCE - TWI General Call Recognition Enable Bit

#define TWGCE 0

TWA0 - TWI (Slave) Address register Bit 0

#define TWA0 1

TWA1 - TWI (Slave) Address register Bit 1

#define TWA1 2

TWA2 - TWI (Slave) Address register Bit 2

#define TWA2 3

TWA3 - TWI (Slave) Address register Bit 3

#define TWA3 4

TWA4 - TWI (Slave) Address register Bit 4

#define TWA4 5

TWA5 - TWI (Slave) Address register Bit 5

#define TWA5 6

TWA6 - TWI (Slave) Address register Bit 6

#define TWA6 7

BANDGAP

BGCRR - Bandgap Calibration of Resistor Ladder

sfrb BGCRR = 0xD1;

BGCR0 - Bandgap Calibration of Resistor Ladder Bit 0

#define BGCR0 0

BGCR1 - Bandgap Calibration of Resistor Ladder Bit 1

#define BGCR1 1

BGCR2 - Bandgap Calibration of Resistor Ladder Bit 2

#define BGCR2 2

BGCR3 - Bandgap Calibration of Resistor Ladder Bit 3

#define BGCR3 3

BGCR4 - Bandgap Calibration of Resistor Ladder Bit 4

#define BGCR4 4

BGCR5 - Bandgap Calibration of Resistor Ladder Bit 5

#define BGCR5 5

BGCR6 - Bandgap Calibration of Resistor Ladder Bit 6

#define BGCR6 6

BGCR7 - Bandgap Calibration of Resistor Ladder Bit 7

#define BGCR7 7

BGCCR - Bandgap Calibration Register

sfrb BGCCR = 0xD0;

BGCC0 - BG Calibration of PTAT Current Bit 0

#define BGCC0 0

These bits are used for trimming of the nominal value of the bandgap reference voltage. These bits are binary caoded, step size is approximately 2mV.

BGCC1 - BG Calibration of PTAT Current Bit 1

#define BGCC1 1

These bits are used for trimming of the nominal value of the bandgap reference voltage. These bits are binary caoded, step size is approximately 2mV.

BGCC2 - BG Calibration of PTAT Current Bit 2

#define BGCC2 2

These bits are used for trimming of the nominal value of the bandgap reference voltage. These bits are binary caoded, step size is approximately 2mV.

BGCC3 - BG Calibration of PTAT Current Bit 3

#define BGCC3 3

These bits are used for trimming of the nominal value of the bandgap reference voltage. These bits are binary caoded, step size is approximately 2mV.

BGCC4 - BG Calibration of PTAT Current Bit 4

#define BGCC4 4

These bits are used for trimming of the nominal value of the bandgap reference voltage. These bits are binary caoded, step size is approximately 2mV.

BGCC5 - BG Calibration of PTAT Current Bit 5

#define BGCC5 5

BGEN - Setting the BGEN bit to one will enable the bandgap voltage reference. This bit must be set before enabling the CC_ADC or V_ADC, and must remain set while either ADC is enabled.

#define BGEN 7

EEPROM

EEPROM Read/Write Access. The EEPROM access registers are accessible in the I/O space. The write access time for the EEPROM is given in Table 1. A self-timing function, however, lets the user software detect when the next byte can be written. If the user code contains instructions that write the EEPROM, some precautions must be taken. In heavily filtered power supplies, V CC is likely to rise or fall slowly on power-up/down. This causes the device for some period of time to run at a voltage lower than specified as minimum for the clock frequency used. See ?Preventing EEPROM Corruption? on page 19. for details on how to avoid problems in these situations.In order to prevent unintentional EEPROM writes, a specific write procedure must be followed. Refer to the description of the EEPROM Control Register for details on this. When the EEPROM is read, the CPU is halted for four clock cycles before the next instruction is executed. When theEEPROM is written, the CPU is halted for two clock cycles before the next instruction is execute

EEARH - EEPROM Address Register High Byte

sfrb EEARH = 0x22;

EEAR8 - EEPROM Read/Write Access Bit 8

#define EEAR8 0

EEARL - EEPROM Address Register Low Byte

sfrb EEARL = 0x21;

EEAR0 - EEPROM Read/Write Access Bit 0

#define EEAR0 0

EEAR1 - EEPROM Read/Write Access Bit 1

#define EEAR1 1

EEAR2 - EEPROM Read/Write Access Bit 2

#define EEAR2 2

EEAR3 - EEPROM Read/Write Access Bit 3

#define EEAR3 3

EEAR4 - EEPROM Read/Write Access Bit 4

#define EEAR4 4

EEAR5 - EEPROM Read/Write Access Bit 5

#define EEAR5 5

EEAR6 - EEPROM Read/Write Access Bit 6

#define EEAR6 6

EEAR7 - EEPROM Read/Write Access Bit 7

#define EEAR7 7

EEDR - EEPROM Data Register

sfrb EEDR = 0x20;

EEDR0 - EEPROM Data Register bit 0

#define EEDR0 0

EEDR1 - EEPROM Data Register bit 1

#define EEDR1 1

EEDR2 - EEPROM Data Register bit 2

#define EEDR2 2

EEDR3 - EEPROM Data Register bit 3

#define EEDR3 3

EEDR4 - EEPROM Data Register bit 4

#define EEDR4 4

EEDR5 - EEPROM Data Register bit 5

#define EEDR5 5

EEDR6 - EEPROM Data Register bit 6

#define EEDR6 6

EEDR7 - EEPROM Data Register bit 7

#define EEDR7 7

EECR - EEPROM Control Register

sfrb EECR = 0x1F;

EERE - EEPROM Read Enable

#define EERE 0

The EEPROM Read Enable Signal EERE is the read strobe to the EEPROM. When the correct address is set up in the EEAR register, the EERE bit must be written to a logic one to trigger the EEPROM read. The EEPROM read access takes one instruction, and the requested data is available immediately. When the EEPROM is read, the CPU is halted for four cycles before the next instruction is executed. The user should poll the EEWE bit before starting the read operation. If a write operation is in progress, it is neither possible to read the EEPROM, nor to change the EEAR register. The calibrated oscillator is used to time the EEPROM accesses. Table 1 lists the typical programming time for EEPROM access from the CPU

EEWE - EEPROM Write Enable

#define EEWE 1

The EEPROM Write Enable Signal EEWE is the write strobe to the EEPROM. When address and data are correctly set up, the EEWE bit must be set to write the value into the EEPROM. The EEMWE bit must be set when the logical one is written to EEWE, otherwise no EEPROM write takes place. The following procedure should be followed when writing the EEPROM (the order of steps 3 and 4 is not essential): 1. Wait until EEWE becomes zero. 2. Wait until SPMEN in SPMCR becomes zero. 3. Write new EEPROM address to EEAR (optional). 4. Write new EEPROM data to EEDR (optional). 5. Write a logical one to the EEMWE bit while writing a zero to EEWE in EECR. 6. Within four clock cycles after setting EEMWE, write a logical one to EEWE. The EEPROM can not be programmed during a CPU write to the Flash memory. The software must check that the Flash programming is completed before initiating a new EEPROM write. Step 2 is only relevant if the software contains a boot loader allowing the CPU to program the Flash. If the Flash is never being updated by the CPU, step 2 can be omitted. See ?Boot Loader Support - Read While Write self-programming? on page 228 for details about boot programming. Caution: An interrupt between step 5 and step 6 will make the write cycle fail, since the EEPROM Master Write Enable will time-out. If an interrupt routine accessing the EEPROM is interrupting another EEPROM access, the EEAR or EEDR regis-ter will be modified, causing the interrupted EEPROM access to fail. It is recommended to have the global interrupt flag cleared during the 4 last steps to avoid these problems. When the write access time has elapsed, the EEWE bit is cleared by hardware. The user software can poll this bit and wait for a zero before writing the next byte. When EEWE has been set, the CPU is halted for two cycles before the next instruc-tion is executed

EEMWE - EEPROM Master Write Enable

#define EEMWE 2

The EEMWE bit determines whether setting EEWE to one causes the EEPROM to be written. When EEMWE is written to one, writing EEWE to one within 4 clock cycles will write data to the EEPROM at the selected address. If EEMWE is zero, writing EEWE to one will have no effect. When EEMWE has been written to one by software, hardware clears the bit to zero after four clock cycles. See the description of the EEWE bit for an EEPROM write procedure.

EERIE - EEPROM Ready Interrupt Enable

#define EERIE 3

EEPROM Ready Interrupt Enable Writing EERIE to one enables the EEPROM Ready Interrupt if the I bit in SREG is set. Writing EERIE to zero disables the interrupt. The EEPROM Ready interrupt generates a constant interrupt when EEWE is cleared.

EEPM0 - EEPROM Programming Mode Bits

#define EEPM0 4

The EEPROM Programming mode bit setting defines which programming action that will

EEPM1 - EEPROM Programming Mode Bits

#define EEPM1 5

The EEPROM Programming mode bit setting defines which programming action that will