[Atmel] 用ASF跑SAMD21程序(4)TCC - time

[复制链接]
2360|0
 楼主| ddllxxrr 发表于 2014-12-19 19:11 | 显示全部楼层 |阅读模式
本帖最后由 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的,所以看上去有点闪烁。
程序清单:



  1. /**
  2. * \file
  3. *
  4. * \brief Empty user application template
  5. *
  6. */

  7. /**
  8. * \mainpage User Application template doxygen documentation
  9. *
  10. * \par Empty user application template
  11. *
  12. * This is a bare minimum user application template.
  13. *
  14. * For documentation of the board, go \ref group_common_boards "here" for a link
  15. * to the board-specific documentation.
  16. *
  17. * \par Content
  18. *
  19. * -# Include the ASF header files (through asf.h)
  20. * -# Minimal main function that starts with a call to system_init()
  21. * -# Basic usage of on-board LED and button
  22. * -# "Insert application code here" comment
  23. *
  24. */

  25. /*
  26. * Include header files for all drivers that have been imported from
  27. * Atmel Software Framework (ASF).
  28. */
  29. #include <asf.h>

  30. struct tcc_module tcc_instance;

  31. static void tcc_callback_to_toggle_led(struct tcc_module *const module_inst)
  32. {    port_pin_toggle_output_level(LED0_PIN);}
  33.         
  34. static void configure_tcc(void)
  35. {    struct tcc_config config_tcc;
  36.          tcc_get_config_defaults(&config_tcc, TCC0);
  37.          config_tcc.counter.clock_source = GCLK_GENERATOR_1;
  38.          config_tcc.counter.clock_prescaler = TCC_CLOCK_PRESCALER_DIV64;
  39.          config_tcc.counter.period =   2000;
  40.          config_tcc.compare.match[0] =  900;
  41.          config_tcc.compare.match[1] =  930;
  42.          config_tcc.compare.match[2] = 1100;
  43.          config_tcc.compare.match[3] = 1250;
  44.          tcc_init(&tcc_instance, TCC0, &config_tcc);
  45.          tcc_enable(&tcc_instance);}
  46. static void configure_tcc_callbacks(void)
  47. {    tcc_register_callback(&tcc_instance, tcc_callback_to_toggle_led,            TCC_CALLBACK_OVERFLOW);
  48.           tcc_register_callback(&tcc_instance, tcc_callback_to_toggle_led,            TCC_CALLBACK_CHANNEL_0);
  49.           tcc_register_callback(&tcc_instance, tcc_callback_to_toggle_led,            TCC_CALLBACK_CHANNEL_1);
  50.           tcc_register_callback(&tcc_instance, tcc_callback_to_toggle_led,            TCC_CALLBACK_CHANNEL_2);
  51.           tcc_register_callback(&tcc_instance, tcc_callback_to_toggle_led,            TCC_CALLBACK_CHANNEL_3);
  52.           tcc_enable_callback(&tcc_instance, TCC_CALLBACK_OVERFLOW);
  53.           tcc_enable_callback(&tcc_instance, TCC_CALLBACK_CHANNEL_0);
  54.           tcc_enable_callback(&tcc_instance, TCC_CALLBACK_CHANNEL_1);
  55.           tcc_enable_callback(&tcc_instance, TCC_CALLBACK_CHANNEL_2);
  56.           tcc_enable_callback(&tcc_instance, TCC_CALLBACK_CHANNEL_3);}        

  57. int main (void)
  58. {
  59.         system_init();
  60.         configure_tcc();
  61.         configure_tcc_callbacks();

  62.         // Insert application code here, after the board has been initialized.

  63.         // This skeleton code simply sets the LED to the state of the button.
  64.         while (1) {
  65.                
  66.         }
  67. }

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:http://shop34182318.taobao.com/ http://shop562064536.taobao.com

2404

主题

7001

帖子

68

粉丝
快速回复 在线客服 返回列表 返回顶部