ATMEGA16-16AU SL602 Atmel, ATMEGA16-16AU SL602 Datasheet - Page 94

no-image

ATMEGA16-16AU SL602

Manufacturer Part Number
ATMEGA16-16AU SL602
Description
Manufacturer
Atmel
Datasheet
Reusing the
Temporary High Byte
Register
Timer/Counter
Clock Sources
2466T–AVR–07/10
The following code examples show how to do an atomic write of the TCNT1 Register contents.
Writing any of the OCR1A/B or ICR1 Registers can be done by using the same principle.
Note:
The assembly code example requires that the r17:r16 register pair contains the value to be writ-
ten to TCNT1.
If writing to more than one 16-bit register where the High byte is the same for all registers writ-
ten, then the High byte only needs to be written once. However, note that the same rule of
atomic operation described previously also applies in this case.
The Timer/Counter can be clocked by an internal or an external clock source. The clock source
is selected by the Clock Select logic which is controlled by the Clock Select (CS12:0) bits
located in the Timer/Counter Control Register B (TCCR1B). For details on clock sources and
prescaler, see
Assembly Code Example
C Code Example
TIM16_WriteTCNT1:
void TIM16_WriteTCNT1 ( unsigned int i )
{
}
; Save global interrupt flag
in
; Disable interrupts
cli
; Set TCNT1 to r17:r16
out TCNT1H,r17
out TCNT1L,r16
; Restore global interrupt flag
out SREG,r18
ret
unsigned char sreg;
unsigned int i;
/* Save global interrupt flag */
sreg = SREG;
/* Disable interrupts */
_CLI();
/* Set TCNT1 to i */
TCNT1 = i;
/* Restore global interrupt flag */
SREG = sreg;
1. See “About Code Examples” on page 7.
r18,SREG
“Timer/Counter0 and Timer/Counter1 Prescalers” on page
(1)
(1)
ATmega16(L)
87.
94

Related parts for ATMEGA16-16AU SL602