Rainbow-electronics ATmega8HVD User Manual Page 84

  • Download
  • Add to my manuals
  • Print
  • Page
    / 168
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 83
84
8052B–AVR–09/08
ATmega4HVD/8HVD
The following code examples show how to do an atomic read of the TCNTn register contents.
Reading any of the OCRn register can be done by using the same principle.
Note: 1. See ”About Code Examples” on page 5.
The assembly code example returns the TCNTnH/L value in the r17:r16 register pair.
Assembly Code Example
TIMn_ReadTCNTn:
; Save global interrupt flag
in r18,SREG
; Disable interrupts
cli
; Read TCNTn into r17:r16
in r16,TCNTnL
in r17,TCNTnH
; Restore global interrupt flag
out SREG,r18
ret
C Code Example
unsigned int TIMn_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;
}
Page view 83
1 2 ... 79 80 81 82 83 84 85 86 87 88 89 ... 167 168

Comments to this Manuals

No comments