/* p2_4.c Read SW0 on SAMD21 Xplained Pro * and use the value to set the LED0. * SW0 is connected to PA15. * PA15 is configured to be input with pull-up. * * Tested with Atmel Studio 7 v7.0.1006 and Keil MDK-ARM v5.20 */ #include "samd21.h" int main (void) { unsigned char* ARRAY_PORT_PINCFG0 = (unsigned char*)®_PORT_PINCFG0; REG_PORT_DIRSET1 = 0x40000000; /* make PB30 output for LED0 */ REG_PORT_DIRCLR0 = 0x00008000; /* make PA15 input for SW0 */ ARRAY_PORT_PINCFG0[15] |= 6; /* enable PA15 input buffer with pull */ REG_PORT_OUTSET0 = 0x00008000; /* make PA15 pull-up */ /* LED shows state of SW0 */ while(1) { if (REG_PORT_IN0 & 0x00008000) /* check switch status */ REG_PORT_OUTSET1 = 0x40000000; /* turn off LED0 */ else REG_PORT_OUTCLR1 = 0x40000000; /* turn on LED0 */ } }