8.4.2 _delay_us Function

Delay for the specified time.

Include

<util/delay.h>

Prototype

void _delay_us(double us);
Arguments
us
The time in micro seconds to delay.

Remarks

This function delays execution by using the _delay_loop_1() function. The macro F_CPU should be defined as a constant that specifies the CPU clock frequency (in Hertz). The compiler optimizers must be enabled for accurate delay times.

The maximal possible delay is 4294967.295 us/F_CPU in MHz. Requesting values greater than the maximal possible delay will result in overflow and a delay of 0us.

Conversion of the requested number of micro seconds into clock cycles may not always result in integer value. By default, the number of clock cycles is rounded up to next integer. This ensures that there is at least the requested amount of delay.

By defining the macro __DELAY_ROUND_DOWN__, or __DELAY_ROUND_CLOSEST__, before including this header file, the algorithm can be made to round down, or round to closest integer, respectively.

Example

#define F_CPU 4000000UL
#include <util/delay.h>

int main(void)
{
  _delay_us(20);  // delay for 20 micro seconds
}