/* p2_3.c Toggle LED0 on SAMD21 Xplained Pro at 1 Hz * In this program the system clock is increased from 1 MHz * to 8 MHz. The loop count in the function delayMs() needs * to be adjusted. * * Tested with Atmel Studio 7 v7.0.1006 and Keil MDK-ARM v5.20 */ #include "samd21.h" void delayMs(int n); int main (void) { REG_SYSCTRL_OSC8M &= ~0x00000300; /* OSC8M prescaler divided by 1 */ REG_PORT_DIR1 = 0x40000000; /* make PB30 output */ /* toggle LED continuously at 1Hz */ while(1) { REG_PORT_OUTCLR1 = 0x40000000; /* turn on LED0 */ delayMs(500); REG_PORT_OUTSET1 = 0x40000000; /* turn off LED0 */ delayMs(500); } } /* millisecond delay based on 8 MHz system clock */ void delayMs(int n) { int i; for (; n > 0; n--) for (i = 0; i < 1143; i++) /* loop count 1143 for Keil MDK-ARM v5 */ /* loop count 1600 for Atmel Studio 7 */ __asm("nop"); }