__delay_ms Builtin

A builtin function that delays execution for the specified time.

Include

<xc.h>

Prototype

void __delay_ms(unsigned long time);

Argument

time
The number of milli seconds to delay

Remarks

This is an inbuilt function that is expanded by the code generator. When called, this routine expands to an in-line assembly delay sequence. The sequence will consist of code that delays for the number of milli seconds specified as the argument. The argument must be a constant expression.

This macro require the prior definition of the preprocessor macro _XTAL_FREQ, which indicates the system frequency. This macro should equate to the oscillator frequency (in hertz) used by the system. Note that this macro only controls the behavior of these delays and does not affect the device execution speed.

The __delay_ms() builtin function can use loops and the nop instruction to implement the delay.

An error will result if the requested delay is not a constant expression or is too large. For larger delays, call this function multiple times.

Example

#include <xc.h>

int main (void)
{
  __delay_ms(10);    // delay for 10 milli seconds
}