打印
[Atmel]

用ASF跑SAMD21程序(20)WDT POLLED

[复制链接]
1086|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主

那个polled我查了下字典是:剪去毛的; 无角的; 截角的; 截去树梢的

现在就记住它不是回调的函数,且特别简单的程序好了。

首先选择:新建ASF工程,在ASF向导里加WDT(POLLED)模块。然后APPLY



在ASF EXPLORER中点开QUICK START GUIDE



按照指导上说的,完成程序。注意这个时钟用到 GCLK generator 4
得把 GCLK generator 4 设为使能。

/* Configure GCLK generator 4 */
#  define CONF_CLOCK_GCLK_4_ENABLE                true
#  define CONF_CLOCK_GCLK_4_RUN_IN_STANDBY        false
#  define CONF_CLOCK_GCLK_4_CLOCK_SOURCE          GCLK_SOURCE_OSCULP32K
#  define CONF_CLOCK_GCLK_4_PRESCALER             1
#  define CONF_CLOCK_GCLK_4_OUTPUT_ENABLE         false



然后编译编译通过后,一按复位键小灯闪一下。

/**
* \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_wdt(void);
#include <asf.h>



void configure_wdt(void)
{
    /* Create a new configuration structure for the Watchdog settings and fill
     * with the default module settings. */
    struct wdt_conf config_wdt;
    wdt_get_config_defaults(&config_wdt);
    /* Set the Watchdog configuration settings */
    config_wdt.always_on      = false;
    config_wdt.clock_source   = GCLK_GENERATOR_4;
    config_wdt.timeout_period = WDT_PERIOD_2048CLK;
    /* Initialize and enable the Watchdog with the user settings */
    wdt_set_config(&config_wdt);
}

int main (void)
{
        system_init();
        configure_wdt();

         enum system_reset_cause reset_cause = system_get_reset_cause();
         if (reset_cause == SYSTEM_RESET_CAUSE_WDT) {
                 port_pin_set_output_level(LED_0_PIN, LED_0_INACTIVE);
         }
         else {
                 port_pin_set_output_level(LED_0_PIN, LED_0_ACTIVE);
         }
         while (true) {
                 if (port_pin_get_input_level(BUTTON_0_PIN) == false) {
                         port_pin_set_output_level(LED_0_PIN, LED_0_ACTIVE);
                         wdt_reset_count();
                 }
         }
}


相关帖子

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

本版积分规则

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

2398

主题

6950

帖子

67

粉丝