zutil-asm/c/util_z.c
2008-11-21 14:37:35 +00:00

14 lines
No EOL
442 B
C

// Delays a multiple of 1 milliseconds at 4 MHz
// using the TMR0 timer
void delay_ms( uns16 millisec){
char next = 0;
OPTION = 2; // prescaler divide TMR0 rate by 8
TMR0 = 2; // deduct 2*8 fixed instruction cycles delay
do {
next += 125;
clrwdt(); // needed only if watchdog is enabled
while (TMR0 != next) // 125 * 8 = 1000 (= 1 ms)
;
} while ( -- millisec != 0);
}