这个接着上次的查询方式来,只是声明了中断函数,然后又加了中断函数原型。
这个可以在ASF EXPLORER中打开API中的例子。来形成程序。
以下是快速指导的截图:
编译时注意了。那个中断的原型一定要在声明函数前明声一下。
否则编译出错哈。
以下是编译通过的截图:
原程序上一下:
- #include <asf.h>
- void extint_detection_callback(void);
- void configure_extint_channel(void)
- {
- struct extint_chan_conf config_extint_chan;
- extint_chan_get_config_defaults(&config_extint_chan);
- config_extint_chan.gpio_pin = BUTTON_0_EIC_PIN;
- config_extint_chan.gpio_pin_mux = BUTTON_0_EIC_MUX;
- config_extint_chan.gpio_pin_pull = EXTINT_PULL_UP;
- config_extint_chan.detection_criteria = EXTINT_DETECT_BOTH;
- extint_chan_set_config(BUTTON_0_EIC_LINE, &config_extint_chan);
- }
- void configure_extint_callbacks(void)
- {
- extint_register_callback(extint_detection_callback,
- BUTTON_0_EIC_LINE,
- EXTINT_CALLBACK_TYPE_DETECT);
- extint_chan_enable_callback(BUTTON_0_EIC_LINE,
- EXTINT_CALLBACK_TYPE_DETECT);
- }
- void extint_detection_callback(void)
- {
- bool pin_state = port_pin_get_input_level(BUTTON_0_PIN);
- port_pin_set_output_level(LED_0_PIN, pin_state);
- }
- int main (void)
- {
-
- system_init();
- configure_extint_channel();
- configure_extint_callbacks();
- system_interrupt_enable_global();
- while (true) {
- /* Nothing to do */
- }
- }
|