#include #include #include #include // GLOBAL VARIABLES volatile unsigned int seconds = 3000; // MAIN int main (void) { wdt_disable(); // disable watchdog // port initialization DDRB = 0xFF; // portb = output PORTB = 0xFF; // all leds off DDRC = 0x00; // portd = input PINC = 0xFF; // all buttons off // button interrupt initialization PCICR |= (1 << PCIE1); // enable PORTC interrupts PCMSK1 |= 0x3F; // enable PCINT8 - PCINT13 sei(); // enable global interrupts // SLEEP sleep_enable(); // enable sleep set_sleep_mode(SLEEP_MODE_PWR_DOWN); sleep_mode(); cli(); // disable global interrupts // START BUTTON while(PINC & (1 << 1)); PORTB = 0x00; // timer interrupt initialization // count = (1 / target freq) / (prescale / frequency) TCCR1B |= (1 << CS12); // prescale = 256 TCCR1B |= (1 << WGM12); // enable clear on timer compare TIMSK1 |= (1 << OCIE1A); // output compare A match interrupt enabled OCR1A = 31250; // compare value A. 31250 equals 1Hz at 8Mhz with prescaler at 256 // watchdog timer initialization wdt_enable(WDTO_8S); // watchdog timeout = 8 seconds WDTCSR |= (1 << WDE); // timeout action = reset sei(); // reenable global interrupts while(1); } // TIMER INTERRUPT ISR(TIMER1_COMPA_vect) { //PORTB = ~(seconds % 60); // seconds PORTB = ~(seconds / 60); // minutes // conditional prevents underflow if(seconds > 0) { seconds--; wdt_reset(); // kick the dog } else { PORTB = 0x00; // toggle all leds PRR |= (1 << PRTIM1); // power reduction timer/counter1 (turn off timer) } } // BUTTON INTERRUPT ISR(PCINT1_vect) { PORTB = PINC; }