[Atmel] Atmel START 跑一下定时器

[复制链接]
3173|1
 楼主| ddllxxrr 发表于 2015-10-14 22:06 | 显示全部楼层 |阅读模式
Atmel START是一个网页编程环境,超简单实用,关于用法可参考前几篇。

今天,跑个定时器.首先打开START.ATMEL.com

加入定时器模块:



定时器模块按默认值。
为了形象观察,用LED0作为指示灯,看看程序是否正确,注意SAMD21是PB30我选了PA30搞了半天哈:



然后下载用STUDIO7导入ZIP文件,然后在程序里加入自己的东东:



部分程序源码如下:

  1. static void TIMER_0_task2_cb(const struct timer_task *const timer_task)
  2. {
  3. gpio_toggle_port_level(GPIO_PORTB,PORT_PB30 );
  4.    
  5. }

  6. void TIMER_0_example(void)
  7. {
  8.         TIMER_0_task1.interval = 100;
  9.         TIMER_0_task1.cb = TIMER_0_task1_cb;
  10.         TIMER_0_task1.mode = TIMER_TASK_REPEAT;
  11.         TIMER_0_task2.interval = 200;
  12.         TIMER_0_task2.cb = TIMER_0_task2_cb;
  13.         TIMER_0_task2.mode = TIMER_TASK_REPEAT;

  14.         timer_add_task(&TIMER_0, &TIMER_0_task1);
  15.         timer_add_task(&TIMER_0, &TIMER_0_task2);
  16.         timer_start(&TIMER_0);
  17. }

  18. void system_init(void)
  19. {
  20.         init_mcu();

  21.         // GPIO on PB30

  22.         // Set pin direction to output
  23.         gpio_set_pin_direction(LED0, GPIO_DIRECTION_OUT);

  24.         gpio_set_pin_level(LED0,
  25.                 // <y> Initial level
  26.                 // <id> pad_initial_level
  27.                 // <false"> Low
  28.                 // <true"> High
  29.                         false);

  30.         gpio_set_pin_mux(LED0, GPIO_MUX_OFF);

  31.         TIMER_0_init();
  32.        
  33.         TIMER_0_example();
  34. }


下进开发板,则程序同预想的一样,定时一段时间就亮,然后就灭。



本帖子中包含更多资源

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

×
serenade753 发表于 2015-10-21 14:24 | 显示全部楼层
TC/TCC不太会用,没怎么看懂
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

2404

主题

7008

帖子

68

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