Delay Routines Using Inline Functions and Macros
================================================

Features:
=========

- No timers or interruptions used.
- Easy to reconfigure when you change the CPU clock frequency.

Note[1] : 
MAM should be fully enabled if the CPU CLOCK (CCLK) is > 20 MHz.
Otherwise CPU cycles will be wasted in the delay loop.

Configuration:
==============

Configure the following defines in delay.h according to
your system values:

#define FOSC        (12000000)     // Specify Oscilator Output Frequency.
#define PLL_MUL     (5)            // Specify PLL Multiplier.

If your have a XTAL of 12MHz and the PLL multiplier is 5,
the configuration used above works fine. CPU clock, will
be 60 MHz. If you don't use the PLL set PLL_MUL to 1. 

Code Example:
=============

#include "delay.h"

int main(void)
{

   for(;;)
   {
      DelayUS( 10 );   // Delay for 10 micro-seconds.
      DelayMS( 500 );  // Delay for 500 mili-seconds.
      DelayS( 5 );     // Delay for 5 seconds.
   }

   return 0;
}

See DelayUS(), DelayMS() and DelayS() macros in delay.h 
header file for more information about errors and maximum
delay values.

Another useful function is Delay4(), you can use it for
small delays. That function delay 4 cpu cycles per loop.
Example: Delay4( 2 ); // Delay 2 * 4 = 8 cpu cycles.

The file inttypes.h is used only to define the typedef "uint32_t".

Enjoy it!.

Boris Estudiez

03/Apr/2007, Cordoba, Argentina.-

