// the prescaler is set so that timer0 ticks every 64 clock cycles, and the
// the overflow handler is called every 256 ticks.
#define MICROSECONDS_PER_TIMER0_OVERFLOW (clockCyclesToMicroseconds(64 * 256))
// the whole number of milliseconds per timer0 overflow
#define MILLIS_INC (MICROSECONDS_PER_TIMER0_OVERFLOW / 1000)
// the fractional number of milliseconds per timer0 overflow. we shift right
// by three to fit these numbers into a byte. (for the clock speeds we care
// about - 8 and 16 MHz - this doesn't lose precision.)
#define FRACT_INC ((MICROSECONDS_PER_TIMER0_OVERFLOW % 1000) >> 3)
#define FRACT_MAX (1000 >> 3)
volatileunsignedlongtimer0_overflow_count=0;volatileunsignedlongtimer0_millis=0;staticunsignedchartimer0_fract=0;ISR(TIMER0_OVF_vect){// copy these to local variables so they can be stored in registers
// (volatile variables must be read from memory on every access)
unsignedlongm=timer0_millis;unsignedcharf=timer0_fract;m+=MILLIS_INC;f+=FRACT_INC;if(f>=FRACT_MAX){f-=FRACT_MAX;m+=1;}timer0_fract=f;timer0_millis=m;timer0_overflow_count++;}
ISR(TIMER0_OVF_vect){// copy these to local variables so they can be stored in registers
// (volatile variables must be read from memory on every access)
unsignedlongm=timer0_millis;unsignedcharf=timer0_fract;
/*
Copyright (c) 2016 garretlab.
Added source code explanation by garretlab.
*//*
wiring.c - Partial implementation of the Wiring API for the ATmega8.
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2005-2006 David A. Mellis
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
*/