小学生
最后登录1970-1-1
在线时间 小时
注册时间2020-12-15
|
10火花
本帖最后由 zhouminrui 于 2020-12-16 15:53 编辑
配置中断优先级
static void Nvic_config(){
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitTypeDef NVIC_Initstruct;
NVIC_Initstruct.NVIC_IRQChannel = EXTI0_IRQn;
NVIC_Initstruct.NVIC_IRQChannelSubPriority =1;
NVIC_Initstruct.NVIC_IRQChannelSubPriority =1;
NVIC_Initstruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_Initstruct);
NVIC_Initstruct.NVIC_IRQChannel = EXTI15_10_IRQn;
NVIC_Init(&NVIC_Initstruct);
}
void Exti_config(){
//配置NVIC
Nvic_config();
//RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO, ENABLE);
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC, ENABLE);
//开启GPIOA,GPIOB时钟
GPIO_InitTypeDef GPIOA_pin0,GPIOC_pin13;
GPIOA_pin0.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIOA_pin0.GPIO_Pin = GPIO_Pin_0;
GPIOC_pin13.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIOC_pin13.GPIO_Pin = GPIO_Pin_13;
GPIO_Init(GPIOA,&GPIOA_pin0);
GPIO_Init(GPIOC,&GPIOC_pin13);//初始化GPIOA的PIN0,GPIOC的pin13引脚
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource0);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource13);
//配置
//配置EXTI
EXTI_InitTypeDef PIN0_initstruct,PIN13_initstruct;
PIN0_initstruct.EXTI_Line = EXTI_Line0;
PIN0_initstruct.EXTI_Mode=EXTI_Mode_Interrupt;
PIN0_initstruct.EXTI_LineCmd = ENABLE;
PIN0_initstruct.EXTI_Trigger = EXTI_Trigger_Rising;
PIN13_initstruct.EXTI_Line = EXTI_Line13;
PIN13_initstruct.EXTI_Mode=EXTI_Mode_Interrupt;
PIN13_initstruct.EXTI_LineCmd = ENABLE;
PIN13_initstruct.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_Init(&PIN0_initstruct);
EXTI_Init(&PIN13_initstruct);
}exti配置
中断服务函数
void EXTI0_IRQHandler(void){
if(EXTI_GetITStatus(EXTI_Line0) !=RESET){
LED_open(0);开启绿灯
EXTI_ClearITPendingBit(EXTI_Line0);
}
}
void EXTI15_10_IRQHandler(void){
if(EXTI_GetITStatus(EXTI_Line13) !=RESET){
LED_open(1);//开启蓝灯
EXTI_ClearITPendingBit(EXTI_Line13);
}
}
主函数
int main(void)
{
LED_config();//配置GPIOB
Exti_config();//配置中断
while(1){
}
}
用的时f103指南者
当我考录好编译好的程序时,程序直接执行EXTI15_10_IRQHandler(),蓝灯打开,重启后蓝灯不打开,按key2时蓝灯不亮没反应,按key1时绿灯正常亮。这是为什么?
https://www.firebbs.cn/forum.php?mod=attachment&aid=MjkxODN8ZTI0MTMxYzdjMmIxNTcyYTg0Njk4NzBiMGE3N2M5MjR8MTczMjM5ODQyOQ%3D%3D&request=yes&_f=.zip
|
|