Atmel Studio-SAM单片机开发 ---EXTINT

来源:互联网 发布:中国网络资讯台无锡市 编辑:程序博客网 时间:2024/05/15 05:15

我自己学习ATMEL ARM也有两个星期了,自己规划了尽量以后能保持一个星期写一篇关于ATMEL ARM单片机的学习或者应用博文。大家的阅读与交流是我最大的动力。
今天我们一起来学习EXTINT,在学习这节内容是可以查看数据手册看到SAMD21是不支持外部中断的,只支持事件触发。

这里写图片描述
关于中断与事件,下面有比较详细的解释:

这里写图片描述

好,开始本节的编程:
1:新建工程(参考第一节 —新建工程),直到下面的界面
这里写图片描述

2:向导界面 Project项选择本工程,并添加本例程需要的ASF模块
这里写图片描述

3:添加以下测试代码

#include <asf.h>void Board_init(void);void configure_extint_channel(void);void configure_extint_callbacks(void);void extint_detection_callback(void);void Board_init(void){    struct port_config pin_conf;    port_get_config_defaults(&pin_conf);    /* Configure LEDs as outputs, turn them off */    pin_conf.direction  = PORT_PIN_DIR_OUTPUT;    port_pin_set_config(PIN_PA00, &pin_conf);    port_pin_set_output_level(PIN_PA00, false);    /* Set buttons as inputs */    pin_conf.direction  = PORT_PIN_DIR_INPUT;    pin_conf.input_pull = PORT_PIN_PULL_UP;    port_pin_set_config(PIN_PA15, &pin_conf);}//! [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           = PIN_PA15A_EIC_EXTINT15;    config_extint_chan.gpio_pin_mux       = MUX_PA15A_EIC_EXTINT15;    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(15, &config_extint_chan);    //! [setup_4]}void configure_extint_callbacks(void){    //! [setup_5]    extint_register_callback(extint_detection_callback,    15,    EXTINT_CALLBACK_TYPE_DETECT);    //! [setup_5]    //! [setup_6]    extint_chan_enable_callback(15,    EXTINT_CALLBACK_TYPE_DETECT);    //! [setup_6]}//! [setup_7]void extint_detection_callback(void){    bool pin_state = port_pin_get_input_level(PIN_PA15);    port_pin_set_output_level(PIN_PA00, pin_state);}int main (void){    system_init();    Board_init();    configure_extint_channel();    configure_extint_callbacks();    system_interrupt_enable_global();    /* Insert application code here, after the board has been initialized. */    while (true)    {    }}

4:编译下载即可以测试效果,想看到不同的测试效果可以改变
void configure_extint_channel(void)函数
config_extint_chan.detection_criteria = EXTINT_DETECT_BOTH;这个项的值。
此值有以下可选:
/**
* \brief External interrupt edge detection configuration enum.
*
* Enum for the possible signal edge detection modes of the External
* Interrupt Controller module.
*/
enum extint_detect {
/** No edge detection. Not allowed as a NMI detection mode on some
* devices. */
EXTINT_DETECT_NONE = 0,
/* Detect rising signal edges /
EXTINT_DETECT_RISING = 1,
/* Detect falling signal edges /
EXTINT_DETECT_FALLING = 2,
/* Detect both signal edges /
EXTINT_DETECT_BOTH = 3,
/* Detect high signal levels /
EXTINT_DETECT_HIGH = 4,
/* Detect low signal levels /
EXTINT_DETECT_LOW = 5,
};

本次文章到此结束,有任何异议或者疑问欢迎留言讨论!!!

原创粉丝点击