今天用定时器点一下灯。首先新建ASF工程加入TC模块,在没加入时或加入后用ASF EXPLORER都可以调出TC的帮助文档。
根据帮助文档,可以继续添加需要的模块,并形成程序。
程序如下:
#include <asf.h>
static void my_callback(void)
{
// User code to execute when the overflow occurs here
ioport_set_pin_high(LED0_GPIO);
ioport_set_pin_high(LED1_GPIO);
ioport_set_pin_high(LED2_GPIO);
ioport_set_pin_high(LED3_GPIO);
//delay_s(1);
}
int main (void)
{
/* Insert system clock initialization code here (sysclk_init()). */
//sysclk_init();
pmic_init();
sysclk_init();
board_init();
delay_init();
tc_enable(&TCC0);
tc_set_overflow_interrupt_callback(&TCC0, my_callback);
tc_set_wgm(&TCC0, TC_WG_NORMAL);
tc_write_period(&TCC0, 65535);
tc_set_overflow_interrupt_level(&TCC0, TC_INT_LVL_LO);
cpu_irq_enable();
tc_write_clock_source(&TCC0, TC_CLKSEL_DIV1_gc);
while(1)
{
//ioport_set_pin_high(LED0);
//ioport_set_pin_high(LED1);
//ioport_set_pin_high(LED2);
//ioport_set_pin_high(LED3);
//ioport_set_pin_high(LED0_GPIO);
//ioport_set_pin_high(LED1_GPIO);
//ioport_set_pin_high(LED2_GPIO);
//ioport_set_pin_high(LED3_GPIO);
//delay_s(1);
ioport_set_pin_low(LED0);
ioport_set_pin_low(LED1);
ioport_set_pin_low(LED2);
ioport_set_pin_low(LED3);
//delay_s(1);
}
// while(1);
/* Insert application code here, after the board has been initialized. */
}
运行结果,灯可以被点亮。
|