Getting Started

(lily) #1

Chapter 7: Microcontroller Interrupts and Timers


:

;
0xFF;

reach the count

R2 && (1<<OCF2A)) );

er:

set our temp variable to 0xFFFF.

if ( (TIFR1 && (1<<TOV1)) )
{
FF

temp = (temp << 8);

Disable global interrupts:


cli();

Clear the timer interrupt flags


TIFR1 = 0xFF
TIFR2 =

Clear the timer counts:


TCNT1H = 0;
TCNT1L = 0;
TCNT2 = 0;

Wait for the timer to


while ( !(TIF

Stop the tim


TCCR1B = 0;

Enable global interrupts


sei();

Has Timer/Counter1 overflowed? If so


temp = 0xFFFF;//if timer1 overflows, set the temp to 0xFF
}

Otherwise read the timer1 counter value into the temp variable


else
{
tempL = TCNT1L;
temp = TCNT1H;

Free download pdf