这个我昨天就搞了,本来认为很简单,照着提示一路做就完了。但是后来发现灯怎么也不亮。 
 
我于是掉过头仔细看了下快速指导。 
 
 
如下: 
- In this use case, the TC will be used as a timer, to generate overflow and compare match callbacks.
 
  
- In the callbacks the on-board LED is toggled.
 
  
- The TC module will be set up as follows:
 
  
- •GCLK generator 1 (GCLK 32K) clock source
 
 - •16-bit resolution on the counter
 
 - •Prescaler is divided by 64
 
 - •GCLK reload action
 
 - •Count upward
 
 - •Don't run in standby
 
 - •No waveform outputs
 
 - •No capture enabled
 
 - •Don't perform one-shot operations
 
 - •No event input enabled
 
 - •No event action
 
 - •No event generation enabled
 
 - •Counter starts on 0
 
 - •Counter top set to 2000 (about 4s) and generate overflow callback
 
 - •Channel 0 is set to compare and match value 900 and generate callback
 
 - •Channel 1 is set to compare and match value 930 and generate callback
 
 
  
可以看到必须设一下GCLK generator 1 (GCLK 32K) clock source 
于是得设两个地方一个是,外部晶振32K 为true,再一个 GCLK generator 1必须是true且为GCLK 32K 
 
再下进程序,则LED0亮了。 
 
 
以下是程序: 
- #include <asf.h>
 
 - #define CONF_TC_MODULE TC3
 
  
- struct tc_module tc_instance;
 
 - void tc_callback_to_toggle_led(struct tc_module *const module_inst);
 
 - void configure_tc(void);
 
 - void configure_tc_callbacks(void);
 
  
- void tc_callback_to_toggle_led( struct tc_module *const module_inst)
 
 - { port_pin_toggle_output_level(LED0_PIN);}
 
 - void configure_tc(void)
 
 - { struct tc_config config_tc;
 
 - tc_get_config_defaults(&config_tc);
 
 - config_tc.counter_size = TC_COUNTER_SIZE_8BIT;
 
 - config_tc.clock_source = GCLK_GENERATOR_1;
 
 - config_tc.clock_prescaler = TC_CLOCK_PRESCALER_DIV1024;
 
 - config_tc.counter_8_bit.period = 100;
 
 - config_tc.counter_8_bit.compare_capture_channel[0] = 50;
 
 - config_tc.counter_8_bit.compare_capture_channel[1] = 54;
 
 - tc_init(&tc_instance, CONF_TC_MODULE, &config_tc);
 
 - tc_enable(&tc_instance);}
 
 - void configure_tc_callbacks(void)
 
 - { tc_register_callback(&tc_instance, tc_callback_to_toggle_led, TC_CALLBACK_OVERFLOW);
 
 - tc_register_callback(&tc_instance, tc_callback_to_toggle_led, TC_CALLBACK_CC_CHANNEL0);
 
 - tc_register_callback(&tc_instance, tc_callback_to_toggle_led, TC_CALLBACK_CC_CHANNEL1);
 
 - tc_enable_callback(&tc_instance, TC_CALLBACK_OVERFLOW);
 
 - tc_enable_callback(&tc_instance, TC_CALLBACK_CC_CHANNEL0);
 
 - tc_enable_callback(&tc_instance, TC_CALLBACK_CC_CHANNEL1);}
 
  
- int main (void)
 
 - {
 
 - system_init();
 
 - configure_tc(); 
 
 - configure_tc_callbacks();
 
 - system_interrupt_enable_global();
 
  
- while (1)
 
  
- {
 
 - }
 
 - }
 
 
  
 
 
  |