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

[复制链接]
1306|2
 楼主| ddllxxrr 发表于 2015-9-11 07:48 | 显示全部楼层 |阅读模式
外部中断可以用来唤醒设备。在实践中是一个比较不错的外设。
其方框图如下:


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

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

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

程序如下:
  1. #include <asf.h>
  2. void configure_extint_channel(void)
  3. {
  4.         struct extint_chan_conf config_extint_chan;
  5.         extint_chan_get_config_defaults(&config_extint_chan);
  6.         config_extint_chan.gpio_pin           = BUTTON_0_EIC_PIN;
  7.         config_extint_chan.gpio_pin_mux       = BUTTON_0_EIC_MUX;
  8.         config_extint_chan.gpio_pin_pull      = EXTINT_PULL_UP;
  9.         config_extint_chan.detection_criteria = EXTINT_DETECT_BOTH;
  10.         extint_chan_set_config(BUTTON_0_EIC_LINE, &config_extint_chan);
  11. }
  12. int main (void)
  13. {
  14.        
  15.           
  16.           /* Initialize the system and console*/
  17.           system_init();
  18.          configure_extint_channel();
  19.                 while (true) {
  20.                         if (extint_chan_is_detected(BUTTON_0_EIC_LINE)) {
  21.                                 // Do something in response to EXTINT edge detection
  22.                                 bool button_pin_state = port_pin_get_input_level(BUTTON_0_PIN);
  23.                                 port_pin_set_output_level(LED_0_PIN, button_pin_state);
  24.                                 extint_chan_clear_detected(BUTTON_0_EIC_LINE);
  25.                         }
  26.                 }
  27.        
  28. }


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
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

2404

主题

7002

帖子

68

粉丝
快速回复 在线客服 返回列表 返回顶部