打印
[Atmel]

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

[复制链接]
1145|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
首先建立ASF工程,选D21开发板那个。
然后把RTC模块加入:



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


然后根据提示形成程序:



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



程序清单如下:

/**
* \file
*
* \brief Empty user application template
*
*/

/**
* \mainpage User Application template doxygen documentation
*
* \par Empty user application template
*
* This is a bare minimum user application template.
*
* For documentation of the board, go \ref group_common_boards "here" for a link
* to the board-specific documentation.
*
* \par Content
*
* -# Include the ASF header files (through asf.h)
* -# Minimal main function that starts with a call to system_init()
* -# Basic usage of on-board LED and button
* -# "Insert application code here" comment
*
*/

/*
* Include header files for all drivers that have been imported from
* Atmel Software Framework (ASF).
*/
void configure_rtc_calendar(void);
#include <asf.h>
struct rtc_module rtc_instance;

void configure_rtc_calendar(void)
{
        /* Initialize RTC in calendar mode. */
        struct rtc_calendar_config config_rtc_calendar;
        rtc_calendar_get_config_defaults(&config_rtc_calendar);
        struct rtc_calendar_time alarm;
        rtc_calendar_get_time_defaults(&alarm);
        alarm.year   = 2013;
        alarm.month  = 1;
        alarm.day    = 1;
        alarm.hour   = 0;
        alarm.minute = 0;
        alarm.second = 4;
        config_rtc_calendar.clock_24h     = true;
        config_rtc_calendar.alarm[0].time = alarm;
        config_rtc_calendar.alarm[0].mask = RTC_CALENDAR_ALARM_MASK_YEAR;
        rtc_calendar_init(&rtc_instance, RTC, &config_rtc_calendar);
        rtc_calendar_enable(&rtc_instance);
}


int main (void)
{
        system_init();
       
        struct rtc_calendar_time time;
        time.year   = 2012;
        time.month  = 12;
        time.day    = 31;
        time.hour   = 23;
        time.minute = 59;
        time.second = 59;
        configure_rtc_calendar();
        /* Set current time. */
        rtc_calendar_set_time(&rtc_instance, &time);
        rtc_calendar_swap_time_mode(&rtc_instance);

         while (true) {
                 if (rtc_calendar_is_alarm_match(&rtc_instance, RTC_CALENDAR_ALARM_0)) {
                         /* Do something on RTC alarm match here */
                         port_pin_toggle_output_level(LED_0_PIN);
                         rtc_calendar_clear_alarm_match(&rtc_instance, RTC_CALENDAR_ALARM_0);
                 }
         }
}


相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

2398

主题

6953

帖子

67

粉丝