/* p6_3.c Non-maskable interrupt from PA08 * * PA08 is configured to generate non-maskable interrupt. * In the interrupt handler, the user LED0 is blinked twice. * * Tested with Atmel Studio 7 v7.0.1006 and Keil MDK-ARM v5.21a */ #include "samd21.h" unsigned char* ARRAY_PORT_PINCFG0 = (unsigned char*)®_PORT_PINCFG0; unsigned char* ARRAY_PORT_PMUX0 = (unsigned char*)®_PORT_PMUX0; void delayMs(int n); int main (void) { REG_PORT_DIRSET1 = 0x40000000; /* make PB30 output for LED */ ARRAY_PORT_PINCFG0[8] |= 7; /* make PA08 NMI */ ARRAY_PORT_PMUX0[4] = 0; /* PA08 = NMI */ REG_PORT_DIRCLR0 = 0x0010; /* PA08 input */ REG_PORT_OUTSET0 = 0x0010; /* pull up PA08 */ REG_GCLK_CLKCTRL = 0x4005; /* GCLK0 -> EIC */ REG_EIC_NMICTRL |= 0xA; /* NMI filtered falling-edge */ while(1) { } } /* in the interrupt handler, the yellow LED0 blinks twice */ void NMI_Handler(void) { REG_PORT_OUTCLR1 = 0x40000000; /* turn on LED */ delayMs(250); REG_PORT_OUTSET1 = 0x40000000; /* turn off LED */ delayMs(250); REG_PORT_OUTCLR1 = 0x40000000; /* turn on LED */ delayMs(250); REG_PORT_OUTSET1 = 0x40000000; /* turn off LED */ delayMs(250); REG_EIC_NMIFLAG = 1; /* clear interrupt flag */ } /* 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"); }