/* p5_6.c Toggle LED0 on SAMD21 Xplained Pro using TC7 * * This program uses TC7 to blink the LED0 in 16-bit mode. * * TC7 is configured to run continuously in 16-bit mode. TC7 counter * clock is derived from 1 MHz main clock. The prescaler divides the * GCLK_TC7 by 16. The TOP count is fixed at 65,535. * * Tested with Atmel Studio 7 v7.0.1006 and Keil MDK-ARM v5.21a. */ #include "samd21.h" int main (void) { REG_GCLK_CLKCTRL = 0x401D; /* GCLK0 -> TC6/TC7 */ REG_PM_APBCMASK |= 0x00008000; /* enable TC7 Clock in PM */ REG_TC7_CTRLA = 1; /* reset TC7 before configuration */ while (REG_TC7_CTRLA & 1) {} /* wait till out of reset */ REG_TC7_CTRLA = 0x0400; /* prescaler /16, 16-bit mode, NFRQ */ REG_TC7_CTRLA |= 2; /* enable TC7 */ REG_PORT_DIR1 |= 0x40000000; /* make PB30 output */ while(1) { if (REG_TC7_INTFLAG & 1) { /* wait until OVF is set */ REG_TC7_INTFLAG = 1; /* clear OVF flag */ REG_PORT_OUT1 ^= 0x40000000; /* toggle LED0 */ } } }