[Atmel] 用ASF跑SAMD21程序(27)RTC (CAL) - Basic

[复制链接]
1348|0
 楼主| ddllxxrr 发表于 2015-2-2 20:44 | 显示全部楼层 |阅读模式
首先建立ASF工程,选D21开发板那个。
然后把RTC模块加入:



然后打开ASF EXPLORER ,选择快速指南。


然后根据提示形成程序:



然后根据提示形成程序:注意提示的时钟设置。
最后编译运行:



程序清单如下:

  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. void configure_rtc_calendar(void);
  30. #include <asf.h>
  31. struct rtc_module rtc_instance;

  32. void configure_rtc_calendar(void)
  33. {
  34.         /* Initialize RTC in calendar mode. */
  35.         struct rtc_calendar_config config_rtc_calendar;
  36.         rtc_calendar_get_config_defaults(&config_rtc_calendar);
  37.         struct rtc_calendar_time alarm;
  38.         rtc_calendar_get_time_defaults(&alarm);
  39.         alarm.year   = 2013;
  40.         alarm.month  = 1;
  41.         alarm.day    = 1;
  42.         alarm.hour   = 0;
  43.         alarm.minute = 0;
  44.         alarm.second = 4;
  45.         config_rtc_calendar.clock_24h     = true;
  46.         config_rtc_calendar.alarm[0].time = alarm;
  47.         config_rtc_calendar.alarm[0].mask = RTC_CALENDAR_ALARM_MASK_YEAR;
  48.         rtc_calendar_init(&rtc_instance, RTC, &config_rtc_calendar);
  49.         rtc_calendar_enable(&rtc_instance);
  50. }


  51. int main (void)
  52. {
  53.         system_init();
  54.        
  55.         struct rtc_calendar_time time;
  56.         time.year   = 2012;
  57.         time.month  = 12;
  58.         time.day    = 31;
  59.         time.hour   = 23;
  60.         time.minute = 59;
  61.         time.second = 59;
  62.         configure_rtc_calendar();
  63.         /* Set current time. */
  64.         rtc_calendar_set_time(&rtc_instance, &time);
  65.         rtc_calendar_swap_time_mode(&rtc_instance);

  66.          while (true) {
  67.                  if (rtc_calendar_is_alarm_match(&rtc_instance, RTC_CALENDAR_ALARM_0)) {
  68.                          /* Do something on RTC alarm match here */
  69.                          port_pin_toggle_output_level(LED_0_PIN);
  70.                          rtc_calendar_clear_alarm_match(&rtc_instance, RTC_CALENDAR_ALARM_0);
  71.                  }
  72.          }
  73. }


本帖子中包含更多资源

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

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

本版积分规则

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

2404

主题

7001

帖子

68

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