打印
[Atmel]

用ASF跑SAMD21程序(12) 外部中断

[复制链接]
2774|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
本帖最后由 ddllxxrr 于 2015-1-4 17:56 编辑

[backcolor=rgba(255, 255, 255, 0.796875)]
外部中断控制器( EIC )允许外部引脚配置为中断线路。每个中断线可
单独屏蔽,可以生成上升,下降或两边,或高或低的水平中断。每个外部
引脚有一个可配置的过滤器,以消除尖峰。每个外部引脚也可以构成为,以异步于
醒来从那里所有的时钟都被禁用休眠模式下的器件。外部引脚还可以生成一个事件。
一个独立的非屏蔽中断( NMI )也支持。它具有类似于其它外部中断性能,但是是
连接到CPU的NMI中断请求,使其能够中断任何其它中断模式。
以下是数据手册的截图:
[backcolor=rgba(255, 255, 255, 0.796875)]
[backcolor=rgba(255, 255, 255, 0.796875)]

这个运行也同其它的一样,先建立一个AFS的工程,然后把外部中断模块包含进来.在ASF EXPLORER中加入
这时应打开快速开始指导,打了几次显示错误的页面,然后,我通过别的方式找到了快速指导的程序,就是如下:



#include <asf.h>

void configure_extint_channel(void);
void configure_extint_callbacks(void);
void extint_detection_callback(void);

//! [setup]
void configure_extint_channel(void)
{
//! [setup_1]
        struct extint_chan_conf config_extint_chan;
//! [setup_1]
//! [setup_2]
        extint_chan_get_config_defaults(&config_extint_chan);
//! [setup_2]

//! [setup_3]
        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;
//! [setup_3]
//! [setup_4]
        extint_chan_set_config(BUTTON_0_EIC_LINE, &config_extint_chan);
//! [setup_4]
}

void configure_extint_callbacks(void)
{
//! [setup_5]
        extint_register_callback(extint_detection_callback,
                        BUTTON_0_EIC_LINE,
                        EXTINT_CALLBACK_TYPE_DETECT);
//! [setup_5]
//! [setup_6]
        extint_chan_enable_callback(BUTTON_0_EIC_LINE,
                        EXTINT_CALLBACK_TYPE_DETECT);
//! [setup_6]
}

//! [setup_7]
void extint_detection_callback(void)
{
        bool pin_state = port_pin_get_input_level(BUTTON_0_PIN);
        port_pin_set_output_level(LED_0_PIN, pin_state);
}
//! [setup_7]
//! [setup]

int main(void)
{
        system_init();

        //! [setup_init]
        configure_extint_channel();
        configure_extint_callbacks();

        system_interrupt_enable_global();
        //! [setup_init]

        //! [main]
        while (true) {
                /* Do nothing - EXTINT will fire callback asynchronously */
        }
        //! [main]
}

把这个程序考到主程序即可,以下是运行的截图:
当我按下SAMD21板子上的用户键时,LED0灯亮了.







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

本版积分规则

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

2398

主题

6945

帖子

66

粉丝