Skip to content

Instantly share code, notes, and snippets.

@jiahuang
Created November 30, 2012 05:55
Show Gist options
  • Save jiahuang/4173993 to your computer and use it in GitHub Desktop.
Save jiahuang/4173993 to your computer and use it in GitHub Desktop.
ATTiny watchdog setting
uint8_t watchdog_count = 0;
ISR(WDT_vect) {
// This vector is for the watchdog timer
PORTA = PORTA | (1 << LED ); // The LED never goes on
++watchdog_count;
}
ISR(PCINT0_vect)
{
//This vector is only here to wake unit up from sleep mode
}
int main() {
while (1) {
PORTA = PORTA & ~(1<<LED );
ACSR = (1<<ACD); //Turn off Analog Comparator
PRR = 0x0F; //Reduce all power right before sleep
asm volatile ("sleep");
}
return 0;
}
void setup_watchdog() {
TCCR0B = (1<<CS01); // Set Prescaler to 8
GIFR = (1<<PCIF0); //Enable the Pin Change interrupts to monitor button presses
GIMSK = (1<<PCIE0); //Enable Pin Change Interrupt Request
PCMSK0 = (1<< BUTTON);
MCUCR = (1<<SM1)|(1<<SE); //Setup Power-down mode and enable sleep
MCUSR &= ~(1<<WDRF); // clear the watchdog reset
// set up watchdog timer
WDTCSR |= (1 << WDCE ) | ( 1 << WDE );
WDTCSR |= (1 << WDIE );
WDTCSR |= (1 << WDP3) | (1 << WDP0); // timer goes off every 8 seconds
sei(); //Enable interrupts
}
@droneshire
Copy link

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment