attiny261a-xu ATMEL Corporation, attiny261a-xu Datasheet - Page 108

no-image

attiny261a-xu

Manufacturer Part Number
attiny261a-xu
Description
8-bit Avr Microcontroller With 2/4/8k Bytes In-system Programmable Flash
Manufacturer
ATMEL Corporation
Datasheet

Available stocks

Company
Part Number
Manufacturer
Quantity
Price
Part Number:
attiny261a-xuR
Manufacturer:
Atmel
Quantity:
5 990
108
ATtiny261A/461A/861A
The following code examples show how to do an atomic read of the TCNT1 register contents.
Reading any of the OCR1A/B/C/D registers can be done by using the same principle.
Note:
The assembly code example returns the TCNT1 value in the r17:r16 register pair.
Assembly Code Example
TIM1_ReadTCNT1:
C Code Example
unsigned int TIM1_ReadTCNT1( void )
{
}
; Save global interrupt flag
in r18,SREG
; Disable interrupts
cli
; Read TCNT1 into r17:r16
in r16,TCNT1
in r17,TC1H
; Restore global interrupt flag
out SREG,r18
ret
unsigned char sreg;
unsigned int i;
/* Save global interrupt flag */
sreg = SREG;
/* Disable interrupts */
_CLI();
/* Read TCNT1 into i */
i = TCNT1;
i |= ((unsigned int)TC1H << 8);
/* Restore global interrupt flag
SREG = sreg;
return i;
See
“Code Examples” on page
6.
8197B–AVR–01/10

Related parts for attiny261a-xu