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

[复制链接]
3146|0
 楼主| ddllxxrr 发表于 2015-1-4 16:04 | 显示全部楼层 |阅读模式
本帖最后由 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中加入
这时应打开快速开始指导,打了几次显示错误的页面,然后,我通过别的方式找到了快速指导的程序,就是如下:



  1. #include <asf.h>

  2. void configure_extint_channel(void);
  3. void configure_extint_callbacks(void);
  4. void extint_detection_callback(void);

  5. //! [setup]
  6. void configure_extint_channel(void)
  7. {
  8. //! [setup_1]
  9.         struct extint_chan_conf config_extint_chan;
  10. //! [setup_1]
  11. //! [setup_2]
  12.         extint_chan_get_config_defaults(&config_extint_chan);
  13. //! [setup_2]

  14. //! [setup_3]
  15.         config_extint_chan.gpio_pin           = BUTTON_0_EIC_PIN;
  16.         config_extint_chan.gpio_pin_mux       = BUTTON_0_EIC_MUX;
  17.         config_extint_chan.gpio_pin_pull      = EXTINT_PULL_UP;
  18.         config_extint_chan.detection_criteria = EXTINT_DETECT_BOTH;
  19. //! [setup_3]
  20. //! [setup_4]
  21.         extint_chan_set_config(BUTTON_0_EIC_LINE, &config_extint_chan);
  22. //! [setup_4]
  23. }

  24. void configure_extint_callbacks(void)
  25. {
  26. //! [setup_5]
  27.         extint_register_callback(extint_detection_callback,
  28.                         BUTTON_0_EIC_LINE,
  29.                         EXTINT_CALLBACK_TYPE_DETECT);
  30. //! [setup_5]
  31. //! [setup_6]
  32.         extint_chan_enable_callback(BUTTON_0_EIC_LINE,
  33.                         EXTINT_CALLBACK_TYPE_DETECT);
  34. //! [setup_6]
  35. }

  36. //! [setup_7]
  37. void extint_detection_callback(void)
  38. {
  39.         bool pin_state = port_pin_get_input_level(BUTTON_0_PIN);
  40.         port_pin_set_output_level(LED_0_PIN, pin_state);
  41. }
  42. //! [setup_7]
  43. //! [setup]

  44. int main(void)
  45. {
  46.         system_init();

  47.         //! [setup_init]
  48.         configure_extint_channel();
  49.         configure_extint_callbacks();

  50.         system_interrupt_enable_global();
  51.         //! [setup_init]

  52.         //! [main]
  53.         while (true) {
  54.                 /* Do nothing - EXTINT will fire callback asynchronously */
  55.         }
  56.         //! [main]
  57. }

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







本帖子中包含更多资源

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

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

本版积分规则

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

2404

主题

7001

帖子

68

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