Rainbow-electronics ATmega8515L Manual de usuario Pagina 99

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 223
  • Tabla de contenidos
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 98
99
ATmega8515(L)
2512A–AVR–04/02
The following codeexamplesshowhow to doanatomicwrite of theTCNT1 Register
contents. Writing any of the OCR1A/B orICR1 Registers can be done by using the
same principle.
Note: 1. Theexample codeassumes that the part specificheaderfileis included.
Theassembly codeexample requires that the r17:r16registerpaircontains thevalue to
be written to TCNT1.
Reusing the Temporary High
Byte Register
If writing to morethan one 16-bit registerwherethe highbyte is the same for all registers
written, then the highbyte only needs to be written once. However, note that the same
ruleof atomic operation describedpreviously alsoapplies in thiscase.
Assembly Code Example
(1)
TIM16_WriteTCNT1:
;
Save global interrupt flag
in r18,SREG
;
Disable interrupts
cli
;
Set TCNT
1
to
r17:r16
out TCNT
1H,r17
out TCNT
1L,r16
;
Restore global interrupt flag
out SREG,r18
ret
CCode Example
(1)
void TIM16_WriteTCNT1( unsigned int i )
{
unsigned char sreg;
unsigned int i;
/*
Save global interrupt flag
*/
sreg = SREG;
/*
Disable interrupts
*/
_CLI();
/*
Set TCNT
1
to i
*/
TCNT
1 =i;
/*
Restore global interrupt flag
*/
SREG = sreg;
}
Vista de pagina 98
1 2 ... 94 95 96 97 98 99 100 101 102 103 104 ... 222 223

Comentarios a estos manuales

Sin comentarios