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

AD CONVERTER

AD Converter Feature list: 10-bit Resolution. 0.5 LSB Integral Non-Linearity. +-2 LSB Absolute Accuracy. TBD - 260 µs Conversion Time. Up to TBD kSPS at maximum resolution. 8 Multiplexed Single Ended Input Channels. 7 Differential input channels (TQFP package only). 2 Differential input channels with optional gain of 10x and 200x (TQFP package only). Optional left adjustment for ADC result readout. 0 - VCC ADC Input Voltage Range. Selectable 2.56 V ADC reference voltage. Free Running or Single Conversion Mode. Interrupt on ADC Conversion Complete. Sleep Mode Noise

ADMUX - The ADC multiplexer Selection Register

sfrb ADMUX = $07;

MUX0 - Analog Channel and Gain Selection Bits

#define MUX0_BIT 0

#define MUX0_MASK 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).

MUX1 - Analog Channel and Gain Selection Bits

#define MUX1_BIT 1

#define MUX1_MASK 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).

MUX2 - Analog Channel and Gain Selection Bits

#define MUX2_BIT 2

#define MUX2_MASK 4

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).

ADCSR - The ADC Control and Status register

sfrb ADCSR = $06;

ADPS0 - ADC Prescaler Select Bits

#define ADPS0_BIT 0

#define ADPS0_MASK 1

These bits determine the division factor between the XTAL frequency and the input clock to the ADC.

ADPS1 - ADC Prescaler Select Bits

#define ADPS1_BIT 1

#define ADPS1_MASK 2

These bits determine the division factor between the XTAL frequency and the input clock to the ADC.

ADPS2 - ADC Prescaler Select Bits

#define ADPS2_BIT 2

#define ADPS2_MASK 4

These bits determine the division factor between the XTAL frequency and the input clock to the ADC.

ADIE - ADC Interrupt Enable

#define ADIE_BIT 3

#define ADIE_MASK 8

When this bit is set (one) and the I-bit in SREG is set (one), the ADC Conversion Complete Interrupt is activated.

ADIF - ADC Interrupt Flag

#define ADIF_BIT 4

#define ADIF_MASK 16

This bit is set (one) when an ADC conversion completes and the data registers are updated. The ADC Conversion Complete Interrupt is executed if the ADIE bit and the I-bit in SREG are set (one). ADIF is cleared by hardware when executing the corresponding interrupt handling vector. Alternatively, ADIF is cleared by writing a logical one to the flag. Beware that if doing a read-modify-write on ADCSR, a pending interrupt can be disabled. This also applies if the SBI and CBI instructions are used.

ADSC - ADC Start Conversion

#define ADSC_BIT 6

#define ADSC_MASK 64

In Single Conversion Mode, a logical ‘1’ must be written to this bit to start each conversion. In Free Running Mode, a logical ‘1’ must be written to this bit to start the first conversion. The first time ADSC has been written after the ADC has been enabled, or if ADSC is written at the same time as the ADC is enabled, an extended conversion will result. This extended conversion performs initialization of the ADC. ADSC will read as one as long as a conversion is in progress. When the conversion is complete, it returns to zero. When a dummy conversion precedes a real conversion, ADSC will stay high until the real conversion completes. Writing a 0 to this bit has no effect

ADEN - ADC Enable

#define ADEN_BIT 7

#define ADEN_MASK 128

Writing a logical ‘1’ to this bit enables the ADC. By clearing this bit to zero, the ADC is turned off. Turning the ADC off while a conversion is in progress, will terminate this conversion.

ADCH - ADC Data Register High Byte

sfrb ADCH = $05;

ADC8 - ADC Data Register High Byte Bit 0

#define ADC8_BIT 0

#define ADC8_MASK 1

ADC9 - ADC Data Register High Byte Bit 1

#define ADC9_BIT 1

#define ADC9_MASK 2

ADCL - ADC Data Register Low Byte

sfrb ADCL = $04;

ADC0 - ADC Data Register Low Byte Bit 0

#define ADC0_BIT 0

#define ADC0_MASK 1

ADC1 - ADC Data Register Low Byte Bit 1

#define ADC1_BIT 1

#define ADC1_MASK 2

ADC2 - ADC Data Register Low Byte Bit 2

#define ADC2_BIT 2

#define ADC2_MASK 4

ADC3 - ADC Data Register Low Byte Bit 3

#define ADC3_BIT 3

#define ADC3_MASK 8

ADC4 - ADC Data Register Low Byte Bit 4

#define ADC4_BIT 4

#define ADC4_MASK 16

ADC5 - ADC Data Register Low Byte Bit 5

#define ADC5_BIT 5

#define ADC5_MASK 32

ADC6 - ADC Data Register Low Byte Bit 6

#define ADC6_BIT 6

#define ADC6_MASK 64

ADC7 - ADC Data Register Low Byte Bit 7

#define ADC7_BIT 7

#define ADC7_MASK 128

ANALOG COMPARATOR

The analog comparator compares the input values on the positive input PB2 (AIN0) and negative input PB3 (AIN1). When the voltage on the positive input PB2 (AIN0) is higher than the voltage on the negative input PB3 (AIN1), the Analog Com-parator Output, ACO is set (one). The comparator’s output can be set to trigger the Timer/Counter1 Input Capture function. In addition, the comparator can trigger a separate interrupt, exclusive to the Analog Comparator. The user can select Inter-rupt triggering on comparator output rise, fall or toggle

ACSR - Analog Comparator Control And Status Register

sfrb ACSR = $08;

ACIS0 - Analog Comparator Interrupt Mode Select bit 0

#define ACIS0_BIT 0

#define ACIS0_MASK 1

These bits determine which comparator events that trigger the Analog Comparator interrupt.

ACIS1 - Analog Comparator Interrupt Mode Select bit 1

#define ACIS1_BIT 1

#define ACIS1_MASK 2

These bits determine which comparator events that trigger the Analog Comparator interrupt.

ACIC - Analog Comparator Input Capture Enable

#define ACIC_BIT 2

#define ACIC_MASK 4

When set (one), this bit enables the Input Capture function in Timer/Counter1 to be triggered by the analog comparator. The comparator output is in this case directly connected to the Input Capture front-end logic, making the comparator utilize the noise canceler and edge select features of the Timer/Counter1 Input Capture interrupt. When cleared (zero), no connection between the analog comparator and the Input Capture function is given. To make the comparator trigger the Timer/Counter1 Input Capture interrupt, the TICIE1 bit in the Timer Interrupt Mask Register (TIMSK) must be set (one)

ACIE - Analog Comparator Interrupt Enable

#define ACIE_BIT 3

#define ACIE_MASK 8

When the ACIE bit is set (one) and the I-bit in the Status Register is set (one), the analog comparator interrupt is activated. When Cleared (Zero), the interrupt is disabled.

ACI - Analog Comparator Interrupt Flag

#define ACI_BIT 4

#define ACI_MASK 16

This bit is set (one) when a comparator output event triggers the interrupt mode defined by ACI1 and ACI0. The Analog Comparator Interrupt routine is executed if the ACIE bit is set (one) and the I-bit in SREG is set (one). ACI is cleared by hardware when executing the corresponding interrupt handling vector. Alternatively, ACI is cleared by writing a logic one to the flag. Observe however, that if another bit in this register is modified using the SBI or CBI instruction, ACI will be cleared if it has become set before the operation

ACO - Analog Comparator Output

#define ACO_BIT 5

#define ACO_MASK 32

When this bit is set(one), the power to the analog comparator is switched off. This bit can be set at any time to turn off the analog comparator. This will reduce power consumption in active and idle mode. When changing the ACD bit, the Analog Comparator Interrupt must be disabled by clearing the ACIE bit in ACSR. Otherwise an interrupt can occur when the bit is changed.

ACD - Analog Comparator Disable

#define ACD_BIT 7

#define ACD_MASK 128

When this bit is set(one), the power to the analog comparator is switched off. This bit can be set at any time to turn off the analog comparator. This will reduce power consumption in active and idle mode. When changing the ACD bit, the Analog Comparator Interrupt must be disabled by clearing the ACIE bit in ACSR. Otherwise an interrupt can occur when the bit is changed.

SPI

The Serial Peripheral Interface(SPI) allows high-speed synchronous data transfer between the AT90S4414/8515 and peripheral devices or between several AVR devices. The AT90S4414/8515 SPI features include the following: • Full-duplex, 3-wire Synchronous Data Transfer • Master or Slave Operation • LSB First or MSB First Data Transfer • Four Programmable Bit Rates • End of Transmission Interrupt Flag • Write Collision Flag Protection • Wakeup from Idle Mode (Slave Mode Only)

SPCR - SPI Control Register

sfrb SPCR = $0D;

SPR0 - SPI Clock Rate Select 0

#define SPR0_BIT 0

#define SPR0_MASK 1

These two bits control the SCK rate of the device configured as a master. SPR1 and SPR0 have no effect on the slave.

SPR1 - SPI Clock Rate Select 1

#define SPR1_BIT 1

#define SPR1_MASK 2

These two bits control the SCK rate of the device configured as a master. SPR1 and SPR0 have no effect on the slave.

CPHA - Clock Phase

#define CPHA_BIT 2

#define CPHA_MASK 4

Refer to Figure 36 or Figure 37 for the functionality of this bit.

CPOL - Clock polarity

#define CPOL_BIT 3

#define CPOL_MASK 8

When this bit is set (one), SCK is high when idle. When CPOL is cleared (zero), SCK is low when idle. Refer to Figure 36 and Figure 37 for additional information.

MSTR - Master/Slave Select

#define MSTR_BIT 4

#define MSTR_MASK 16

This bit selects Master SPI mode when set (one), and Slave SPI mode when cleared (zero). If SS is configured as an input and is driven low while MSTR is set, MSTR will be cleared, and SPIF in SPSR will become set. The user will then have to set MSTR to re-enable SPI master mode.

DORD - Data Order

#define DORD_BIT 5

#define DORD_MASK 32

When the DORD bit is set (one), the LSB of the data word is transmitted first. When the DORD bit is cleared (zero), the MSB of the data word is transmitted first.

SPE - SPI Enable

#define SPE_BIT 6

#define SPE_MASK 64

When the SPE bit is set (one), the SPI is enabled. This bit must be set to enable any SPI operations.

SPIE - SPI Interrupt Enable

#define SPIE_BIT 7

#define SPIE_MASK 128

This bit causes the SPI interrupt to be executed if SPIF bit in the SPSR register is set and the global interrupts are enabled.

SPSR - SPI Status Register

sfrb SPSR = $0E;

WCOL - Write Collision Flag

#define WCOL_BIT 6

#define WCOL_MASK 64

The WCOL bit is set if the SPI data register (SPDR) is written during a data transfer. The WCOL bit (and the SPIF bit) are cleared (zero) by first reading the SPI Status Register when WCOL is set (one), and then accessing the SPI Data Register.

SPIF - SPI Interrupt Flag

#define SPIF_BIT 7

#define SPIF_MASK 128

When a serial transfer is complete, the SPIF bit is set (one) and an interrupt is generated if SPIE in SPCR is set (one) and global interrupts are enabled. If SS is an input and is driven low when the SPI is in master mode, this will also set the SPIF flag. SPIF is cleared by hardware when executing the corresponding interrupt handling vector. Alternatively, the SPIF bit is cleared by first reading the SPI status register when SPIF is set (one), then accessing the SPI Data Register (SPDR).

SPDR - SPI Data Register

sfrb SPDR = $0F;

SPDR0 - SPI Data Register bit 0

#define SPDR0_BIT 0

#define SPDR0_MASK 1

SPDR1 - SPI Data Register bit 1

#define SPDR1_BIT 1

#define SPDR1_MASK 2

SPDR2 - SPI Data Register bit 2

#define SPDR2_BIT 2

#define SPDR2_MASK 4

SPDR3 - SPI Data Register bit 3

#define SPDR3_BIT 3

#define SPDR3_MASK 8

SPDR4 - SPI Data Register bit 4

#define SPDR4_BIT 4

#define SPDR4_MASK 16

SPDR5 - SPI Data Register bit 5

#define SPDR5_BIT 5

#define SPDR5_MASK 32

SPDR6 - SPI Data Register bit 6

#define SPDR6_BIT 6

#define SPDR6_MASK 64

SPDR7 - SPI Data Register bit 7

#define SPDR7_BIT 7

#define SPDR7_MASK 128

UART

UDR - UART I/O Data Register

sfrb UDR = $0C;

UDR0 - UART I/O Data Register bit 0

#define UDR0_BIT 0

#define UDR0_MASK 1

UDR1 - UART I/O Data Register bit 1

#define UDR1_BIT 1

#define UDR1_MASK 2

UDR2 - UART I/O Data Register bit 2

#define UDR2_BIT 2

#define UDR2_MASK 4

UDR3 - UART I/O Data Register bit 3

#define UDR3_BIT 3

#define UDR3_MASK 8

UDR4 - UART I/O Data Register bit 4

#define UDR4_BIT 4

#define UDR4_MASK 16

UDR5 - UART I/O Data Register bit 5

#define UDR5_BIT 5

#define UDR5_MASK 32

UDR6 - UART I/O Data Register bit 6

#define UDR6_BIT 6

#define UDR6_MASK 64

UDR7 - UART I/O Data Register bit 7

#define UDR7_BIT 7

#define UDR7_MASK 128

USR - UART Status Register

sfrb USR = $0B;

OR - Overrun

#define OR_BIT 3

#define OR_MASK 8

This bit is set if an Overrun condition is detected, i.e. when a character already present in the UDR register is not read before the next character has been shifted into the Receiver Shift register. The OR bit is buffered, which means that it will be set once the valid data still in UDRE is read. The OR bit is cleared (zero) when data is received and transferred to UDR.

FE - Framing Error

#define FE_BIT 4

#define FE_MASK 16

This bit is set if a Framing Error condition is detected, i.e. when the stop bit of an incoming character is zero. The FE bit is cleared when the stop bit of received data is one.

UDRE - UART Data Register Empty

#define UDRE_BIT 5

#define UDRE_MASK 32

This bit is set (one) when a character written to UDR is transferred to the Transmit shift register. Setting of this bit indicates that the transmitter is ready to receive a new character for transmission. When the UDRIE bit in UCR is set, the UART Transmit Complete interrupt to be executed as long as UDRE is set. UDRE is cleared by writing UDR. When interrupt-driven data transmittal is used, the UART Data Register Empty Interrupt routine must write UDR in order to clear UDRE, otherwise a new interrupt will occur once the interrupt routine terminates. UDRE is set (one) during reset to indicate that the transmitter is ready

TXC - UART Transmit Complete

#define TXC_BIT 6

#define TXC_MASK 64

This bit is set (one) when the entire character (including the stop bit) in the Transmit Shift register has been shifted out and no new data has been written to UDR. This flag is especially useful in half-duplex communications interfaces, where a transmitting application must enter receive mode and free the communications bus immediately after completing the transmission. When the TXCIE bit in UCR is set, setting of TXC causes the UART Transmit Complete interrupt to be executed. TXC is cleared by hardware when executing the corresponding interrupt handling vector. Alternatively, the TXC bit is cleared (zero) by writing a logical one to the bit

RXC - UART Receive Complete

#define RXC_BIT 7

#define RXC_MASK 128

This bit is set (one) when a received character is transferred from the Receiver Shift register to UDR. The bit is set regard-less of any detected framing errors. When the RXCIE bit in UCR is set, the UART Receive Complete interrupt will be executed when RXC is set(one). RXC is cleared by reading UDR. When interrupt-driven data reception is used, the UART Receive Complete Interrupt routine must read UDR in order to clear RXC, otherwise a new interrupt will occur once the interrupt routine terminates.

UCR - UART Control Register

sfrb UCR = $0A;

TXB8 - Transmit Data Bit 8

#define TXB8_BIT 0

#define TXB8_MASK 1

When CHR9 is set (one), TXB8 is the 9th data bit in the character to be transmitted.

RXB8 - Receive Data Bit 8

#define RXB8_BIT 1

#define RXB8_MASK 2

When CHR9 is set (one), RXB8 is the 9th data bit of the received character.

CHR9 - 9-bit Characters

#define CHR9_BIT 2

#define CHR9_MASK 4

When this bit is set (one) transmitted and received characters are 9 bit long plus start and stop bits. The 9th bit is read and written by using the RXB8 and TXB8 bits in UCR, respectively. The 9th data bit can be used as an extra stop bit or a parity bit.

TXEN - Transmitter Enable

#define TXEN_BIT 3

#define TXEN_MASK 8

This bit enables the UART transmitter when set (one). When disabling the transmitter while transmitting a character, the transmitter is not disabled before the character in the shift register plus any following character in UDR has been completely transmitted.

RXEN - Receiver Enable

#define RXEN_BIT 4

#define RXEN_MASK 16

This bit enables the UART receiver when set (one). When the receiver is disabled, the TXC, OR and FE status flags cannot become set. If these flags are set, turning off RXEN does not cause them to be cleared.

UDRIE - UART Data Register Empty Interrupt Enable

#define UDRIE_BIT 5

#define UDRIE_MASK 32

When this bit is set (one), a setting of the UDRE bit in USR will cause the UART Data Register Empty interrupt routine to be executed provided that global interrupts are enabled.

TXCIE - TX Complete Interrupt Enable

#define TXCIE_BIT 6

#define TXCIE_MASK 64

When this bit is set (one), a setting of the TXC bit in USR will cause the Transmit Complete interrupt routine to be executed provided that global interrupts are enabled.

RXCIE - RX Complete Interrupt Enable

#define RXCIE_BIT 7

#define RXCIE_MASK 128

When this bit is set (one), a setting of the RXC bit in USR will cause the Receive Complete interrupt routine to be executed provided that global interrupts are enabled.

UBRR - UART BAUD Rate Register

sfrb UBRR = $09;

UBRR0 - UART Baud Rate Register bit 0

#define UBRR0_BIT 0

#define UBRR0_MASK 1

UBRR1 - UART Baud Rate Register bit 1

#define UBRR1_BIT 1

#define UBRR1_MASK 2

UBRR2 - UART Baud Rate Register bit 2

#define UBRR2_BIT 2

#define UBRR2_MASK 4

UBRR3 - UART Baud Rate Register bit 3

#define UBRR3_BIT 3

#define UBRR3_MASK 8

UBRR4 - UART Baud Rate Register bit 4

#define UBRR4_BIT 4

#define UBRR4_MASK 16

UBRR5 - UART Baud Rate Register bit 5

#define UBRR5_BIT 5

#define UBRR5_MASK 32

UBRR6 - UART Baud Rate Register bit 6

#define UBRR6_BIT 6

#define UBRR6_MASK 64

UBRR7 - UART Baud Rate Register bit 7

#define UBRR7_BIT 7

#define UBRR7_MASK 128

CPU

SREG - Status Register

sfrb SREG = $3F;

SPH - Stack Pointer High

sfrb SPH = $3E;

SP8 - Stack pointer bit 8

#define SP8_BIT 0

#define SP8_MASK 1

SP9 - Stack pointer bit 9

#define SP9_BIT 1

#define SP9_MASK 2

SP10 - Stack pointer bit 10

#define SP10_BIT 2

#define SP10_MASK 4

SP11 - Stack pointer bit 11

#define SP11_BIT 3

#define SP11_MASK 8

SP12

#define SP12_BIT 4

#define SP12_MASK 16

SP13 - Stack pointer bit 13

#define SP13_BIT 5

#define SP13_MASK 32

SP14 - Stack pointer bit 14

#define SP14_BIT 6

#define SP14_MASK 64

SP15 - Stack pointer bit 15

#define SP15_BIT 7

#define SP15_MASK 128

SPL - Stack Pointer Low

sfrb SPL = $3D;

SP0 - Stack pointer bit 0

#define SP0_BIT 0

#define SP0_MASK 1

SP1 - Stack pointer bit 1

#define SP1_BIT 1

#define SP1_MASK 2

SP2 - Stack pointer bit 2

#define SP2_BIT 2

#define SP2_MASK 4

SP3 - Stack pointer bit 3

#define SP3_BIT 3

#define SP3_MASK 8

SP4

#define SP4_BIT 4

#define SP4_MASK 16

SP5 - Stack pointer bit 5

#define SP5_BIT 5

#define SP5_MASK 32

SP6 - Stack pointer bit 6

#define SP6_BIT 6

#define SP6_MASK 64

SP7 - Stack pointer bit 7

#define SP7_BIT 7

#define SP7_MASK 128

MCUCR - MCU Control Register

sfrb MCUCR = $35;

SM0 - Sleep Mode Select

#define SM0_BIT 3

#define SM0_MASK 8

The description is to long for the tooltip help, please refer to the manual

SM1 - Sleep Mode Select

#define SM1_BIT 4

#define SM1_MASK 16

The description is to long for the tooltip help, please refer to the manual

SE - Sleep Enable

#define SE_BIT 5

#define SE_MASK 32

SRW - External SRAM Wait State Select

#define SRW_BIT 6

#define SRW_MASK 64

For a detailed description in non ATmega103 Compatibility mode, see common description for the SRWn bits below (XMRA description). In ATmega103 Compatibility mode, writing SRW10 to one enables the wait state and one extra cycle is added during read/write strobe as shown in Figure 14.

SRE - External SRAM Enable

#define SRE_BIT 7

#define SRE_MASK 128

Writing SRE to one enables the External Memory Interface.The pin functions AD7:0, A15:8, ALE, WR, and RD are acti-vated as the alternate pin functions. The SRE bit overrides any pin direction settings in the respective data direction regis-ters. Writing SRE to zero, disables the External Memory Interface and the normal pin and data direction settings are used.

MCUSR - MCU Status Register

sfrb MCUSR = $34;

PORF - Power-on reset flag

#define PORF_BIT 0

#define PORF_MASK 1

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_BIT 1

#define EXTRF_MASK 2

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.

XDIV - XTAL Divide Control Register

sfrb XDIV = $3C;

XDIV0 - XTAl Divide Select Bit 0

#define XDIV0_BIT 0

#define XDIV0_MASK 1

These bits define the division factor that applies when the XDIVEN bit is set (one). Please refer to the manual for details on the formulas.

XDIV1 - XTAl Divide Select Bit 1

#define XDIV1_BIT 1

#define XDIV1_MASK 2

These bits define the division factor that applies when the XDIVEN bit is set (one). Please refer to the manual for details on the formulas.

XDIV2 - XTAl Divide Select Bit 2

#define XDIV2_BIT 2

#define XDIV2_MASK 4

These bits define the division factor that applies when the XDIVEN bit is set (one). Please refer to the manual for details on the formulas.

XDIV3 - XTAl Divide Select Bit 3

#define XDIV3_BIT 3

#define XDIV3_MASK 8

These bits define the division factor that applies when the XDIVEN bit is set (one). Please refer to the manual for details on the formulas.

XDIV4 - XTAl Divide Select Bit 4

#define XDIV4_BIT 4

#define XDIV4_MASK 16

These bits define the division factor that applies when the XDIVEN bit is set (one). Please refer to the manual for details on the formulas.

XDIV5 - XTAl Divide Select Bit 5

#define XDIV5_BIT 5

#define XDIV5_MASK 32

These bits define the division factor that applies when the XDIVEN bit is set (one). Please refer to the manual for details on the formulas.

XDIV6 - XTAl Divide Select Bit 6

#define XDIV6_BIT 6

#define XDIV6_MASK 64

These bits define the division factor that applies when the XDIVEN bit is set (one). Please refer to the manual for details on the formulas.

XDIVEN - XTAL Divide Enable

#define XDIVEN_BIT 7

#define XDIVEN_MASK 128

When the XDIVEN bit is written one, the clock frequency of the CPU and all peripherals (clk I/O , clk ADC , clk CPU , clk FLASH ) is divided by the factor defined by the setting of XDIV6 - XDIV0. This bit can be written run-time to vary the clock frequency as suitable to the application.

RAMPZ - RAM Page Z Select Register

sfrb RAMPZ = $3B;

RAMPZ0 - RAMPZ0 = 0: Program memory address $0000 - $7FFF. RAMPZ0 = 1, program memory address $8000 - $FFFF.

#define RAMPZ0_BIT 0

#define RAMPZ0_MASK 1

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 interrupt

EICRB - External Interrupt Control Register B

sfrb EICRB = $3A;

ISC40 - External Interrupt 7-4 Sense Control Bit

#define ISC40_BIT 0

#define ISC40_MASK 1

ISC41 - External Interrupt 7-4 Sense Control Bit

#define ISC41_BIT 1

#define ISC41_MASK 2

ISC50 - External Interrupt 7-4 Sense Control Bit

#define ISC50_BIT 2

#define ISC50_MASK 4

ISC51 - External Interrupt 7-4 Sense Control Bit

#define ISC51_BIT 3

#define ISC51_MASK 8

ISC60 - External Interrupt 7-4 Sense Control Bit

#define ISC60_BIT 4

#define ISC60_MASK 16

ISC61 - External Interrupt 7-4 Sense Control Bit

#define ISC61_BIT 5

#define ISC61_MASK 32

ISC70 - External Interrupt 7-4 Sense Control Bit

#define ISC70_BIT 6

#define ISC70_MASK 64

ISC71 - External Interrupt 7-4 Sense Control Bit

#define ISC71_BIT 7

#define ISC71_MASK 128

EIMSK - External Interrupt Mask Register

sfrb EIMSK = $39;

INT0 - External Interrupt Request 0 Enable

#define INT0_BIT 0

#define INT0_MASK 1

INT1 - External Interrupt Request 1 Enable

#define INT1_BIT 1

#define INT1_MASK 2

INT2 - External Interrupt Request 2 Enable

#define INT2_BIT 2

#define INT2_MASK 4

INT3 - External Interrupt Request 3 Enable

#define INT3_BIT 3

#define INT3_MASK 8

INT4 - External Interrupt Request 4 Enable

#define INT4_BIT 4

#define INT4_MASK 16

INT5 - External Interrupt Request 5 Enable

#define INT5_BIT 5

#define INT5_MASK 32

INT6 - External Interrupt Request 6 Enable

#define INT6_BIT 6

#define INT6_MASK 64

INT7 - External Interrupt Request 7 Enable

#define INT7_BIT 7

#define INT7_MASK 128

EIFR - External Interrupt Flag Register

sfrb EIFR = $38;

INTF4 - External Interrupt Flag 4

#define INTF4_BIT 4

#define INTF4_MASK 16

INTF5 - External Interrupt Flag 5

#define INTF5_BIT 5

#define INTF5_MASK 32

INTF6 - External Interrupt Flag 6

#define INTF6_BIT 6

#define INTF6_MASK 64

INTF7 - External Interrupt Flag 7

#define INTF7_BIT 7

#define INTF7_MASK 128

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 Read/Write Access High Byte

sfrb EEARH = $1F;

EEAR8 - EEPROM Read/Write Access Bit 8

#define EEAR8_BIT 0

#define EEAR8_MASK 1

EEAR9 - EEPROM Read/Write Access Bit 9

#define EEAR9_BIT 1

#define EEAR9_MASK 2

EEAR10 - EEPROM Read/Write Access Bit 10

#define EEAR10_BIT 2

#define EEAR10_MASK 4

EEAR11 - EEPROM Read/Write Access Bit 11

#define EEAR11_BIT 3

#define EEAR11_MASK 8

EEARL - EEPROM Read/Write Access Low Byte

sfrb EEARL = $1E;

EEARL0 - EEPROM Read/Write Access Bit 0

#define EEARL0_BIT 0

#define EEARL0_MASK 1

EEARL1 - EEPROM Read/Write Access Bit 1

#define EEARL1_BIT 1

#define EEARL1_MASK 2

EEARL2 - EEPROM Read/Write Access Bit 2

#define EEARL2_BIT 2

#define EEARL2_MASK 4

EEARL3 - EEPROM Read/Write Access Bit 3

#define EEARL3_BIT 3

#define EEARL3_MASK 8

EEARL4 - EEPROM Read/Write Access Bit 4

#define EEARL4_BIT 4

#define EEARL4_MASK 16

EEARL5 - EEPROM Read/Write Access Bit 5

#define EEARL5_BIT 5

#define EEARL5_MASK 32

EEARL6 - EEPROM Read/Write Access Bit 6

#define EEARL6_BIT 6

#define EEARL6_MASK 64

EEARL7 - EEPROM Read/Write Access Bit 7

#define EEARL7_BIT 7

#define EEARL7_MASK 128

EEDR - EEPROM Data Register

sfrb EEDR = $1D;

EEDR0 - EEPROM Data Register bit 0

#define EEDR0_BIT 0

#define EEDR0_MASK 1

EEDR1 - EEPROM Data Register bit 1

#define EEDR1_BIT 1

#define EEDR1_MASK 2

EEDR2 - EEPROM Data Register bit 2

#define EEDR2_BIT 2

#define EEDR2_MASK 4

EEDR3 - EEPROM Data Register bit 3

#define EEDR3_BIT 3

#define EEDR3_MASK 8

EEDR4 - EEPROM Data Register bit 4

#define EEDR4_BIT 4

#define EEDR4_MASK 16

EEDR5 - EEPROM Data Register bit 5

#define EEDR5_BIT 5

#define EEDR5_MASK 32

EEDR6 - EEPROM Data Register bit 6

#define EEDR6_BIT 6

#define EEDR6_MASK 64

EEDR7 - EEPROM Data Register bit 7

#define EEDR7_BIT 7

#define EEDR7_MASK 128

EECR - EEPROM Control Register

sfrb EECR = $1C;

EERE - EEPROM Read Enable

#define EERE_BIT 0

#define EERE_MASK 1

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_BIT 1

#define EEWE_MASK 2

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_BIT 2

#define EEMWE_MASK 4

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_BIT 3

#define EERIE_MASK 8

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.

PORTA

PORTA - Port A Data Register

sfrb PORTA = $1B;

PORTA0 - Port A Data Register bit 0

#define PORTA0_BIT 0

#define PORTA0_MASK 1

PORTA1 - Port A Data Register bit 1

#define PORTA1_BIT 1

#define PORTA1_MASK 2

PORTA2 - Port A Data Register bit 2

#define PORTA2_BIT 2

#define PORTA2_MASK 4

PORTA3 - Port A Data Register bit 3

#define PORTA3_BIT 3

#define PORTA3_MASK 8

PORTA4 - Port A Data Register bit 4

#define PORTA4_BIT 4

#define PORTA4_MASK 16

PORTA5 - Port A Data Register bit 5

#define PORTA5_BIT 5

#define PORTA5_MASK 32

PORTA6 - Port A Data Register bit 6

#define PORTA6_BIT 6

#define PORTA6_MASK 64

PORTA7 - Port A Data Register bit 7

#define PORTA7_BIT 7

#define PORTA7_MASK 128

DDRA - Port A Data Direction Register

sfrb DDRA = $1A;

DDA0 - Data Direction Register, Port A, bit 0

#define DDA0_BIT 0

#define DDA0_MASK 1

DDA1 - Data Direction Register, Port A, bit 1

#define DDA1_BIT 1

#define DDA1_MASK 2

DDA2 - Data Direction Register, Port A, bit 2

#define DDA2_BIT 2

#define DDA2_MASK 4

DDA3 - Data Direction Register, Port A, bit 3

#define DDA3_BIT 3

#define DDA3_MASK 8

DDA4 - Data Direction Register, Port A, bit 4

#define DDA4_BIT 4

#define DDA4_MASK 16

DDA5 - Data Direction Register, Port A, bit 5

#define DDA5_BIT 5

#define DDA5_MASK 32

DDA6 - Data Direction Register, Port A, bit 6

#define DDA6_BIT 6

#define DDA6_MASK 64

DDA7 - Data Direction Register, Port A, bit 7

#define DDA7_BIT 7

#define DDA7_MASK 128

PINA - Port A Input Pins

sfrb PINA = $19;

PINA0 - Input Pins, Port A bit 0

#define PINA0_BIT 0

#define PINA0_MASK 1

PINA1 - Input Pins, Port A bit 1

#define PINA1_BIT 1

#define PINA1_MASK 2

PINA2 - Input Pins, Port A bit 2

#define PINA2_BIT 2

#define PINA2_MASK 4

PINA3 - Input Pins, Port A bit 3

#define PINA3_BIT 3

#define PINA3_MASK 8

PINA4 - Input Pins, Port A bit 4

#define PINA4_BIT 4

#define PINA4_MASK 16

PINA5 - Input Pins, Port A bit 5

#define PINA5_BIT 5

#define PINA5_MASK 32

PINA6 - Input Pins, Port A bit 6

#define PINA6_BIT 6

#define PINA6_MASK 64

PINA7 - Input Pins, Port A bit 7

#define PINA7_BIT 7

#define PINA7_MASK 128

PORTB

PORTB - Port B Data Register

sfrb PORTB = $18;

PORTB0 - Port B Data Register bit 0

#define PORTB0_BIT 0

#define PORTB0_MASK 1

PORTB1 - Port B Data Register bit 1

#define PORTB1_BIT 1

#define PORTB1_MASK 2

PORTB2 - Port B Data Register bit 2

#define PORTB2_BIT 2

#define PORTB2_MASK 4

PORTB3 - Port B Data Register bit 3

#define PORTB3_BIT 3

#define PORTB3_MASK 8

PORTB4 - Port B Data Register bit 4

#define PORTB4_BIT 4

#define PORTB4_MASK 16

PORTB5 - Port B Data Register bit 5

#define PORTB5_BIT 5

#define PORTB5_MASK 32

PORTB6 - Port B Data Register bit 6

#define PORTB6_BIT 6

#define PORTB6_MASK 64

PORTB7 - Port B Data Register bit 7

#define PORTB7_BIT 7

#define PORTB7_MASK 128

DDRB - Port B Data Direction Register

sfrb DDRB = $17;

DDB0 - Port B Data Direction Register bit 0

#define DDB0_BIT 0

#define DDB0_MASK 1

DDB1 - Port B Data Direction Register bit 1

#define DDB1_BIT 1

#define DDB1_MASK 2

DDB2 - Port B Data Direction Register bit 2

#define DDB2_BIT 2

#define DDB2_MASK 4

DDB3 - Port B Data Direction Register bit 3

#define DDB3_BIT 3

#define DDB3_MASK 8

DDB4 - Port B Data Direction Register bit 4

#define DDB4_BIT 4

#define DDB4_MASK 16

DDB5 - Port B Data Direction Register bit 5

#define DDB5_BIT 5

#define DDB5_MASK 32

DDB6 - Port B Data Direction Register bit 6

#define DDB6_BIT 6

#define DDB6_MASK 64

DDB7 - Port B Data Direction Register bit 7

#define DDB7_BIT 7

#define DDB7_MASK 128

PINB - Port B Input Pins

sfrb PINB = $16;

PINB0 - Port B Input Pins bit 0

#define PINB0_BIT 0

#define PINB0_MASK 1

PINB1 - Port B Input Pins bit 1

#define PINB1_BIT 1

#define PINB1_MASK 2

PINB2 - Port B Input Pins bit 2

#define PINB2_BIT 2

#define PINB2_MASK 4

PINB3 - Port B Input Pins bit 3

#define PINB3_BIT 3

#define PINB3_MASK 8

PINB4 - Port B Input Pins bit 4

#define PINB4_BIT 4

#define PINB4_MASK 16

PINB5 - Port B Input Pins bit 5

#define PINB5_BIT 5

#define PINB5_MASK 32

PINB6 - Port B Input Pins bit 6

#define PINB6_BIT 6

#define PINB6_MASK 64

PINB7 - Port B Input Pins bit 7

#define PINB7_BIT 7

#define PINB7_MASK 128

PORTD

PORTD - Port D Data Register

sfrb PORTD = $12;

PORTD0 - Port D Data Register bit 0

#define PORTD0_BIT 0

#define PORTD0_MASK 1

PORTD1 - Port D Data Register bit 1

#define PORTD1_BIT 1

#define PORTD1_MASK 2

PORTD2 - Port D Data Register bit 2

#define PORTD2_BIT 2

#define PORTD2_MASK 4

PORTD3 - Port D Data Register bit 3

#define PORTD3_BIT 3

#define PORTD3_MASK 8

PORTD4 - Port D Data Register bit 4

#define PORTD4_BIT 4

#define PORTD4_MASK 16

PORTD5 - Port D Data Register bit 5

#define PORTD5_BIT 5

#define PORTD5_MASK 32

PORTD6 - Port D Data Register bit 6

#define PORTD6_BIT 6

#define PORTD6_MASK 64

PORTD7 - Port D Data Register bit 7

#define PORTD7_BIT 7

#define PORTD7_MASK 128

DDRD - Port D Data Direction Register

sfrb DDRD = $11;

DDD0 - Port D Data Direction Register bit 0

#define DDD0_BIT 0

#define DDD0_MASK 1

DDD1 - Port D Data Direction Register bit 1

#define DDD1_BIT 1

#define DDD1_MASK 2

DDD2 - Port D Data Direction Register bit 2

#define DDD2_BIT 2

#define DDD2_MASK 4

DDD3 - Port D Data Direction Register bit 3

#define DDD3_BIT 3

#define DDD3_MASK 8

DDD4 - Port D Data Direction Register bit 4

#define DDD4_BIT 4

#define DDD4_MASK 16

DDD5 - Port D Data Direction Register bit 5

#define DDD5_BIT 5

#define DDD5_MASK 32

DDD6 - Port D Data Direction Register bit 6

#define DDD6_BIT 6

#define DDD6_MASK 64

DDD7 - Port D Data Direction Register bit 7

#define DDD7_BIT 7

#define DDD7_MASK 128

PIND - Port D Input Pins

sfrb PIND = $10;

PIND0 - Port D Input Pins bit 0

#define PIND0_BIT 0

#define PIND0_MASK 1

PIND1 - Port D Input Pins bit 1

#define PIND1_BIT 1

#define PIND1_MASK 2

PIND2 - Port D Input Pins bit 2

#define PIND2_BIT 2

#define PIND2_MASK 4

PIND3 - Port D Input Pins bit 3

#define PIND3_BIT 3

#define PIND3_MASK 8

PIND4 - Port D Input Pins bit 4

#define PIND4_BIT 4

#define PIND4_MASK 16

PIND5 - Port D Input Pins bit 5

#define PIND5_BIT 5

#define PIND5_MASK 32

PIND6 - Port D Input Pins bit 6

#define PIND6_BIT 6

#define PIND6_MASK 64

PIND7 - Port D Input Pins bit 7

#define PIND7_BIT 7

#define PIND7_MASK 128

PORTC

PORTC - Port C Data Register

sfrb PORTC = $15;

PORTC0 - Port C Data Register bit 0

#define PORTC0_BIT 0

#define PORTC0_MASK 1

PORTC1 - Port C Data Register bit 1

#define PORTC1_BIT 1

#define PORTC1_MASK 2

PORTC2 - Port C Data Register bit 2

#define PORTC2_BIT 2

#define PORTC2_MASK 4

PORTC3 - Port C Data Register bit 3

#define PORTC3_BIT 3

#define PORTC3_MASK 8

PORTC4 - Port C Data Register bit 4

#define PORTC4_BIT 4

#define PORTC4_MASK 16

PORTC5 - Port C Data Register bit 5

#define PORTC5_BIT 5

#define PORTC5_MASK 32

PORTC6 - Port C Data Register bit 6

#define PORTC6_BIT 6

#define PORTC6_MASK 64

PORTC7 - Port C Data Register bit 7

#define PORTC7_BIT 7

#define PORTC7_MASK 128

PORTE

PORTE - Data Register, Port E

sfrb PORTE = $03;

PORTE0

#define PORTE0_BIT 0

#define PORTE0_MASK 1

PORTE1

#define PORTE1_BIT 1

#define PORTE1_MASK 2

PORTE2

#define PORTE2_BIT 2

#define PORTE2_MASK 4

PORTE3

#define PORTE3_BIT 3

#define PORTE3_MASK 8

PORTE4

#define PORTE4_BIT 4

#define PORTE4_MASK 16

PORTE5

#define PORTE5_BIT 5

#define PORTE5_MASK 32

PORTE6

#define PORTE6_BIT 6

#define PORTE6_MASK 64

PORTE7

#define PORTE7_BIT 7

#define PORTE7_MASK 128

DDRE - Data Direction Register, Port E

sfrb DDRE = $02;

DDE0

#define DDE0_BIT 0

#define DDE0_MASK 1

DDE1

#define DDE1_BIT 1

#define DDE1_MASK 2

DDE2

#define DDE2_BIT 2

#define DDE2_MASK 4

DDE3

#define DDE3_BIT 3

#define DDE3_MASK 8

DDE4

#define DDE4_BIT 4

#define DDE4_MASK 16

DDE5

#define DDE5_BIT 5

#define DDE5_MASK 32

DDE6

#define DDE6_BIT 6

#define DDE6_MASK 64

DDE7

#define DDE7_BIT 7

#define DDE7_MASK 128

PINE - Input Pins, Port E

sfrb PINE = $01;

PINE0

#define PINE0_BIT 0

#define PINE0_MASK 1

PINE1

#define PINE1_BIT 1

#define PINE1_MASK 2

PINE2

#define PINE2_BIT 2

#define PINE2_MASK 4

PINE3

#define PINE3_BIT 3

#define PINE3_MASK 8

PINE4

#define PINE4_BIT 4

#define PINE4_MASK 16

PINE5

#define PINE5_BIT 5

#define PINE5_MASK 32

PINE6

#define PINE6_BIT 6

#define PINE6_MASK 64

PINE7

#define PINE7_BIT 7

#define PINE7_MASK 128

PORTF

PINF - Input Pins, Port F

sfrb PINF = $00;

PINF0

#define PINF0_BIT 0

#define PINF0_MASK 1

PINF1

#define PINF1_BIT 1

#define PINF1_MASK 2

PINF2

#define PINF2_BIT 2

#define PINF2_MASK 4

PINF3

#define PINF3_BIT 3

#define PINF3_MASK 8

PINF4

#define PINF4_BIT 4

#define PINF4_MASK 16

PINF5

#define PINF5_BIT 5

#define PINF5_MASK 32

PINF6

#define PINF6_BIT 6

#define PINF6_MASK 64

PINF7

#define PINF7_BIT 7

#define PINF7_MASK 128

TIMER COUNTER 2

The 8-bit Timer/Counter2 can select clock source from CK, prescaled CK, or external crystal input TOSC1. It can also be stopped as described in the section “Timer/Counter2 Control Register - TCCR2”. The status flags (overflow and compare match) are found in the Timer/Counter Interrupt Flag Register - TIFR. Control signals are found in the Timer/Counter Control Register TCCR2. The interrupt enable/disable settings are found in “The Timer/Counter Interrupt Mask Register - TIMSK”. When Timer/Counter2 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. This module features a high resolution and a high accuracy usage with the lower prescaling opportunities. Similarly, the high prescaling opportunities make this unit useful for lower speed functions or exact timing functions with infrequent actions. Timer/Counter2 can also be used as an 8-bit Pulse Width Modulator. In this mode, Timer/Counter2 and the output compare register serve as a glitch-free, stand-alone PWM with centered puls

TIMSK - Timer/Counter Interrupt Mask register

sfrb TIMSK = $37;

TOIE2 - Timer/Counter2 Overflow Interrupt Enable

#define TOIE2_BIT 6

#define TOIE2_MASK 64

When the TOIE2 bit is set (one) and the I-bit in the Status Register is set (one), the Timer/Counter2 Overflow interrupt is

OCIE2 - Timer/Counter2 Output Compare Match Interrupt Enable

#define OCIE2_BIT 7

#define OCIE2_MASK 128

When the OCIE2 bit is set (one) and the I-bit in the Status Register is set (one), the Timer/Counter2 Compare Match interrupt is enabled. The corresponding interrupt (at vector $006) is executed if a compare match in Timer/Counter2 occurs, i.e. when the OCF2 bit is set in the Timer/Counter Interrupt Flag Register - TIFR.

TIFR - Timer/Counter Interrupt Flag Register

sfrb TIFR = $36;

TOV2 - Timer/Counter2 Overflow Flag

#define TOV2_BIT 6

#define TOV2_MASK 64

The TOV2 bit is set (one) when an overflow occurs in Timer/Counter2. TOV2 is cleared by hardware when executing the corresponding interrupt handling vector. Alternatively, TOV2 is cleared by writing a logic one to the flag. When the SREG I-bit, and TOIE2 (Timer/Counter2 Overflow Interrupt Enable), and TOV2 are set (one), the Timer/Counter2 Overflow interrupt is executed. In up/down PWM mode, this bit is set when Timer/Counter2 changes counting direction at $00.

OCF2 - Output Compare Flag 2

#define OCF2_BIT 7

#define OCF2_MASK 128

The OCF2 bit is set (one) when a compare match occurs between the Timer/Counter2 and the data in OCR2 - Output Compare Register2. OCF2 is cleared by hardware when executing the corresponding interrupt handling vector. Alternatively, OCF2 is cleared by writing a logic one to the flag. When the I-bit in SREG, and OCIE2 (Timer/Counter2 Compare match Interrupt Enable), and the OCF2 are set (one), the Timer/Counter2 Compare match Interrupt is executed.

TCCR2 - Timer/Counter2 Control Register

sfrb TCCR2 = $25;

CS20 - Clock Select bit 0

#define CS20_BIT 0

#define CS20_MASK 1

The Clock Select bits 2,1, and 0 define the prescaling source of Timer/Counter2. (CS22:CS21:CS20) Description. (0:0:0) Timer/Counter2 is stopped. (0:0:1) PCK2. (0:1:0) PCK2/8. (0:1:1) PCK2/32. (1:0:0) PCK2/64. (1:0:1) PCK2/128. (1:1:0) PCK2/256. (1:1:1) PCK2/1024. The Stop condition provides a Timer Enable/Disable function. The prescaled modes are scaled directly from the PCK2 clock.

CS21 - Clock Select bit 1

#define CS21_BIT 1

#define CS21_MASK 2

The Clock Select bits 2,1, and 0 define the prescaling source of Timer/Counter2. (CS22:CS21:CS20) Description. (0:0:0) Timer/Counter2 is stopped. (0:0:1) PCK2. (0:1:0) PCK2/8. (0:1:1) PCK2/32. (1:0:0) PCK2/64. (1:0:1) PCK2/128. (1:1:0) PCK2/256. (1:1:1) PCK2/1024. The Stop condition provides a Timer Enable/Disable function. The prescaled modes are scaled directly from the PCK2 clock.

CS22 - Clock Select bit 2

#define CS22_BIT 2

#define CS22_MASK 4

The Clock Select bits 2,1, and 0 define the prescaling source of Timer/Counter2. (CS22:CS21:CS20) Description. (0:0:0) Timer/Counter2 is stopped. (0:0:1) PCK2. (0:1:0) PCK2/8. (0:1:1) PCK2/32. (1:0:0) PCK2/64. (1:0:1) PCK2/128. (1:1:0) PCK2/256. (1:1:1) PCK2/1024. The Stop condition provides a Timer Enable/Disable function. The prescaled modes are scaled directly from the PCK2 clock.

CTC2 - Clear Timer/Counter2 on Compare Match

#define CTC2_BIT 3

#define CTC2_MASK 8

When the CTC2 control bit is set (one), Timer/Counter2 is reset to $00 in the CPU clock cycle following a compare match. If the control bit is cleared, the Timer/Counter2 continues counting and is unaffected by a compare match. When a prescal-ing of 1 is used, and the compare register is set to C, the timer will count as follows if CTC2 is set: ...|C-1|C|0|1|... When the prescaler is set to divide by 8, the timer will count like this: ...|C-1,C-1,C-1,C-1,C-1,C-1,C-1,C-1|C,C,C,C,C,C,C,C |0,0,0,0,0,0,0,0|1,1,1,... In PWM mode, this bit has a different function. If the CTC2 bit is cleared in PWM mode, the Timer/Counter acts as an up/down counter. If the CTC2 bit is set (one), the Timer/Counter wraps when it reaches $FF

COM20 - Compare Output Mode bit 0

#define COM20_BIT 4

#define COM20_MASK 16

The COM21 and COM20 control bits determine any output pin action following a compare match in Timer/Counter2. Output pin actions affect pin PD7(OC2). This is an alternative function to an I/O port, and the corresponding direction control bit must be set (one) to control an output pin. (COM21:COM20) description: (0:0) = Timer/Counter disconnected from output pin OC2. (0:1) = Toggle the OC2 output line. (1:0) = Clear the OC2 output line (to zero). (1:1) = Set the OC2 output line (to one). Note: In PWM mode, these bits have a different function.

COM21 - Compare Output Mode bit 1

#define COM21_BIT 5

#define COM21_MASK 32

The COM21 and COM20 control bits determine any output pin action following a compare match in Timer/Counter2. Output pin actions affect pin PD7(OC2). This is an alternative function to an I/O port, and the corresponding direction control bit must be set (one) to control an output pin. (COM21:COM20) description: (0:0) = Timer/Counter disconnected from output pin OC2. (0:1) = Toggle the OC2 output line. (1:0) = Clear the OC2 output line (to zero). (1:1) = Set the OC2 output line (to one). Note: In PWM mode, these bits have a different function.

PWM2 - Pulse Width Modulator Enable

#define PWM2_BIT 6

#define PWM2_MASK 64

When set (one) this bit enables PWM mode for Timer/Counter2.

TCNT2 - Timer/Counter2

sfrb TCNT2 = $24;

TCNT2-0 - Timer/Counter 2 bit 0

#define TCNT2-0_BIT 0

#define TCNT2-0_MASK 1

TCNT2-1 - Timer/Counter 2 bit 1

#define TCNT2-1_BIT 1

#define TCNT2-1_MASK 2

TCNT2-2 - Timer/Counter 2 bit 2

#define TCNT2-2_BIT 2

#define TCNT2-2_MASK 4

TCNT2-3 - Timer/Counter 2 bit 3

#define TCNT2-3_BIT 3

#define TCNT2-3_MASK 8

TCNT2-4 - Timer/Counter 2 bit 4

#define TCNT2-4_BIT 4

#define TCNT2-4_MASK 16

TCNT2-5 - Timer/Counter 2 bit 5

#define TCNT2-5_BIT 5

#define TCNT2-5_MASK 32

TCNT2-6 - Timer/Counter 2 bit 6

#define TCNT2-6_BIT 6

#define TCNT2-6_MASK 64

TCNT2-7 - Timer/Counter 2 bit 7

#define TCNT2-7_BIT 7

#define TCNT2-7_MASK 128

OCR2 - Timer/Counter2 Output Compare Register

sfrb OCR2 = $23;

OCR2-0 - Timer/Counter2 Output Compare Register Bit 0

#define OCR2-0_BIT 0

#define OCR2-0_MASK 1

OCR2-1 - Timer/Counter2 Output Compare Register Bit 1

#define OCR2-1_BIT 1

#define OCR2-1_MASK 2

OCR2-2 - Timer/Counter2 Output Compare Register Bit 2

#define OCR2-2_BIT 2

#define OCR2-2_MASK 4

OCR2-3 - Timer/Counter2 Output Compare Register Bit 3

#define OCR2-3_BIT 3

#define OCR2-3_MASK 8

OCR2-4 - Timer/Counter2 Output Compare Register Bit 4

#define OCR2-4_BIT 4

#define OCR2-4_MASK 16

OCR2-5 - Timer/Counter2 Output Compare Register Bit 5

#define OCR2-5_BIT 5

#define OCR2-5_MASK 32

OCR2-6 - Timer/Counter2 Output Compare Register Bit 6

#define OCR2-6_BIT 6

#define OCR2-6_MASK 64

OCR2-7 - Timer/Counter2 Output Compare Register Bit 7

#define OCR2-7_BIT 7

#define OCR2-7_MASK 128

TIMER COUNTER 0

TCCR0 - Timer/Counter Control Register

sfrb TCCR0 = $33;

CS00 - Clock Select 1

#define CS00_BIT 0

#define CS00_MASK 1

The three clock select bits select the clock source to be used by the Timer/Counter,

CS01 - Clock Select 1

#define CS01_BIT 1

#define CS01_MASK 2

The three clock select bits select the clock source to be used by the Timer/Counter,

CS02 - Clock Select 2

#define CS02_BIT 2

#define CS02_MASK 4

The three clock select bits select the clock source to be used by the Timer/Counter,

CTC0 - CLear Timer/Counter on Compare Match

#define CTC0_BIT 3

#define CTC0_MASK 8

COM00 - Compare match Output Mode 0

#define COM00_BIT 4

#define COM00_MASK 16

These bits control the output compare pin (OC0) behavior. If one or both of the COM01:0 bits are set, the OC0 output over-rides the normal port functionality of the I/O pin it is connected to. However, note that the Data Direction Register (DDR) bit corresponding to OC0 pin must be set in order to enable the output driver. When OC0 is connected to the pin, the function of the COM01:0 bits depends on the WGM01:0 bit setting. Table 52 shows the COM01:0 bit functionality when the WGM01:0 bits are set to a normal or CTC mode (non-PWM)

COM01 - Compare Match Output Mode 1

#define COM01_BIT 5

#define COM01_MASK 32

These bits control the output compare pin (OC0) behavior. If one or both of the COM01:0 bits are set, the OC0 output over-rides the normal port functionality of the I/O pin it is connected to. However, note that the Data Direction Register (DDR) bit corresponding to OC0 pin must be set in order to enable the output driver. When OC0 is connected to the pin, the function of the COM01:0 bits depends on the WGM01:0 bit setting. Table 52 shows the COM01:0 bit functionality when the WGM01:0 bits are set to a normal or CTC mode (non-PWM)

PWM0 - Pulse Width Modulator Enable

#define PWM0_BIT 6

#define PWM0_MASK 64

Setting this bit to 1 will enable the Pulse Width Modulator for Timer/Counter 0.

TCNT0 - Timer/Counter Register

sfrb TCNT0 = $32;

TCNT0_0

#define TCNT0_0_BIT 0

#define TCNT0_0_MASK 1

TCNT0_1

#define TCNT0_1_BIT 1

#define TCNT0_1_MASK 2

TCNT0_2

#define TCNT0_2_BIT 2

#define TCNT0_2_MASK 4

TCNT0_3

#define TCNT0_3_BIT 3

#define TCNT0_3_MASK 8

TCNT0_4

#define TCNT0_4_BIT 4

#define TCNT0_4_MASK 16

TCNT0_5

#define TCNT0_5_BIT 5

#define TCNT0_5_MASK 32

TCNT0_6

#define TCNT0_6_BIT 6

#define TCNT0_6_MASK 64

TCNT0_7

#define TCNT0_7_BIT 7

#define TCNT0_7_MASK 128

OCR0 - Output Compare Register

sfrb OCR0 = $31;

OCR0_0

#define OCR0_0_BIT 0

#define OCR0_0_MASK 1

OCR0_1

#define OCR0_1_BIT 1

#define OCR0_1_MASK 2

OCR0_2

#define OCR0_2_BIT 2

#define OCR0_2_MASK 4

OCR0_3

#define OCR0_3_BIT 3

#define OCR0_3_MASK 8

OCR0_4

#define OCR0_4_BIT 4

#define OCR0_4_MASK 16

OCR0_5

#define OCR0_5_BIT 5

#define OCR0_5_MASK 32

OCR0_6

#define OCR0_6_BIT 6

#define OCR0_6_MASK 64

OCR0_7

#define OCR0_7_BIT 7

#define OCR0_7_MASK 128

ASSR - Asynchronus Status Register

sfrb ASSR = $30;

TCR0UB - Timer/Counter Control Register 0 Update Busy

#define TCR0UB_BIT 0

#define TCR0UB_MASK 1

When Timer/Counter0 operates asynchronously and TCCR0 is written, this bit becomes set. When TCCR0 has been updated from the temporary storage register, this bit is cleared by hardware. A logical zero in this bit indicates that TCCR0 is ready to be updated with a new value. If a write is performed to any of the three Timer/Counter0 registers while its update busy flag is set, the updated value might get corrupted and cause an unintentional interrupt to occur.The mechanisms for reading TCNT0, OCR0, and TCCR0 are different. When reading TCNT0, the actual timer value is read. When reading OCR0 or TCCR0, the value in the temporary storage register is read

OCR0UB - Output Compare register 0 Busy

#define OCR0UB_BIT 1

#define OCR0UB_MASK 2

When Timer/Counter0 operates asynchronously and OCR0 is written, this bit becomes set. When OCR0 has been updated from the temporary storage register, this bit is cleared by hardware. A logical zero in this bit indicates that OCR0 is ready to be updated with a new value.

TCN0UB - Timer/Couner0 Update Busy

#define TCN0UB_BIT 2

#define TCN0UB_MASK 4

When Timer/Counter0 operates asynchronously and TCNT0 is written, this bit becomes set. When TCNT0 has been updated from the temporary storage register, this bit is cleared by hardware. A logical zero in this bit indicates that TCNT0 is ready to be updated with a new value.

AS0 - Asynchronus Timer/Counter 0

#define AS0_BIT 3

#define AS0_MASK 8

When AS0 is cleared, Timer/Counter 0 is clocked from the I/O clock, clk I/O . When AS0 is set, Timer/Counter 0 is clocked from a crystal oscillator connected to the Timer Oscillator 1 (TOSC1) pin. When the value of AS0 is changed, the contents of TCNT0, OCR0, and TCCR0 might be corrupted.

TIMSK - Timer/Counter Interrupt Mask Register

sfrb TIMSK = $37;

TOIE0 - Timer/Counter0 Overflow Interrupt Enable

#define TOIE0_BIT 0

#define TOIE0_MASK 1

When the TOIE0 bit is written to one, and the I-bit in the Status Register is set (one), the Timer/Counter0 Overflow interrupt is enabled. The corresponding interrupt is executed if an overflow in Timer/Counter0 occurs, i.e. when the TOV0 bit is set in the Timer/Counter Interrupt Flag Register - TIFR.

OCIE0 - Timer/Counter0 Output Compare Match Interrupt register

#define OCIE0_BIT 1

#define OCIE0_MASK 2

When the OCIE0 bit is written to one, and the I-bit in the Status Register is set (one), the Timer/Counter0 Compare Match interrupt is enabled. The corresponding interrupt is executed if a compare match in Timer/Counter0 occurs, i.e. when the OCF0 bit is set in the Timer/Counter Interrupt Flag Register - TIFR.

TIFR - Timer/Counter Interrupt Flag register

sfrb TIFR = $36;

TOV0 - Timer/Counter0 Overflow Flag

#define TOV0_BIT 0

#define TOV0_MASK 1

The bit TOV0 is set (one) when an overflow occurs in Timer/Counter0. TOV0 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, TOIE0 (Timer/Counter0 Overflow Interrupt Enable), and TOV0 are set (one), the Timer/Counter0 Overflow interrupt is executed. In PWM mode, this bit is set when Timer/Counter0 changes counting direction at $00.

OCF0 - Output Compare Flag 0

#define OCF0_BIT 1

#define OCF0_MASK 2

The OCF0 bit is set (one) when a compare match occurs between the Timer/Counter0 and the data in OCR0 - Output Compare Register0. OCF0 is cleared by hardware when executing the corresponding interrupt handling vector. Alterna-tively, OCF0 is cleared by writing a logic one to the flag. When the I-bit in SREG, OCIE0 (Timer/Counter0 Compare match Interrupt Enable), and OCF0 are set (one), the Timer/Counter0 Compare match Interrupt is executed.

TIMER COUNTER 1

The 16-bit Timer/Counter1 can select clock source from CK, prescaled CK, or an external pin. In addition it can be stopped as described in the specification for the Timer/Counter1 Control Registers - TCCR1A and TCCR1B. The different status flags (overflow, compare match and capture event) are found in the Timer/Counter Interrupt Flag Register - TIFR. Control signals are found in the Timer/Counter1 Control Registers - TCCR1A and TCCR1B. The interrupt enable/disable settings for Timer/Counter1 are found in the Timer/Counter Interrupt Mask Register - TIMS

TIMSK - Timer/Counter Interrupt Mask Register

sfrb TIMSK = $37;

TOIE1 - Timer/Counter1 Overflow Interrupt Enable

#define TOIE1_BIT 2

#define TOIE1_MASK 4

When the TOIE1 bit is set (one) and the I-bit in the Status Register is set (one), the Timer/Counter1 Overflow interrupt is enabled. The corresponding interrupt (at vector $006) is executed if an overflow in Timer/Counter1 occurs, i.e., when the TOV1 bit is set in the Timer/Counter Interrupt Flag Register - TIFR.

OCIE1B - Timer/Counter1 Output CompareB Match Interrupt Enable

#define OCIE1B_BIT 3

#define OCIE1B_MASK 8

When the OCIE1B bit is set (one) and the I-bit in the Status Register is set (one), the Timer/Counter1 CompareB Match interrupt is enabled. The corresponding interrupt (at vector $005) is executed if a CompareB match in Timer/Counter1 occurs, i.e., when the OCF1B bit is set in the Timer/Counter Interrupt Flag Register - TIFR.

OCIE1A - Timer/Counter1 Output CompareA Match Interrupt Enable

#define OCIE1A_BIT 4

#define OCIE1A_MASK 16

When the OCIE1A bit is set (one) and the I-bit in the Status Register is set (one), the Timer/Counter1 CompareA Match interrupt is enabled. The corresponding interrupt (at vector $004) is executed if a CompareA match in Timer/Counter1 occurs, i.e., when the OCF1A bit is set in the Timer/Counter Interrupt Flag Register - TIFR.

TICIE1 - Timer/Counter1 Input Capture Interrupt Enable

#define TICIE1_BIT 5

#define TICIE1_MASK 32

When the TICIE1 bit is set (one) and the I-bit in the Status Register is set (one), the Timer/Counter1 Input Capture Event Interrupt is enabled. The corresponding interrupt (at vector $003) is executed if a capture-triggering event occurs on pin 31, ICP, i.e., when the ICF1 bit is set in the Timer/Counter Interrupt Flag Register - TIFR.

TIFR - Timer/Counter Interrupt Flag register

sfrb TIFR = $36;

TOV1 - Timer/Counter1 Overflow Flag

#define TOV1_BIT 2

#define TOV1_MASK 4

The TOV1 is set (one) when an overflow occurs in Timer/Counter1. TOV1 is cleared by hardware when executing the cor-responding interrupt handling vector. Alternatively, TOV1 is cleared by writing a logic one to the flag. When the I-bit in SREG, and TOIE1 (Timer/Counter1 Overflow Interrupt Enable), and TOV1 are set (one), the Timer/Counter1 Overflow Interrupt is executed. In PWM mode, this bit is set when Timer/Counter1 changes counting direction at $0000.

OCF1B - Output Compare Flag 1B

#define OCF1B_BIT 3

#define OCF1B_MASK 8

The OCF1B bit is set (one) when compare match occurs between the Timer/Counter1 and the data in OCR1B - Output Compare Register 1B. OCF1B is cleared by hardware when executing the corresponding interrupt handling vector. Alterna-tively, OCF1B is cleared by writing a logic one to the flag. When the I-bit in SREG, and OCIE1B (Timer/Counter1 Compare match InterruptB Enable), and the OCF1B are set (one), the Timer/Counter1 Compare B match Interrupt is executed.

OCF1A - Output Compare Flag 1A

#define OCF1A_BIT 4

#define OCF1A_MASK 16

The OCF1A bit is set (one) when compare match occurs between the Timer/Counter1 and the data in OCR1A - Output Compare Register 1A. OCF1A is cleared by hardware when executing the corresponding interrupt handling vector. Alterna-tively, OCF1A is cleared by writing a logic one to the flag. When the I-bit in SREG, and OCIE1A (Timer/Counter1 Compare match InterruptA Enable), and the OCF1A are set (one), the Timer/Counter1 Compare A match Interrupt is executed.

ICF1 - Input Capture Flag 1

#define ICF1_BIT 5

#define ICF1_MASK 32

The ICF1 bit is set (one) to flag an input capture event, indicating that the Timer/Counter1 value has been transferred to the input capture register - ICR1. ICF1 is cleared by hardware when executing the corresponding interrupt handling vector. Alternatively, ICF1 is cleared by writing a logic one to the flag. When the SREG I-bit, and TICIE1 (Timer/Counter1 Input Capture Interrupt Enable), and ICF1 are set (one), the Timer/Counter1 Capture Interrupt is executed.

TCCR1A - Timer/Counter1 Control Register A

sfrb TCCR1A = $2F;

PWM10 - Pulse Width Modulator Select Bit 0

#define PWM10_BIT 0

#define PWM10_MASK 1

PWM11 - Pulse Width Modulator Select Bit 1

#define PWM11_BIT 1

#define PWM11_MASK 2

COM1B0 - Compare Output Mode 1B, bit 0

#define COM1B0_BIT 4

#define COM1B0_MASK 16

The COM1B1 and COM1B0 control bits determine any output pin action following a compare match in Timer/Counter1. Any output pin actions affect pin OC1B - Output CompareB.

COM1B1 - Compare Output Mode 1B, bit 1

#define COM1B1_BIT 5

#define COM1B1_MASK 32

The COM1B1 and COM1B0 control bits determine any output pin action following a compare match in Timer/Counter1. Any output pin actions affect pin OC1B - Output CompareB.

COM1A0 - Compare Ouput Mode 1A, bit 0

#define COM1A0_BIT 6

#define COM1A0_MASK 64

The COM1A1 and COM1A0 control bits determine any output pin action following a compare match in Timer/Counter1. Any output pin actions affect pin OC1A - Output CompareA pin 1. This is an alternative function to an I/O port and the corresponding direction control bit must be set (one) to control the output pin. The control configuration is shown in Table 9.

COM1A1 - Compare Output Mode 1A, bit 1

#define COM1A1_BIT 7

#define COM1A1_MASK 128

The COM1A1 and COM1A0 control bits determine any output pin action following a compare match in Timer/Counter1. Any output pin actions affect pin OC1A - Output CompareA pin 1. This is an alternative function to an I/O port and the corresponding direction control bit must be set (one) to control the output pin. The control configuration is shown in Table 9.

TCCR1B - Timer/Counter1 Control Register B

sfrb TCCR1B = $2E;

CS10 - Clock Select1 bit 0

#define CS10_BIT 0

#define CS10_MASK 1

CS11 - Clock Select1 bit 1

#define CS11_BIT 1

#define CS11_MASK 2

CS12 - Clock Select1 bit 2

#define CS12_BIT 2

#define CS12_MASK 4

CTC1 - Clear Timer/Counter1 on Compare Match

#define CTC1_BIT 3

#define CTC1_MASK 8

When the CTC1 control bit is set (one), the Timer/Counter1 is reset to $0000 in the clock cycle after a compareA match. If the CTC1 control bit is cleared, Timer/Counter1 continues counting and is unaffected by a compare match. Since the compare match is detected in the CPU clock cycle following the match, this function will behave differently when a prescal-ing higher than 1 is used for the timer. When a prescaling of 1 is used, and the compareA register is set to C, the timer will count as follows if CTC1 is set: ...|C-2 |C-1 |C |0|1 |... When the prescaler is set to divide by 8, the timer will count like this: ... | C-2, C-2, C-2, C-2, C-2, C-2, C-2, C-2 | C-1, C-1, C-1, C-1, C-1, C-1, C-1, C-1 | C, 0, 0, 0, 0, 0, 0, 0 | ... In PWM mode, this bit has no effect

ICES1 - Input Capture 1 Edge Select

#define ICES1_BIT 6

#define ICES1_MASK 64

While the ICES1 bit is cleared (zero), the Timer/Counter1 contents are transferred to the Input Capture Register - ICR1 - on the falling edge of the input capture pin - ICP. While the ICES1 bit is set (one), the Timer/Counter1 contents are transferred to the Input Capture Register - ICR1 - on the rising edge of the input capture pin - ICP.

ICNC1 - Input Capture 1 Noise Canceler

#define ICNC1_BIT 7

#define ICNC1_MASK 128

When the ICNC1 bit is cleared (zero), the input capture trigger noise canceler function is disabled. The input capture is triggered at the first rising/falling edge sampled on the ICP - input capture pin - as specified. When the ICNC1 bit is set (one), four successive samples are measures on the ICP - input capture pin, and all samples must be high/low according to the input capture trigger specification in the ICES1 bit. The actual sampling frequency is XTAL clock frequency.

TCNT1H - Timer/Counter1 High Byte

sfrb TCNT1H = $2D;

TCNT1H0 - Timer/Counter1 High Byte bit 0

#define TCNT1H0_BIT 0

#define TCNT1H0_MASK 1

TCNT1H1 - Timer/Counter1 High Byte bit 1

#define TCNT1H1_BIT 1

#define TCNT1H1_MASK 2

TCNT1H2 - Timer/Counter1 High Byte bit 2

#define TCNT1H2_BIT 2

#define TCNT1H2_MASK 4

TCNT1H3 - Timer/Counter1 High Byte bit 3

#define TCNT1H3_BIT 3

#define TCNT1H3_MASK 8

TCNT1H4 - Timer/Counter1 High Byte bit 4

#define TCNT1H4_BIT 4

#define TCNT1H4_MASK 16

TCNT1H5 - Timer/Counter1 High Byte bit 5

#define TCNT1H5_BIT 5

#define TCNT1H5_MASK 32

TCNT1H6 - Timer/Counter1 High Byte bit 6

#define TCNT1H6_BIT 6

#define TCNT1H6_MASK 64

TCNT1H7 - Timer/Counter1 High Byte bit 7

#define TCNT1H7_BIT 7

#define TCNT1H7_MASK 128

TCNT1L - Timer/Counter1 Low Byte

sfrb TCNT1L = $2C;

TCNT1L0 - Timer/Counter1 Low Byte bit 0

#define TCNT1L0_BIT 0

#define TCNT1L0_MASK 1

TCNT1L1 - Timer/Counter1 Low Byte bit 1

#define TCNT1L1_BIT 1

#define TCNT1L1_MASK 2

TCNT1L2 - Timer/Counter1 Low Byte bit 2

#define TCNT1L2_BIT 2

#define TCNT1L2_MASK 4

TCNT1L3 - Timer/Counter1 Low Byte bit 3

#define TCNT1L3_BIT 3

#define TCNT1L3_MASK 8

TCNT1L4 - Timer/Counter1 Low Byte bit 4

#define TCNT1L4_BIT 4

#define TCNT1L4_MASK 16

TCNT1L5 - Timer/Counter1 Low Byte bit 5

#define TCNT1L5_BIT 5

#define TCNT1L5_MASK 32

TCNT1L6 - Timer/Counter1 Low Byte bit 6

#define TCNT1L6_BIT 6

#define TCNT1L6_MASK 64

TCNT1L7 - Timer/Counter1 Low Byte bit 7

#define TCNT1L7_BIT 7

#define TCNT1L7_MASK 128

OCR1AH - Timer/Counter1 Outbut Compare Register High Byte

sfrb OCR1AH = $2B;

OCR1AH0 - Timer/Counter1 Outbut Compare Register High Byte bit 0

#define OCR1AH0_BIT 0

#define OCR1AH0_MASK 1

OCR1AH1 - Timer/Counter1 Outbut Compare Register High Byte bit 1

#define OCR1AH1_BIT 1

#define OCR1AH1_MASK 2

OCR1AH2 - Timer/Counter1 Outbut Compare Register High Byte bit 2

#define OCR1AH2_BIT 2

#define OCR1AH2_MASK 4

OCR1AH3 - Timer/Counter1 Outbut Compare Register High Byte bit 3

#define OCR1AH3_BIT 3

#define OCR1AH3_MASK 8

OCR1AH4 - Timer/Counter1 Outbut Compare Register High Byte bit 4

#define OCR1AH4_BIT 4

#define OCR1AH4_MASK 16

OCR1AH5 - Timer/Counter1 Outbut Compare Register High Byte bit 5

#define OCR1AH5_BIT 5

#define OCR1AH5_MASK 32

OCR1AH6 - Timer/Counter1 Outbut Compare Register High Byte bit 6

#define OCR1AH6_BIT 6

#define OCR1AH6_MASK 64

OCR1AH7 - Timer/Counter1 Outbut Compare Register High Byte bit 7

#define OCR1AH7_BIT 7

#define OCR1AH7_MASK 128

OCR1AL - Timer/Counter1 Output Compare Register Low Byte

sfrb OCR1AL = $2A;

OCR1AL0 - Timer/Counter1 Output Compare Register Low Byte Bit 0

#define OCR1AL0_BIT 0

#define OCR1AL0_MASK 1

OCR1AL1 - Timer/Counter1 Output Compare Register Low Byte Bit 1

#define OCR1AL1_BIT 1

#define OCR1AL1_MASK 2

OCR1AL2 - Timer/Counter1 Output Compare Register Low Byte Bit 2

#define OCR1AL2_BIT 2

#define OCR1AL2_MASK 4

OCR1AL3 - Timer/Counter1 Output Compare Register Low Byte Bit 3

#define OCR1AL3_BIT 3

#define OCR1AL3_MASK 8

OCR1AL4 - Timer/Counter1 Output Compare Register Low Byte Bit 4

#define OCR1AL4_BIT 4

#define OCR1AL4_MASK 16

OCR1AL5 - Timer/Counter1 Output Compare Register Low Byte Bit 5

#define OCR1AL5_BIT 5

#define OCR1AL5_MASK 32

OCR1AL6 - Timer/Counter1 Output Compare Register Low Byte Bit 6

#define OCR1AL6_BIT 6

#define OCR1AL6_MASK 64

OCR1AL7 - Timer/Counter1 Output Compare Register Low Byte Bit 7

#define OCR1AL7_BIT 7

#define OCR1AL7_MASK 128

OCR1BH - Timer/Counter1 Output Compare Register High Byte

sfrb OCR1BH = $29;

OCR1BH0 - Timer/Counter1 Output Compare Register High Byte bit 0

#define OCR1BH0_BIT 0

#define OCR1BH0_MASK 1

OCR1BH1 - Timer/Counter1 Output Compare Register High Byte bit 1

#define OCR1BH1_BIT 1

#define OCR1BH1_MASK 2

OCR1BH2 - Timer/Counter1 Output Compare Register High Byte bit 2

#define OCR1BH2_BIT 2

#define OCR1BH2_MASK 4

OCR1BH3 - Timer/Counter1 Output Compare Register High Byte bit 3

#define OCR1BH3_BIT 3

#define OCR1BH3_MASK 8

OCR1BH4 - Timer/Counter1 Output Compare Register High Byte bit 4

#define OCR1BH4_BIT 4

#define OCR1BH4_MASK 16

OCR1BH5 - Timer/Counter1 Output Compare Register High Byte bit 5

#define OCR1BH5_BIT 5

#define OCR1BH5_MASK 32

OCR1BH6 - Timer/Counter1 Output Compare Register High Byte bit 6

#define OCR1BH6_BIT 6

#define OCR1BH6_MASK 64

OCR1BH7 - Timer/Counter1 Output Compare Register High Byte bit 7

#define OCR1BH7_BIT 7

#define OCR1BH7_MASK 128

OCR1BL - Timer/Counter1 Output Compare Register Low Byte

sfrb OCR1BL = $28;

OCR1BL0 - Timer/Counter1 Output Compare Register Low Byte bit 0

#define OCR1BL0_BIT 0

#define OCR1BL0_MASK 1

OCR1BL1 - Timer/Counter1 Output Compare Register Low Byte bit 1

#define OCR1BL1_BIT 1

#define OCR1BL1_MASK 2

OCR1BL2 - Timer/Counter1 Output Compare Register Low Byte bit 2

#define OCR1BL2_BIT 2

#define OCR1BL2_MASK 4

OCR1BL3 - Timer/Counter1 Output Compare Register Low Byte bit 3

#define OCR1BL3_BIT 3

#define OCR1BL3_MASK 8

OCR1BL4 - Timer/Counter1 Output Compare Register Low Byte bit 4

#define OCR1BL4_BIT 4

#define OCR1BL4_MASK 16

OCR1BL5 - Timer/Counter1 Output Compare Register Low Byte bit 5

#define OCR1BL5_BIT 5

#define OCR1BL5_MASK 32

OCR1BL6 - Timer/Counter1 Output Compare Register Low Byte bit 6

#define OCR1BL6_BIT 6

#define OCR1BL6_MASK 64

OCR1BL7 - Timer/Counter1 Output Compare Register Low Byte bit 7

#define OCR1BL7_BIT 7

#define OCR1BL7_MASK 128

ICR1H - Timer/Counter1 Input Capture Register High Byte

sfrb ICR1H = $27;

ICR1H0 - Timer/Counter1 Input Capture Register High Byte bit 0

#define ICR1H0_BIT 0

#define ICR1H0_MASK 1

ICR1H1 - Timer/Counter1 Input Capture Register High Byte bit 1

#define ICR1H1_BIT 1

#define ICR1H1_MASK 2

ICR1H2 - Timer/Counter1 Input Capture Register High Byte bit 2

#define ICR1H2_BIT 2

#define ICR1H2_MASK 4

ICR1H3 - Timer/Counter1 Input Capture Register High Byte bit 3

#define ICR1H3_BIT 3

#define ICR1H3_MASK 8

ICR1H4 - Timer/Counter1 Input Capture Register High Byte bit 4

#define ICR1H4_BIT 4

#define ICR1H4_MASK 16

ICR1H5 - Timer/Counter1 Input Capture Register High Byte bit 5

#define ICR1H5_BIT 5

#define ICR1H5_MASK 32

ICR1H6 - Timer/Counter1 Input Capture Register High Byte bit 6

#define ICR1H6_BIT 6

#define ICR1H6_MASK 64

ICR1H7 - Timer/Counter1 Input Capture Register High Byte bit 7

#define ICR1H7_BIT 7

#define ICR1H7_MASK 128

ICR1L - Timer/Counter1 Input Capture Register Low Byte

sfrb ICR1L = $26;

ICR1L0 - Timer/Counter1 Input Capture Register Low Byte bit 0

#define ICR1L0_BIT 0

#define ICR1L0_MASK 1

ICR1L1 - Timer/Counter1 Input Capture Register Low Byte bit 1

#define ICR1L1_BIT 1

#define ICR1L1_MASK 2

ICR1L2 - Timer/Counter1 Input Capture Register Low Byte bit 2

#define ICR1L2_BIT 2

#define ICR1L2_MASK 4

ICR1L3 - Timer/Counter1 Input Capture Register Low Byte bit 3

#define ICR1L3_BIT 3

#define ICR1L3_MASK 8

ICR1L4 - Timer/Counter1 Input Capture Register Low Byte bit 4

#define ICR1L4_BIT 4

#define ICR1L4_MASK 16

ICR1L5 - Timer/Counter1 Input Capture Register Low Byte bit 5

#define ICR1L5_BIT 5

#define ICR1L5_MASK 32

ICR1L6 - Timer/Counter1 Input Capture Register Low Byte bit 6

#define ICR1L6_BIT 6

#define ICR1L6_MASK 64

ICR1L7 - Timer/Counter1 Input Capture Register Low Byte bit 7

#define ICR1L7_BIT 7

#define ICR1L7_MASK 128

WATCHDOG

WDTCR - Watchdog Timer Control Register

sfrb WDTCR = $21;

WDP0 - Watch Dog Timer Prescaler bit 0

#define WDP0_BIT 0

#define WDP0_MASK 1

WDP1 - Watch Dog Timer Prescaler bit 1

#define WDP1_BIT 1

#define WDP1_MASK 2

WDP2 - Watch Dog Timer Prescaler bit 2

#define WDP2_BIT 2

#define WDP2_MASK 4

WDE - Watch Dog Enable

#define WDE_BIT 3

#define WDE_MASK 8

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

WDTOE - RW

#define WDTOE_BIT 4

#define WDTOE_MASK 16

This bit must be set (one) when the WDE bit is cleared. Otherwise, the watchdog will not be disabled. Once set, hardware will clear this bit to zero after four clock cycles. Refer to the description of the WDE bit for a watchdog disable procedure.