/* p5_1.c Toggle LED0 on SAMD21 Xplained Pro using SysTick * This program configures SysTick to be a 24-bit free-running * down-counter. * Bit 20 of SysTick current value is written to the LED0 * (PB30) continuously. * SysTick is based on system clock running at 1 MHz. * So bit 20 of SysTick current value toggles about 1 Hz * (1,000,000 Hz / 2^20 = 0.9537 Hz). * * Tested with Atmel Studio 7 v7.0.1006 and Keil MDK-ARM v5.21a. */ #include "samd21.h" int main (void) { REG_PORT_DIRSET1 = 0x40000000; /* make PB30 output for LED */ /* Configure SysTick */ SysTick->LOAD = 0xFFFFFF; /* reload with max value */ SysTick->CTRL = 5; /* enable it, no interrupt, use system clock */ while (1) { /* take bit 20 of SysTick current value and shift it to bit 30 then write it to PortB */ REG_PORT_OUT1 = (SysTick->VAL & 0x100000) << (30-20); } }