/* p5_2.c Toggle LED0 on SAMD21 Xplained Pro at 5 Hz using SysTick * This program uses SysTick to generate 200 ms delay to * toggle the LED0. * System clock is running at 1 MHz. SysTick is configure * to count down from 199999 to zero to give a 200 ms delay. * The LED0 is connected to PB30. * * Tested with Atmel Studio 7 v7.0.1006 and Keil MDK-ARM v5.21a. */ #include "samd21.h" int main (void) { // make PB30 output for LED REG_PORT_DIRSET1 = 0x40000000; /* make PB30 output for LED */ /* Configure SysTick */ SysTick->LOAD = 200000 - 1; /* reload with number of clocks per second */ SysTick->VAL = 0; SysTick->CTRL = 5; /* enable it, no interrupt, use system clock */ while (1) { if (SysTick->CTRL & 0x10000) { /* if COUNT flag is set */ REG_PORT_OUTTGL1 = 0x40000000; /* toggle red LED */ } } }