外部中断可以用来唤醒设备。在实践中是一个比较不错的外设。
其方框图如下:
本例程是以查询为主,主要是把L21开发板上的SW0来作为外部中断开关,用来控制LED0。
首配置开关所在的管脚为外部中断模块,然后配置管脚的多路复用,最后检测这个管脚,有动作时,点亮LED0。
给我感觉这个开发板的初始化程序就是这个。
按照提示开始形成程序,这个在每个工程的ASF EXPLORER中的API Documentation中可以找到例程。
然后加入外部中断模块,再编译,这个没有什么不顺利的地方可注意的,最后绿色三角键运行。
程序如下:
- #include <asf.h>
- 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);
- }
- int main (void)
- {
-
-
- /* Initialize the system and console*/
- system_init();
- configure_extint_channel();
- while (true) {
- if (extint_chan_is_detected(BUTTON_0_EIC_LINE)) {
- // Do something in response to EXTINT edge detection
- bool button_pin_state = port_pin_get_input_level(BUTTON_0_PIN);
- port_pin_set_output_level(LED_0_PIN, button_pin_state);
- extint_chan_clear_detected(BUTTON_0_EIC_LINE);
- }
- }
-
- }
|