/* p2_1.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 0 or 1 to bit 30 of the OUT register. * 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_OUT1 &= ~0x40000000; /* turn on LED0 */ delayMs(500); REG_PORT_OUT1 |= 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"); }