From 19025584c93d3a92b2010c0f82ed63e0d815babb Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Fri, 21 Nov 2008 14:37:35 +0000 Subject: [PATCH] c util file --- c/util_z.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 c/util_z.c 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