主函数:
#include "stm32f4xx.h"
#include "delay.h"
#include "usart.h"
#include "ledhebeep.h"
#include "exti.h"
#include "anjian.h"
int main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
delay_init(168);
uart_init(115200);
GPIO_INIT();
exti_init();
LED1=0;
while(1)
{
printf("OK
");
delay_ms(1000);
}
}
中断文件:
#include"exti.h"
#include"ledhebeep.h"
#include"anjian.h"
void EXTI4_IRQHandler(void)
{
if(KEY0==0)
{
LED1=!LED1;
LED2=!LED2;
}
EXTI_ClearITPendingBit(EXTI_Line4);
}
void exti_init(void)
{
NVIC_InitTypeDef nvic_struct;
EXTI_InitTypeDef exti_struct;
ANJIAN_INIT();
RCC_APB2PeriphClockLPModeCmd(RCC_APB2Periph_SYSCFG,ENABLE);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE,EXTI_PinSource4);
exti_struct.EXTI_Line=EXTI_Line4;
exti_struct.EXTI_LineCmd=ENABLE;
exti_struct.EXTI_Mode=EXTI_Mode_Interrupt;
exti_struct.EXTI_Trigger=EXTI_Trigger_Falling;
EXTI_Init(&exti_struct);
nvic_struct.NVIC_IRQChannel=EXTI4_IRQn;
nvic_struct.NVIC_IRQChannelCmd=ENABLE;
nvic_struct.NVIC_IRQChannelPreemptionPriority=0x01;
nvic_struct.NVIC_IRQChannelSubPriority=0x02;
NVIC_Init(&nvic_struct);
}
请大神指教。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>