[Atmel] SAML21走起28:RTC记数模式

[复制链接]
773|0
 楼主| ddllxxrr 发表于 2015-9-28 22:08 | 显示全部楼层 |阅读模式
本例程,是工作在RCT记数模式,记数2000ms,并取反LED0.

首先按快速指导建立程序,我没有改头文件,只是放到程序最前面这样就有警告但不致于编译错误。

以下是配置工作在16比特记数模式,
  1. config_rtc_count.prescaler           =  RTC_COUNT_PRESCALER_DIV_1;


编译时提示警告!但没有错误,可以不用管它。

下载运行,只见LED0每隔2秒钟,换一下状态。

以下是程序:

  1. #include <asf.h>


  2. /* SYSTEM_CLOCK_SOURCE_OSC32K configuration - Internal 32KHz oscillator */
  3. #  define CONF_CLOCK_OSC32K_ENABLE                true
  4. #  define CONF_CLOCK_OSC32K_STARTUP_TIME          SYSTEM_OSC32K_STARTUP_130
  5. #  define CONF_CLOCK_OSC32K_ENABLE_1KHZ_OUTPUT    true
  6. #  define CONF_CLOCK_OSC32K_ENABLE_32KHZ_OUTPUT   true
  7. #  define CONF_CLOCK_OSC32K_ON_DEMAND true
  8. #  define CONF_CLOCK_OSC32K_RUN_IN_STANDBY        false

  9. /* Configure GCLK generator 2 (RTC) */
  10. #  define CONF_CLOCK_GCLK_2_ENABLE                true
  11. #  define CONF_CLOCK_GCLK_2_RUN_IN_STANDBY        false
  12. #  define CONF_CLOCK_GCLK_2_CLOCK_SOURCE          SYSTEM_CLOCK_SOURCE_OSC32K
  13. #  define CONF_CLOCK_GCLK_2_PRESCALER             32
  14. #  define CONF_CLOCK_GCLK_2_OUTPUT_ENABLE         false

  15. struct rtc_module rtc_instance;

  16. void configure_rtc_count(void)
  17. {    struct rtc_count_config config_rtc_count;
  18.             rtc_count_get_config_defaults(&config_rtc_count);
  19.                     config_rtc_count.prescaler           = RTC_COUNT_PRESCALER_DIV_1;
  20.                             config_rtc_count.mode                = RTC_COUNT_MODE_16BIT;
  21.                                 #ifdef FEATURE_RTC_CONTINUOUSLY_UPDATED   
  22.                                  config_rtc_count.continuously_update = true;
  23.                                  #endif   
  24.                                  config_rtc_count.compare_values[0]   = 1000;
  25.                                  rtc_count_init(&rtc_instance, RTC, &config_rtc_count);
  26.                              rtc_count_enable(&rtc_instance);}
  27. int main (void)
  28. {
  29.        
  30.           
  31.           /* Initialize the system and console*/
  32.           system_init();
  33.           configure_rtc_count();
  34.         rtc_count_set_period(&rtc_instance, 2000);
  35.                       while (true) {        if (rtc_count_is_compare_match(&rtc_instance,  RTC_COUNT_COMPARE_0))
  36.                                    {            /* Do something on RTC count match here */   
  37.                                                     port_pin_toggle_output_level(LED_0_PIN);
  38.                                                       rtc_count_clear_compare_match(&rtc_instance, RTC_COUNT_COMPARE_0);        }    }

  39. }


以下是编译通过,但有警告的截图:


本帖子中包含更多资源

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

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

本版积分规则

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

2404

主题

7001

帖子

68

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