Rainbow-electronics ATmega8HVD Bedienungsanleitung Seite 85

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 168
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 84
85
8052B–AVR–09/08
ATmega4HVD/8HVD
The following code examples show how to do an atomic write of the TCNTnH/L register con-
tents. Writing any of the OCRnA/B registers can be done by using the same principle.
Note: See ”About Code Examples” on page 5.
The assembly code example requires that the r17:r16 register pair contains the value to be
written to TCNTnH/L.
16.9.1 Reusing the temporary high byte register
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.
Assembly Code Example
TIMn_WriteTCNTn:
; Save global interrupt flag
in r18,SREG
; Disable interrupts
cli
; Set TCNTn to r17:r16
out TCNTnH,r17
out TCNTnL,r16
; Restore global interrupt flag
out SREG,r18
ret
C Code Example
void TIMn_WriteTCNTn( unsigned int i )
{
unsigned char sreg;
unsigned int i;
/* Save global interrupt flag */
sreg = SREG;
/* Disable interrupts */
_CLI();
/* Set TCNTn to i */
TCNTn = i;
/* Restore global interrupt flag */
SREG = sreg;
}
Seitenansicht 84
1 2 ... 80 81 82 83 84 85 86 87 88 89 90 ... 167 168

Kommentare zu diesen Handbüchern

Keine Kommentare