#include "MsTimer2.h" unsigned long MsTimer2::msecs; void (*MsTimer2::func)(); volatile unsigned long MsTimer2::count; volatile char MsTimer2::overflowing; volatile unsigned int MsTimer2::tcnt2; void MsTimer2::set(unsigned long ms, void (*f)()) { float prescaler = 0.0; #if defined (__AVR_ATmega168__) || defined (__AVR_ATmega48__) || defined (__AVR_ATmega88__) || defined (__AVR_ATmega328P__) || (__AVR_ATmega1280__) TIMSK2 &= ~(1<= 1000000UL) && (F_CPU <= 16000000UL)) { TCCR2B |= (1<= 1000000UL) && (F_CPU <= 16000000UL)) { TCCR2 |= (1<= 1000000UL) && (F_CPU <= 16000000UL)) { TCCR2 |= ((1<= msecs && !overflowing) { overflowing = 1; count = 0; (*func)(); overflowing = 0; } } ISR(TIMER2_OVF_vect) { #if defined (__AVR_ATmega168__) || defined (__AVR_ATmega48__) || defined (__AVR_ATmega88__) || defined (__AVR_ATmega328P__) || (__AVR_ATmega1280__) TCNT2 = MsTimer2::tcnt2; #elif defined (__AVR_ATmega128__) TCNT2 = MsTimer2::tcnt2; #elif defined (__AVR_ATmega8__) TCNT2 = MsTimer2::tcnt2; #endif MsTimer2::_overflow(); }