2.7 Delay Driver
2.7.1 Overview
The MPLAB® XC8 and XC-DSC compilers have built-in delay functions or macros to make the microcontroller (MCU) wait for a certain amount of time. For these delay functions, time is measured in microseconds or milliseconds, and for PIC32 devices, in timer ticks as well. The format for invoking these macros will vary from device to device, but this delay driver helps abstract the format differences.
2.7.2 Features
The Delay driver supports pausing for a number of milliseconds or microseconds.
2.7.3 How to Use the Delay Driver
To use the delay drivers, include the delay.h file wherever the delay function is needed and call the DELAY_milliseconds(time) or DELAY_microseconds(time) function, where time is the number of milliseconds or microseconds to delay.
2.7.3.1 Use Cases
The Delay driver is an interface for abstracting the built-in delay macros.
2.7.3.1.1 Use Case 1: Delay for 1s before Toggling an LED
-
This requires 1000 ms to get a 1s delay:
int main(void) { SYSTEM_Initialize(); while(1){ DELAY_milliseconds(1000); //Delay for 1s LED_Toggle(); } }
2.7.3.1.2 Use Case 2: Delay for 1 ms before Toggling an LED
-
This requires 1000 μs to get a 1 ms delay:
int main(void) { SYSTEM_Initialize(); while(1){ DELAY_microseconds(1000); //Delay for 1 ms LED_Toggle(); } }
2.7.4 Module Documentation
2.7.4.1 Delay Driver
2.7.4.1.1 Module description
This file contains the API to generate delays in the range of milliseconds and microseconds.
Functions
void DELAY_milliseconds (uint16_t milliseconds)
Delays the execution of the program for a certain number of milliseconds.
void DELAY_microseconds (uint16_t microseconds)
Delays the execution of the program for a certain number of microseconds.
2.7.4.1.2 Function Documentation
DELAY_microseconds()
void DELAY_microseconds (uint16_t microseconds)
Delays the execution of the program for a certain number of microseconds.
in | microseconds |
- Number of microseconds to delay |
None. |
DELAY_milliseconds()
void DELAY_milliseconds (uint16_t milliseconds)
Delays the execution of the program for a certain number of milliseconds.
in | milliseconds |
- Number of milliseconds to delay |
None. |
2.7.5 File Documentation
2.7.5.1 source/delay.h File Reference
#include <stdint.h>
2.7.5.1.1 Functions
void DELAY_milliseconds (uint16_t milliseconds)
Delays the execution of the program for a certain number of milliseconds.
void DELAY_microseconds (uint16_t microseconds)
Delays the execution of the program for a certain number of microseconds.
2.7.5.1.2 Detailed Description
DELAY Generated Driver API Header File