Tutorial 3 - Toggling LED - EVK1105

Toggling LED using delay function


For this tutorial we will be using timed delay to toggle the LED

You will need to add Delay functions and System Clock Control ASF modules.



Go to menu Project > ASF wizard and select the above mentioned modules.




 

1: #include <asf.h>
 2: 
 3: int main(void)
 4: {
 5:  sysclk_init();
 6:  delay_init(sysclk_get_cpu_hz());
 7:  gpio_configure_pin(AVR32_PIN_PB27,GPIO_DIR_OUTPUT | GPIO_INIT_HIGH);
 8:  
 9:  while(1)
10:  {
11:   gpio_tgl_gpio_pin(AVR32_PIN_PB27);
12:   delay_ms(500);
13:  }
14: }


sysclk_init() initializes the system clocks, which is required for delay functions.

delay_init() initializes delay functions. 
sysclk_get_cpu_hz() returns the cpu speed in hertz, which is required by delay_init() for the initialization.

gpio_tgl_gpio_pin toggles the gpio pin.

delay_ms() Number of millisecond to wait

Toggling LED on button press





No comments:

Post a Comment