Let's now make the led toggle every half a second.
As usual, we will use a delay function to do this. But initialising the delay function requires the current CPU frequency. The ASF has a clock control module driver. We can use a function from this which will return the value of current CPU frequency.
To add the clock control driver
Note that when a new driver is added through ASF Wizard, new files are found in the Solution Explorer window.
Every driver must be initialised before using. Type
sysclk_init();
It better to use the auto complete by selecting the required suggestion from the pop-up and pressing Enter.
Now add the delay driver using the ASF Wizard.
We can get the current CPU frequency using the function
sysclk_get_cpu_hz()
Initialise the delay driver by typing
delay_init(sysclk_get_cpu_hz())
To make the LED toggle, use the following code
gpio_toggle_pin(LED0_GPIO);
delay_ms(500);
in the while loop. Use any delay function that you prefer.