本帖最后由 ddllxxrr 于 2014-12-19 19:14 编辑
关于建立ASF的工程:这里不重述,具体请看《用ASF跑SAMD21程序(3)(2)(1)》:
用ASF跑SAMD21程序(1)8位定时器点LED
https://bbs.21ic.com/forum.php?mod=viewthread&tid=850511&extra=page%3D1%26filter%3Dtypeid%26typeid%3D380%26typeid%3D380
用ASF跑SAMD21程序(2)TCC-BASIC
https://bbs.21ic.com/forum.php?mod=viewthread&tid=850813&extra=page%3D1%26filter%3Dtypeid%26typeid%3D380%26typeid%3D380
用ASF跑SAMD21程序(3)TCC - Double Buffering & Circular
https://bbs.21ic.com/forum.php?mod=viewthread&tid=851403&extra=page%3D1%26filter%3Dtypeid%26typeid%3D380%26typeid%3D380
这个是点开快速指导TCC-TIMER的截图:
按照上述提示建立的程序,并编译通过:
时钟配置截图:
当程序运行时,LED0的灯亮了,由于四个中断都是来取反这个LED0的,所以看上去有点闪烁。
程序清单:
/**
* \file
*
* \brief Empty user application template
*
*/
/**
* \mainpage User Application template doxygen documentation
*
* \par Empty user application template
*
* This is a bare minimum user application template.
*
* For documentation of the board, go \ref group_common_boards "here" for a link
* to the board-specific documentation.
*
* \par Content
*
* -# Include the ASF header files (through asf.h)
* -# Minimal main function that starts with a call to system_init()
* -# Basic usage of on-board LED and button
* -# "Insert application code here" comment
*
*/
/*
* Include header files for all drivers that have been imported from
* Atmel Software Framework (ASF).
*/
#include <asf.h>
struct tcc_module tcc_instance;
static void tcc_callback_to_toggle_led(struct tcc_module *const module_inst)
{ port_pin_toggle_output_level(LED0_PIN);}
static void configure_tcc(void)
{ struct tcc_config config_tcc;
tcc_get_config_defaults(&config_tcc, TCC0);
config_tcc.counter.clock_source = GCLK_GENERATOR_1;
config_tcc.counter.clock_prescaler = TCC_CLOCK_PRESCALER_DIV64;
config_tcc.counter.period = 2000;
config_tcc.compare.match[0] = 900;
config_tcc.compare.match[1] = 930;
config_tcc.compare.match[2] = 1100;
config_tcc.compare.match[3] = 1250;
tcc_init(&tcc_instance, TCC0, &config_tcc);
tcc_enable(&tcc_instance);}
static void configure_tcc_callbacks(void)
{ tcc_register_callback(&tcc_instance, tcc_callback_to_toggle_led, TCC_CALLBACK_OVERFLOW);
tcc_register_callback(&tcc_instance, tcc_callback_to_toggle_led, TCC_CALLBACK_CHANNEL_0);
tcc_register_callback(&tcc_instance, tcc_callback_to_toggle_led, TCC_CALLBACK_CHANNEL_1);
tcc_register_callback(&tcc_instance, tcc_callback_to_toggle_led, TCC_CALLBACK_CHANNEL_2);
tcc_register_callback(&tcc_instance, tcc_callback_to_toggle_led, TCC_CALLBACK_CHANNEL_3);
tcc_enable_callback(&tcc_instance, TCC_CALLBACK_OVERFLOW);
tcc_enable_callback(&tcc_instance, TCC_CALLBACK_CHANNEL_0);
tcc_enable_callback(&tcc_instance, TCC_CALLBACK_CHANNEL_1);
tcc_enable_callback(&tcc_instance, TCC_CALLBACK_CHANNEL_2);
tcc_enable_callback(&tcc_instance, TCC_CALLBACK_CHANNEL_3);}
int main (void)
{
system_init();
configure_tcc();
configure_tcc_callbacks();
// Insert application code here, after the board has been initialized.
// This skeleton code simply sets the LED to the state of the button.
while (1) {
}
}
|