1 //***************************************************************************
\r
3 // File........: timer0.c
\r
5 // Author(s)...: ATMEL Norway
\r
7 // Target(s)...: ATmega169
\r
9 // Compiler....: AVR-GCC 4.1.1; avr-libc 1.4.5
\r
11 // Description.: AVR Butterfly Timer0 routines
\r
13 // Revisions...: 1.0
\r
15 // YYYYMMDD - VER. - COMMENT - SIGN.
\r
17 // 20030116 - 1.0 - Created - KS
\r
18 // 20031009 port to avr-gcc/avr-libc - M.Thomas
\r
19 // 20070129 SIGNAL->ISR - mt
\r
21 //***************************************************************************
\r
24 //#include <inavr.h>
\r
25 //#include "iom169.h"
\r
28 #include <avr/interrupt.h>
\r
35 //TIMER_CALLBACK_FUNC CallbackFunc[TIMER0_NUM_CALLBACKS];
\r
37 // Value definition:
\r
38 // 0 The timer has expired
\r
39 // 1-254 The timer is counting down
\r
42 // mt char CountDownTimers[TIMER0_NUM_COUNTDOWNTIMERS];
\r
43 //uint8_t CountDownTimers[TIMER0_NUM_COUNTDOWNTIMERS];
\r
45 /*****************************************************************************
\r
47 * Function name : Timer0_Init
\r
53 * Purpose : Initialize Timer/Counter 0
\r
55 *****************************************************************************/
\r
56 void Timer0_Init(void)
\r
62 // Initialize array of callback functions
\r
63 //for (i=0; i<TIMER0_NUM_CALLBACKS; i++)
\r
64 // CallbackFunc[i] = NULL;
\r
66 // Initialize countdown timers
\r
67 //for (i=0; i<TIMER0_NUM_COUNTDOWNTIMERS; i++)
\r
68 // CountDownTimers[i] = 255;
\r
71 // Initialize Timer0.
\r
72 // Used to give the correct time-delays in the song
\r
74 // Enable timer0 compare interrupt
\r
75 TIMSK0 = (1<<OCIE0A);
\r
77 // Sets the compare value
\r
80 // Set Clear on Timer Compare (CTC) mode, CLK/256 prescaler
\r
81 TCCR0A = (1<<WGM01)|(0<<WGM00)|(4<<CS00);
\r
86 /*****************************************************************************
\r
88 * Function name : TIMER0_COMP_interrupt
\r
94 * Purpose : Check if any functions are to be called
\r
96 *****************************************************************************/
\r
98 // #pragma vector = TIMER0_COMP_vect
\r
99 // __interrupt void TIMER0_COMP_interrupt(void)
\r
100 // SIGNAL(SIG_OUTPUT_COMPARE0)
\r
101 ISR(TIMER0_COMP_vect)
\r
104 setup.elapsed_time += 1;
\r