Short delays are required while switch debouncing, controlling LCDs,
blinking LEDs, etc. The Delay module provides functions to generate
short delays. The Delay functions are declared in delay.h
. The
following example blinks the led every 500ms.
Blink LED.
#include <delay.h>
#include <board.h>
int main()
{
board_init();
delay_init();
gpio_init();
gpio_enable_pin(LED1_GPIO);
gpio_direction_output(LED1_GPIO, OFF);
while (1) {
mdelay(250);
gpio_set_pin(LED1_GPIO, 0);
mdelay(250);
gpio_set_pin(LED1_GPIO, 1);
}
}