118
7679H–CAN–08/08
AT90CAN32/64/128
The following code examples show how to do an atomic read of the TCNTn Register contents.
Reading any of the OCRnx or ICRn Registers can be done by using the same principle.
Note:
1. The example code assumes that the part specific header file is included.
The assembly code example returns the TCNTn value in the r17:r16 register pair.
Assembly Code Example
TIM16_ReadTCNTn:
;
Save global interrupt flag
in
r18,SREG
;
Disable interrupts
cli
; Read TCNTn into r17:r16
lds
r16,TCNTnL
lds
r17,TCNTnH
;
Restore global interrupt flag
out
SREG,r18
ret
C Code Example
unsigned int
TIM16_ReadTCNTn(
void
)
{
unsigned char
sreg;
unsigned int
i;
/*
Save global interrupt flag
*/
sreg = SREG;
/*
Disable interrupts
*/
_CLI();
/*
Read TCNTn into i
*/
i = TCNTn;
/*
Restore global interrupt flag
*/
SREG = sreg;
return
i;
}
Содержание AVR AT90CAN128
Страница 414: ...414 7679H CAN 08 08 AT90CAN32 64 128 32 2 QFN64...
Страница 415: ...415 7679H CAN 08 08 AT90CAN32 64 128...