5,9 → 5,12 |
#include "main.h" |
|
volatile uint16_t CountMilliseconds = 0; |
#ifdef USE_FOLLOWME |
volatile uint16_t BeepTime = 0; |
volatile uint16_t BeepModulation = 0xFFFF; |
#endif |
|
|
|
/*****************************************************/ |
/* Initialize Timer 0 */ |
/*****************************************************/ |
20,6 → 23,15 |
// disable all interrupts before reconfiguration |
cli(); |
|
|
// configure speaker port as output |
|
#ifdef USE_FOLLOWME |
// Speaker at PC7 |
DDRC |= (1<<DDC7); |
PORTC &= ~(1<<PORTC7); |
#endif |
|
// Timer/Counter 0 Control Register A |
|
// Waveform Generation Mode is Fast PWM (Bits WGM02 = 0, WGM01 = 1, WGM00 = 1) |
61,6 → 73,9 |
ISR(TIMER0_OVF_vect) // 9.765 kHz |
{ |
static uint8_t cnt = 0; |
#ifdef USE_FOLLOWME |
uint8_t Beeper_On = 0; |
#endif |
|
if(!cnt--) // every 10th run (9.765kHz/10 = 976Hz) |
{ |
67,6 → 82,33 |
cnt = 9; |
CountMilliseconds++; // increment millisecond counter |
} |
|
#ifdef USE_FOLLOWME |
// beeper on if duration is not over |
if(BeepTime) |
{ |
BeepTime--; // decrement BeepTime |
if(BeepTime & BeepModulation) Beeper_On = 1; |
else Beeper_On = 0; |
} |
else // beeper off if duration is over |
{ |
Beeper_On = 0; |
BeepModulation = 0xFFFF; |
} |
|
// if beeper is on |
if(Beeper_On) |
{ |
// set speaker port to high |
PORTC |= (1<<PORTC7); // Speaker at PC7 |
} |
else // beeper is off |
{ |
// set speaker port to low |
PORTC &= ~(1<<PORTC7);// Speaker at PC7 |
} |
#endif |
} |
|
|