This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Creating a not-so-portable Delay library

Hello,

I'm rather new to Keil C and just getting geared up to use it on my next project. ATM, I'm overwhelmed with the number of options and extensions that are available. I intend to write a C "library" that consists of 3 functions:

Delay()
DelayMS()
DelayUS()

These will be used as follows (examples):

Delay(2);        // creates a 2 second delay
DelayMS(500);    // creates 500ms delay
DelayUS(10);     // creates a 10us delay

I realize a timer could be used, but I'd like to have a few generic approximated delay functions available that do not occupy a timer module.

Is this even possible? I realize exact accuracy would not be possible. But a 502ms delay (or even as much as 10ms off) would be sufficient for my needs.

I'd guess I will need to write a delay loop in assembly and call it from C correct? And of course if a controller or clock got changed, i'd have to update my library..

John