DELAY FUNCTIONS
The information in this document is obtained from the following Microchip manuals:
PIC18Fxx2 Datasheet
PICmicro 18C MCU Family Reference Manual
MPLAB C18 C Compiler Libraries
Function Prototypes:
For a detailed description of these functions, please see:
Section 4.5 Delay Functions, in MPLAB C18 C Compiler Libraries manual.
#include <delays.h>
void Delay1TCY
( void );
// Delay one instruction cycle.
void Delay10TCYx
( unsigned char unit );
// Delay in multiples of 10 instruction cycles.
void Delay100TCYx ( unsigned char unit );
// Delay in multiples of 100 instruction cycles.
void Delay1KTCYx
// Delay in multiples of 1,000 instruction cycles.
( unsigned char unit );
void Delay10KTCYx ( unsigned char unit );
// Delay in multiples of 10,000 instruction cycles.
Notes:
1. The letter x in the function name above stands for times or multiplication. It is not to be replaced by a
number as done in some other function names.
2. unit is an 8-bit value in the range [0,255]. unit = 0 is equivalent to unit = 256.
3. TCY stands for instruction cycle. For 18F252/452 running at 20MHz oscillator frequency,
TCY =
4
= 0.2 s
20 MHz
4. Some examples:
// gives a delay of 0.2 s (implemented as a single NOP instruction).
Delay1TCY ();
(50);
// gives a delay of 10 0.2 s 50 = 100 s
Delay100TCYx (100);
// gives a delay of 100 0.2 s 100 = 2ms
Delay1KTCYx
// gives a delay of 1000 0.2 s 250 = 50ms
Delay10TCYx
Delay10KTCYx
F. Zia (20050727)
(250);
(0);
// gives a delay of 10000 0.2 s 256 = 0.512 s