GD32F470配置外部中断

key.c

#include "key.h"

void KeyInit(void)
{
    rcu_periph_clock_enable(RCU_GPIOE);
    rcu_periph_clock_enable(RCU_SYSCFG);

    gpio_mode_set(GPIOE, GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO_PIN_7);

    nvic_irq_enable(EXTI5_9_IRQn, 2U, 0U);
    syscfg_exti_line_config(EXTI_SOURCE_GPIOE, EXTI_SOURCE_PIN7);
    exti_init(EXTI_7, EXTI_INTERRUPT, EXTI_TRIG_FALLING);
    exti_interrupt_flag_clear(EXTI_7);
}

void EXTI5_9_IRQHandler(void)
{
    if(RESET != exti_interrupt_flag_get(EXTI_7)) {
        LED_ON();
    }
    exti_interrupt_flag_clear(EXTI_7);
}

key.h

#ifndef __KEY_H
#define __KEY_H

#include "head.h"

void KeyInit(void);

#endif


main.c

    systick_config();//时钟配置
	
	LED_Init();
	LED_OFF();
	KeyInit();
	
	
	while(1){};

你可能感兴趣的:(兆易创新,单片机,嵌入式硬件)