Subversion Repositories Projects

Rev

Rev 231 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 231 Rev 271
Line 3... Line 3...
3
#include <avr/interrupt.h>
3
#include <avr/interrupt.h>
Line 4... Line 4...
4
 
4
 
Line 5... Line 5...
5
#include "main.h"
5
#include "main.h"
-
 
6
 
-
 
7
volatile uint16_t CountMilliseconds = 0;
-
 
8
#ifdef USE_FOLLOWME
6
 
9
volatile uint16_t BeepTime = 0;
Line 7... Line 10...
7
volatile uint16_t CountMilliseconds = 0;
10
volatile uint16_t BeepModulation = 0xFFFF;
8
 
11
#endif
9
 
12
 
Line 18... Line 21...
18
        uint8_t sreg = SREG;
21
        uint8_t sreg = SREG;
Line 19... Line 22...
19
 
22
 
20
        // disable all interrupts before reconfiguration
23
        // disable all interrupts before reconfiguration
Line -... Line 24...
-
 
24
        cli();
-
 
25
 
-
 
26
 
-
 
27
        // configure speaker port as output
-
 
28
 
-
 
29
        #ifdef USE_FOLLOWME
-
 
30
        // Speaker at PC7
-
 
31
        DDRC |= (1<<DDC7);
-
 
32
        PORTC &= ~(1<<PORTC7);
21
        cli();
33
        #endif
Line 22... Line 34...
22
 
34
 
23
        // Timer/Counter 0 Control Register A
35
        // Timer/Counter 0 Control Register A
24
 
36
 
Line 59... Line 71...
59
/*          Interrupt Routine of Timer 0             */
71
/*          Interrupt Routine of Timer 0             */
60
/*****************************************************/
72
/*****************************************************/
61
ISR(TIMER0_OVF_vect)    // 9.765 kHz
73
ISR(TIMER0_OVF_vect)    // 9.765 kHz
62
{
74
{
63
    static uint8_t cnt = 0;
75
    static uint8_t cnt = 0;
-
 
76
    #ifdef USE_FOLLOWME
-
 
77
    uint8_t Beeper_On = 0;
-
 
78
        #endif
Line 64... Line 79...
64
 
79
 
65
        if(!cnt--) // every 10th run (9.765kHz/10 = 976Hz)
80
        if(!cnt--) // every 10th run (9.765kHz/10 = 976Hz)
66
        {
81
        {
67
                cnt = 9;
82
                cnt = 9;
68
                CountMilliseconds++; // increment millisecond counter
83
                CountMilliseconds++; // increment millisecond counter
-
 
84
        }
-
 
85
 
-
 
86
         #ifdef USE_FOLLOWME
-
 
87
        // beeper on if duration is not over
-
 
88
        if(BeepTime)
-
 
89
        {
-
 
90
                BeepTime--; // decrement BeepTime
-
 
91
                if(BeepTime & BeepModulation) Beeper_On = 1;
-
 
92
                else Beeper_On = 0;
-
 
93
        }
-
 
94
        else // beeper off if duration is over
-
 
95
        {
-
 
96
                Beeper_On = 0;
-
 
97
                BeepModulation = 0xFFFF;
-
 
98
        }
-
 
99
 
-
 
100
        // if beeper is on
-
 
101
        if(Beeper_On)
-
 
102
        {
-
 
103
                // set speaker port to high
-
 
104
                PORTC |= (1<<PORTC7); // Speaker at PC7
-
 
105
        }
-
 
106
        else // beeper is off
-
 
107
        {
-
 
108
                // set speaker port to low
-
 
109
                PORTC &= ~(1<<PORTC7);// Speaker at PC7
-
 
110
        }
69
        }
111
        #endif
Line 70... Line 112...
70
}
112
}
71
 
113