打印
[Atmel]

SAML21走起22:外部中断查询方式

[复制链接]
1035|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
外部中断可以用来唤醒设备。在实践中是一个比较不错的外设。
其方框图如下:


本例程是以查询为主,主要是把L21开发板上的SW0来作为外部中断开关,用来控制LED0。
首配置开关所在的管脚为外部中断模块,然后配置管脚的多路复用,最后检测这个管脚,有动作时,点亮LED0。
给我感觉这个开发板的初始化程序就是这个。

按照提示开始形成程序,这个在每个工程的ASF EXPLORER中的API Documentation中可以找到例程。

然后加入外部中断模块,再编译,这个没有什么不顺利的地方可注意的,最后绿色三角键运行。

程序如下:
#include <asf.h>
void configure_extint_channel(void)
{
        struct extint_chan_conf config_extint_chan;
        extint_chan_get_config_defaults(&config_extint_chan);
        config_extint_chan.gpio_pin           = BUTTON_0_EIC_PIN;
        config_extint_chan.gpio_pin_mux       = BUTTON_0_EIC_MUX;
        config_extint_chan.gpio_pin_pull      = EXTINT_PULL_UP;
        config_extint_chan.detection_criteria = EXTINT_DETECT_BOTH;
        extint_chan_set_config(BUTTON_0_EIC_LINE, &config_extint_chan);
}
int main (void)
{
       
          
          /* Initialize the system and console*/
          system_init();
         configure_extint_channel();
                while (true) {
                        if (extint_chan_is_detected(BUTTON_0_EIC_LINE)) {
                                // Do something in response to EXTINT edge detection
                                bool button_pin_state = port_pin_get_input_level(BUTTON_0_PIN);
                                port_pin_set_output_level(LED_0_PIN, button_pin_state);
                                extint_chan_clear_detected(BUTTON_0_EIC_LINE);
                        }
                }
       
}


相关帖子

沙发
dirtwillfly| | 2015-9-11 07:56 | 只看该作者
楼主真勤奋,大清早就发帖了

使用特权

评论回复
板凳
ddllxxrr|  楼主 | 2015-9-11 07:58 | 只看该作者
dirtwillfly 发表于 2015-9-11 07:56
楼主真勤奋,大清早就发帖了

彼此彼此

使用特权

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

本版积分规则

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

2398

主题

6945

帖子

66

粉丝