[Atmel] Atmel START 跑一下外部中断

[复制链接]
3101|0
 楼主| ddllxxrr 发表于 2015-10-17 22:25 | 显示全部楼层 |阅读模式
首先加入外部中断模块:


然后编辑这个模埠,如下设置:
我设置按下和抬起都中断。


再添加个管脚LED0 PB30


最后调试运行,LED0在按键时反转一下,抬起时反转一下:





原程序如下:
main.c:
  1. #include "atmel_start.h"
  2. #include "atmel_start_pins.h"

  3. int main(void)
  4. {
  5.         system_init();

  6.         /* Replace with your application code */
  7.         while(1) {
  8.         }
  9. }



atmel_start.c:

  1. /*
  2. * Code generated from Atmel Start.
  3. *
  4. * This file will be overwritten when reconfiguring your Atmel Start project.
  5. * Please copy examples or other code you want to keep to a separate file
  6. * to avoid losing it when reconfiguring.
  7. */

  8. #include "atmel_start.h"
  9. #include <utils.h>
  10. #include <hal_init.h>
  11. #include <hpl_irq.h>
  12. #include <hpl_pm1_v201_base.h>
  13. #include <hpl_gclk1_v210_base.h>
  14. #include <peripheral_gclk_config.h>

  15. extern struct _irq_descriptor *_irq_table[PERIPH_COUNT_IRQn];
  16. extern void Default_Handler(void);

  17. void EXTERNAL_IRQ_0_init(void)
  18. {
  19.         _gclk_enable_channel(EIC_GCLK_ID, CONF_GCLK_EIC_SRC);

  20.         ext_irq_init();

  21.         // Set pin direction to input
  22.         gpio_set_pin_direction(PA15, GPIO_DIRECTION_IN);

  23.         gpio_set_pin_pull_mode(PA15,
  24.                 // <y> Pull configuration
  25.                 // <id> pad_pull_config
  26.                 // <GPIO_PULL_OFF"> Off
  27.                 // <GPIO_PULL_UP"> Pull-up
  28.                 // <GPIO_PULL_DOWN"> Pull-down
  29.                         GPIO_PULL_OFF);

  30.         gpio_set_pin_mux(PA15, GPIO_MUX_A);
  31. }

  32. void EIC_Handler(void)
  33. {
  34.         if (_irq_table[ EIC_IRQn + 0 ]) {
  35.                 _irq_table[ EIC_IRQn + 0 ]->handler(
  36.                                 _irq_table[ EIC_IRQn + 0 ]->parameter);
  37.         } else {
  38.                 Default_Handler();
  39.         }
  40. }

  41. void GCLK_Handler(void)
  42. {
  43.         if (_irq_table[  +0 ]) {
  44.                 _irq_table[  +0 ]->handler(_irq_table[  +0 ]->parameter);
  45.         } else {
  46.                 Default_Handler();
  47.         }
  48. }

  49. void SYSCTRL_Handler(void)
  50. {
  51.         if (_irq_table[ SYSCTRL_IRQn + 0 ]) {
  52.                 _irq_table[ SYSCTRL_IRQn + 0 ]->handler(
  53.                                 _irq_table[ SYSCTRL_IRQn + 0 ]->parameter);
  54.         } else {
  55.                 Default_Handler();
  56.         }
  57. }

  58. void PM_Handler(void)
  59. {
  60.         if (_irq_table[ PM_IRQn + 0 ]) {
  61.                 _irq_table[ PM_IRQn + 0 ]->handler(_irq_table[ PM_IRQn + 0 ]->parameter);
  62.         } else {
  63.                 Default_Handler();
  64.         }
  65. }

  66. static void button_on_PA15_pressed(void)
  67. {
  68.    gpio_toggle_port_level(GPIO_PORTB,PORT_PB30 );
  69. }

  70. /**
  71. * Example of using EXTERNAL_IRQ_0
  72. */
  73. void EXTERNAL_IRQ_0_example(void)
  74. {
  75.         ext_irq_register(PIN_PA15, button_on_PA15_pressed);
  76. }

  77. void system_init(void)
  78. {
  79.         init_mcu();

  80.         EXTERNAL_IRQ_0_init();
  81.        
  82.         EXTERNAL_IRQ_0_example();
  83.        
  84.         // GPIO on PB30

  85.         // Set pin direction to output
  86.         gpio_set_pin_direction(PIN_PB30, GPIO_DIRECTION_OUT);

  87.         gpio_set_pin_level(PIN_PB30,
  88.         // <y> Initial level
  89.         // <id> pad_initial_level
  90.         // <false"> Low
  91.         // <true"> High
  92.         false);

  93.         gpio_set_pin_mux(PIN_PB30, GPIO_MUX_OFF);
  94. }



本帖子中包含更多资源

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

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

本版积分规则

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

2404

主题

7002

帖子

68

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