@@ -92,7 +92,6 @@ unsigned long micros() {
9292 #error TIMER 0 not defined
9393#endif
9494
95-
9695#ifdef TIFR0
9796 if ((TIFR0 & _BV (TOV0 )) && (t < 255 ))
9897 m ++ ;
@@ -122,16 +121,16 @@ void delay(unsigned long ms)
122121/* Delay for the given number of microseconds. Assumes a 1, 8, 12, 16, 20 or 24 MHz clock. */
123122void delayMicroseconds (unsigned int us )
124123{
125- // call = 4 cycles + 2 to 4 cycles to init us(2 for constant delay, 4 for variable)
126-
124+ // call = 4 cycles + 2 to 4 cycles to init us(2 for constant delay, 4 for variable)
125+
127126 // calling avrlib's delay_us() function with low values (e.g. 1 or
128127 // 2 microseconds) gives delays longer than desired.
129128 //delay_us(us);
130129#if F_CPU >= 24000000L
131130 // for the 24 MHz clock for the aventurous ones, trying to overclock
132131
133132 // zero delay fix
134- if (!us ) return ; // = 3 cycles, (4 when true)
133+ if (!us ) return ; // = 3 cycles, (4 when true)
135134
136135 // the following loop takes a 1/6 of a microsecond (4 cycles)
137136 // per iteration, so execute it six times for each microsecond of
@@ -140,7 +139,7 @@ void delayMicroseconds(unsigned int us)
140139
141140 // account for the time taken in the preceeding commands.
142141 // we just burned 22 (24) cycles above, remove 5, (5*4=20)
143- // us is at least 6 so we can substract 5
142+ // us is at least 6 so we can substract 5
144143 us -= 5 ; //=2 cycles
145144
146145#elif F_CPU >= 20000000L
@@ -153,7 +152,7 @@ void delayMicroseconds(unsigned int us)
153152 "nop" "\n\t"
154153 "nop" "\n\t"
155154 "nop" ); //just waiting 4 cycles
156- if (us <= 1 ) return ; // = 3 cycles, (4 when true)
155+ if (us <= 1 ) return ; // = 3 cycles, (4 when true)
157156
158157 // the following loop takes a 1/5 of a microsecond (4 cycles)
159158 // per iteration, so execute it five times for each microsecond of
@@ -162,7 +161,7 @@ void delayMicroseconds(unsigned int us)
162161
163162 // account for the time taken in the preceeding commands.
164163 // we just burned 26 (28) cycles above, remove 7, (7*4=28)
165- // us is at least 10 so we can substract 7
164+ // us is at least 10 so we can substract 7
166165 us -= 7 ; // 2 cycles
167166
168167#elif F_CPU >= 16000000L
@@ -179,8 +178,8 @@ void delayMicroseconds(unsigned int us)
179178
180179 // account for the time taken in the preceeding commands.
181180 // we just burned 19 (21) cycles above, remove 5, (5*4=20)
182- // us is at least 8 so we can substract 5
183- us -= 5 ; // = 2 cycles,
181+ // us is at least 8 so we can substract 5
182+ us -= 5 ; // = 2 cycles,
184183
185184#elif F_CPU >= 12000000L
186185 // for the 12 MHz clock if somebody is working with USB
@@ -196,7 +195,7 @@ void delayMicroseconds(unsigned int us)
196195
197196 // account for the time taken in the preceeding commands.
198197 // we just burned 20 (22) cycles above, remove 5, (5*4=20)
199- // us is at least 6 so we can substract 5
198+ // us is at least 6 so we can substract 5
200199 us -= 5 ; //2 cycles
201200
202201#elif F_CPU >= 8000000L
@@ -213,7 +212,7 @@ void delayMicroseconds(unsigned int us)
213212
214213 // account for the time taken in the preceeding commands.
215214 // we just burned 17 (19) cycles above, remove 4, (4*4=16)
216- // us is at least 6 so we can substract 4
215+ // us is at least 6 so we can substract 4
217216 us -= 4 ; // = 2 cycles
218217
219218#else
@@ -227,7 +226,7 @@ void delayMicroseconds(unsigned int us)
227226 us -= 22 ; // = 2 cycles
228227 // the following loop takes 4 microseconds (4 cycles)
229228 // per iteration, so execute it us/4 times
230- // us is at least 4, divided by 4 gives us 1 (no zero delay bug)
229+ // us is at least 4, divided by 4 gives us 1 (no zero delay bug)
231230 us >>= 2 ; // us div 4, = 4 cycles
232231
233232
@@ -253,7 +252,7 @@ void init()
253252#if defined(TCCR0A ) && defined(WGM01 )
254253 sbi (TCCR0A , WGM01 );
255254 sbi (TCCR0A , WGM00 );
256- #endif
255+ #endif
257256
258257 // set timer 0 prescale factor to 64
259258#if defined(__AVR_ATmega128__ )
@@ -357,31 +356,31 @@ void init()
357356
358357#if defined(ADCSRA )
359358 // set a2d prescaler so we are inside the desired 50-200 KHz range.
360- #if F_CPU >= 16000000 // 16 MHz / 128 = 125 KHz
361- sbi (ADCSRA , ADPS2 );
362- sbi (ADCSRA , ADPS1 );
363- sbi (ADCSRA , ADPS0 );
364- #elif F_CPU >= 8000000 // 8 MHz / 64 = 125 KHz
365- sbi (ADCSRA , ADPS2 );
366- sbi (ADCSRA , ADPS1 );
367- cbi (ADCSRA , ADPS0 );
368- #elif F_CPU >= 4000000 // 4 MHz / 32 = 125 KHz
369- sbi (ADCSRA , ADPS2 );
370- cbi (ADCSRA , ADPS1 );
371- sbi (ADCSRA , ADPS0 );
372- #elif F_CPU >= 2000000 // 2 MHz / 16 = 125 KHz
373- sbi (ADCSRA , ADPS2 );
374- cbi (ADCSRA , ADPS1 );
375- cbi (ADCSRA , ADPS0 );
376- #elif F_CPU >= 1000000 // 1 MHz / 8 = 125 KHz
377- cbi (ADCSRA , ADPS2 );
378- sbi (ADCSRA , ADPS1 );
379- sbi (ADCSRA , ADPS0 );
380- #else // 128 kHz / 2 = 64 KHz -> This is the closest you can get, the prescaler is 2
381- cbi (ADCSRA , ADPS2 );
382- cbi (ADCSRA , ADPS1 );
383- sbi (ADCSRA , ADPS0 );
384- #endif
359+ #if F_CPU >= 16000000 // 16 MHz / 128 = 125 KHz
360+ sbi (ADCSRA , ADPS2 );
361+ sbi (ADCSRA , ADPS1 );
362+ sbi (ADCSRA , ADPS0 );
363+ #elif F_CPU >= 8000000 // 8 MHz / 64 = 125 KHz
364+ sbi (ADCSRA , ADPS2 );
365+ sbi (ADCSRA , ADPS1 );
366+ cbi (ADCSRA , ADPS0 );
367+ #elif F_CPU >= 4000000 // 4 MHz / 32 = 125 KHz
368+ sbi (ADCSRA , ADPS2 );
369+ cbi (ADCSRA , ADPS1 );
370+ sbi (ADCSRA , ADPS0 );
371+ #elif F_CPU >= 2000000 // 2 MHz / 16 = 125 KHz
372+ sbi (ADCSRA , ADPS2 );
373+ cbi (ADCSRA , ADPS1 );
374+ cbi (ADCSRA , ADPS0 );
375+ #elif F_CPU >= 1000000 // 1 MHz / 8 = 125 KHz
376+ cbi (ADCSRA , ADPS2 );
377+ sbi (ADCSRA , ADPS1 );
378+ sbi (ADCSRA , ADPS0 );
379+ #else // 128 kHz / 2 = 64 KHz -> This is the closest you can get, the prescaler is 2
380+ cbi (ADCSRA , ADPS2 );
381+ cbi (ADCSRA , ADPS1 );
382+ sbi (ADCSRA , ADPS0 );
383+ #endif
385384 // enable a2d conversions
386385 sbi (ADCSRA , ADEN );
387386#endif
0 commit comments