本例程,是工作在RCT记数模式,记数2000ms,并取反LED0.
首先按快速指导建立程序,我没有改头文件,只是放到程序最前面这样就有警告但不致于编译错误。
以下是配置工作在16比特记数模式,
- config_rtc_count.prescaler = RTC_COUNT_PRESCALER_DIV_1;
编译时提示警告!但没有错误,可以不用管它。
下载运行,只见LED0每隔2秒钟,换一下状态。
以下是程序:
- #include <asf.h>
- /* SYSTEM_CLOCK_SOURCE_OSC32K configuration - Internal 32KHz oscillator */
- # define CONF_CLOCK_OSC32K_ENABLE true
- # define CONF_CLOCK_OSC32K_STARTUP_TIME SYSTEM_OSC32K_STARTUP_130
- # define CONF_CLOCK_OSC32K_ENABLE_1KHZ_OUTPUT true
- # define CONF_CLOCK_OSC32K_ENABLE_32KHZ_OUTPUT true
- # define CONF_CLOCK_OSC32K_ON_DEMAND true
- # define CONF_CLOCK_OSC32K_RUN_IN_STANDBY false
- /* Configure GCLK generator 2 (RTC) */
- # define CONF_CLOCK_GCLK_2_ENABLE true
- # define CONF_CLOCK_GCLK_2_RUN_IN_STANDBY false
- # define CONF_CLOCK_GCLK_2_CLOCK_SOURCE SYSTEM_CLOCK_SOURCE_OSC32K
- # define CONF_CLOCK_GCLK_2_PRESCALER 32
- # define CONF_CLOCK_GCLK_2_OUTPUT_ENABLE false
- struct rtc_module rtc_instance;
- void configure_rtc_count(void)
- { struct rtc_count_config config_rtc_count;
- rtc_count_get_config_defaults(&config_rtc_count);
- config_rtc_count.prescaler = RTC_COUNT_PRESCALER_DIV_1;
- config_rtc_count.mode = RTC_COUNT_MODE_16BIT;
- #ifdef FEATURE_RTC_CONTINUOUSLY_UPDATED
- config_rtc_count.continuously_update = true;
- #endif
- config_rtc_count.compare_values[0] = 1000;
- rtc_count_init(&rtc_instance, RTC, &config_rtc_count);
- rtc_count_enable(&rtc_instance);}
- int main (void)
- {
-
-
- /* Initialize the system and console*/
- system_init();
- configure_rtc_count();
- rtc_count_set_period(&rtc_instance, 2000);
- while (true) { if (rtc_count_is_compare_match(&rtc_instance, RTC_COUNT_COMPARE_0))
- { /* Do something on RTC count match here */
- port_pin_toggle_output_level(LED_0_PIN);
- rtc_count_clear_compare_match(&rtc_instance, RTC_COUNT_COMPARE_0); } }
- }
以下是编译通过,但有警告的截图:
|