[Atmel] SAML21走起23:外部中断方式

[复制链接]
 楼主| ddllxxrr 发表于 2015-9-14 15:18 | 显示全部楼层 |阅读模式
这个接着上次的查询方式来,只是声明了中断函数,然后又加了中断函数原型。

这个可以在ASF EXPLORER中打开API中的例子。来形成程序。

以下是快速指导的截图:


编译时注意了。那个中断的原型一定要在声明函数前明声一下。

否则编译出错哈。

以下是编译通过的截图:



原程序上一下:
  1. #include <asf.h>

  2. void extint_detection_callback(void);

  3. void configure_extint_channel(void)
  4. {
  5.          struct extint_chan_conf config_extint_chan;
  6.          extint_chan_get_config_defaults(&config_extint_chan);
  7.          config_extint_chan.gpio_pin           = BUTTON_0_EIC_PIN;
  8.          config_extint_chan.gpio_pin_mux       = BUTTON_0_EIC_MUX;
  9.          config_extint_chan.gpio_pin_pull      = EXTINT_PULL_UP;
  10.          config_extint_chan.detection_criteria = EXTINT_DETECT_BOTH;
  11.          extint_chan_set_config(BUTTON_0_EIC_LINE, &config_extint_chan);
  12. }
  13. void configure_extint_callbacks(void)
  14. {
  15.          extint_register_callback(extint_detection_callback,
  16.          BUTTON_0_EIC_LINE,
  17.          EXTINT_CALLBACK_TYPE_DETECT);
  18.          extint_chan_enable_callback(BUTTON_0_EIC_LINE,
  19.          EXTINT_CALLBACK_TYPE_DETECT);
  20. }
  21. void extint_detection_callback(void)
  22. {
  23.          bool pin_state = port_pin_get_input_level(BUTTON_0_PIN);
  24.          port_pin_set_output_level(LED_0_PIN, pin_state);
  25. }


  26. int main (void)
  27. {
  28.        
  29.         system_init();
  30.            configure_extint_channel();
  31.            configure_extint_callbacks();
  32.            system_interrupt_enable_global();
  33.          while (true) {
  34.                  /* Nothing to do */
  35.          }
  36. }


本帖子中包含更多资源

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

×
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

2403

主题

6994

帖子

68

粉丝
快速回复 在线客服 返回列表 返回顶部
个人签名:http://shop34182318.taobao.com/ http://shop562064536.taobao.com

2403

主题

6994

帖子

68

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