/* p2_2.c Toggle LED0 on SAMD21 Xplained Pro at 1 Hz * This program toggles LED0 for 0.5 second ON and 0.5 second OFF * by writing to bit 30 of the OUTCLR and OUTSET registers. * The LED is connected to PB30. * The LED is low active (a '0' turns ON the LED). * * 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_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 1 MHz system clock */ void delayMs(int n) { int i; for (; n > 0; n--) for (i = 0; i < 199; i++) __asm("nop"); }