#include #include #include static uint32_t seconds; uint32_t getSeconds() { ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { return seconds; } } // EMPTY_INTERRUPT(TIMER2_OVF_vect); ISR(TIMER2_OVF_vect) { seconds++; } int main() { set_sleep_mode(SLEEP_MODE_PWR_SAVE); // set_sleep_mode(SLEEP_MODE_PWR_DOWN); // async TIMSK2 = 0; ASSR = _BV(AS2); // Prescaler 1024 // TCCR2B = _BV(CS22) | _BV(CS21) | _BV(CS20); // Prescaler 128 TCCR2B = _BV(CS22) | _BV(CS20); TCCR2A = 0; // Wait until OSC is running while (ASSR != _BV(AS2)) { } // clear interrupt flags TIFR2 = (1 << TOV2); // Enable only Overflow TIMSK2 = _BV(TOIE2); DDRB |= _BV(PB5); sei(); while (true) { sleep_mode(); PINB |= _BV(PB5); } return 0; }