|
大佬们帮忙看看,外部中断初始化后按键按下没有作用,不知道是什么问题呀?大佬们看看下面单片机源码:
exit.c
#include "exti.h"
#include "oled.h"
#include "key.h"
#include "risk.h"
#include "delay.h"
#include "usart.h"
extern int oledSwitchFlag; //oledSwitchFlag实现外部中断切换页面
extern int valueMode; //valueMode实现阈值上限下限的切换 0-上限 1-下限
extern int temp_up, temp_low; //温度阈值, up上限,low下限
extern int humi_up, humi_low; //湿度阈值, up上限,low下限
extern int hydr_up; //氢气阈值, up上限,气体只设置上限阈值
extern int carbon_up; //一氧化碳阈值, up上限,气体只设置上限阈值
extern int natgas_up; //天然气阈值, up上限,气体只设置上限阈值
extern int Timer3_Switch; //定时器TIM3的开关标记位
extern int riskFlag;
void EXTIX_Init(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
KEYInit(); //按键模块初始化
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
//GPIOB12 //KEY_Mode
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource12);
EXTI_InitStructure.EXTI_Line=EXTI_Line12;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_Init(&EXTI_InitStructure);
//GPIOB13 //KEY_Add
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource13);
EXTI_InitStructure.EXTI_Line=EXTI_Line13;
EXTI_Init(&EXTI_InitStructure);
//GPIOB14 //KEY_Reduce
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource14);
EXTI_InitStructure.EXTI_Line=EXTI_Line14;
EXTI_Init(&EXTI_InitStructure);
//GPIOB15 //KEY_Control
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource15);
EXTI_InitStructure.EXTI_Line=EXTI_Line15;
EXTI_Init(&EXTI_InitStructure);
//GPIOA.0 PA0 WK_UP
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource0);
EXTI_InitStructure.EXTI_Line=EXTI_Line0;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_Init(&EXTI_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void EXTI0_IRQHandler(void)
{
delay_ms(10);
if(WK_UP == 1){
Risk != Risk;
}
EXTI_ClearITPendingBit(EXTI_Line0);
}
void EXTI15_10_IRQHandler(void)
{
delay_ms(10);
if(KEY_Mode == 0){ //模式按键
oledSwitchFlag++;
OLED_Clear();
UsartPrintf(USART_DEBUG,"oledSwitchFlag=%d\r\n",oledSwitchFlag);
if(valueMode != 0)
valueMode = 0;
if(oledSwitchFlag == 6)
oledSwitchFlag = 0;
EXTI_ClearITPendingBit(EXTI_Line12);
}
if(KEY_Add == 0){ //数值加
if(oledSwitchFlag == 0) //控制警报
riskFlag = 0;
if(oledSwitchFlag == 1){
if(valueMode == 0){
temp_up++;
if(temp_up > 99)
temp_up = 0;
}else{
temp_low++;
if(temp_low > 99)
temp_low = 0;
}
}else if(oledSwitchFlag == 2){
if(valueMode == 0){
humi_up++;
if(humi_up > 99)
humi_up = 0;
}else{
humi_low++;
if(humi_low > 99)
humi_low = 0;
}
}else if(oledSwitchFlag == 3){
hydr_up++;
if(hydr_up > 99)
hydr_up = 0;
}else if(oledSwitchFlag == 4){
carbon_up++;
if(carbon_up > 99)
carbon_up = 0;
}else if(oledSwitchFlag == 5){
natgas_up++;
if(natgas_up > 99)
natgas_up = 0;
}
EXTI_ClearITPendingBit(EXTI_Line13);
}
if(KEY_Reduce == 0){ //数值减
if(oledSwitchFlag == 1){
if(valueMode == 0){
temp_up--;
if(temp_up < 0)
temp_up = 99;
}else{
temp_low--;
if(temp_low < 0)
temp_low = 99;
}
}else if(oledSwitchFlag == 2){
if(valueMode == 0){
humi_up--;
if(humi_up < 0)
humi_up = 99;
}else{
humi_low--;
if(humi_low < 0)
humi_low = 99;
}
}else if(oledSwitchFlag == 3){
hydr_up--;
if(hydr_up < 0)
hydr_up = 99;
}else if(oledSwitchFlag == 4){
carbon_up--;
if(carbon_up < 0)
carbon_up = 99;
}else if(oledSwitchFlag == 5){
natgas_up--;
if(natgas_up < 0)
natgas_up = 99;
}
EXTI_ClearITPendingBit(EXTI_Line14);
}
if(KEY_Control == 0){ //控制光标和数据动态切屏
if(oledSwitchFlag == 0){
if(Timer3_Switch == 1){
TIM_Cmd(TIM3, DISABLE); //关闭定时器TIM3
Timer3_Switch = 0;
}else if(Timer3_Switch ==0){
TIM_Cmd(TIM3, ENABLE); //打开定时器TIM3
Timer3_Switch = 1;
}
}else if(oledSwitchFlag == 1 || oledSwitchFlag == 2){
valueMode++;
OLED_Clear();
if(valueMode > 1)
valueMode = 0;
}
EXTI_ClearITPendingBit(EXTI_Line15);
}
}
key.c
#include "key.h"
void KEYInit(void){
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB,ENABLE);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;
GPIO_Init(GPIOB ,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPD;
GPIO_Init(GPIOA,&GPIO_InitStructure);
}
|
|