1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include "timer.h" #include "global.h" #include <avr/interrupt.h> static volatile unsigned long ticks = 0; SIGNAL(SIG_OVERFLOW0) { ticks++; } void sleep(unsigned long ms) { unsigned long t = ticks + ms * (F_CPU/TIMER_PRESCALER/256000); while(ticks < t); }