diff --git a/c/util_z.c b/c/util_z.c new file mode 100644 index 0000000..d68b6ae --- /dev/null +++ b/c/util_z.c @@ -0,0 +1,14 @@ +// 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); +} \ No newline at end of file