[Atmel] 跑SAM4S程序3:利用滴答时钟延时

[复制链接]
 楼主| ddllxxrr 发表于 2015-2-13 13:24 | 显示全部楼层 |阅读模式
本帖最后由 ddllxxrr 于 2015-2-14 13:00 编辑

这个程序是调用,CMSIS中的滴答时钟来实现1秒钟延时。

首选建立ASF工程,然后选择SAM4S的芯片,我这里选择ATSAM4SD32C

然后系统自动建立程序框架,并且还有LED程序。

然后加入Delay routines模块,



最后键入以下程序:

  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 board_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. /**
  30. * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
  31. */
  32. #include <asf.h>
  33. #include "conf_board.h"
  34. static volatile uint32_t ticks = 0U;

  35. void SysTick_Handler(void)
  36. {
  37.         ticks ++;
  38. }

  39. int main (void)
  40. {
  41.         sysclk_init();
  42.         board_init();     
  43.         

  44.         // Insert application code here, after the board has been initialized.
  45.      if(SysTick_Config(sysclk_get_cpu_hz()/(uint32_t)1000))
  46.          {
  47.                  while(1)
  48.                  {
  49.                  }
  50.          }
  51.         // This skeleton code simply sets the LED to the state of the button.
  52.         while (1) {
  53.                 // Is button pressed?
  54.                 //if (ioport_get_pin_level(BUTTON_0_PIN) == BUTTON_0_ACTIVE) {
  55.                         // Yes, so turn LED on.
  56.                         ioport_set_pin_level(LED_0_PIN, LED_0_ACTIVE);
  57.                         delay_ms((uint32_t)1000);
  58.                 //} else {
  59.                         // No, so turn LED off.
  60.                         ioport_set_pin_level(LED_0_PIN, !LED_0_ACTIVE);
  61.                         delay_ms((uint32_t)1000);
  62.                 //}
  63.         }
  64. }





编译通过时,下进开发板,发现LED0每一秒换一下亮灭的状态。


这个程序就是每记到1000就换一下状态。

本帖子中包含更多资源

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

×
dirtwillfly 发表于 2015-2-13 13:41 | 显示全部楼层
感谢分享
 楼主| ddllxxrr 发表于 2015-2-13 13:57 | 显示全部楼层
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

2403

主题

6994

帖子

68

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