2.GuiStar_EXTI.c#include "stm32f10x.h" // Device header
void (*GuiStar_EXTI0_IRQHandler)(void);
void (*GuiStar_EXTI1_IRQHandler)(void);
void (*GuiStar_EXTI2_IRQHandler)(void);
void (*GuiStar_EXTI3_IRQHandler)(void);
void (*GuiStar_EXTI4_IRQHandler)(void);
void (*GuiStar_EXTI9_5_IRQHandler)(void);
void (*GuiStar_EXTI15_10_IRQHandler)(void);
/**
* @brief 确定外部中断0处理器的行为
* @param *Function 它是一个指向定时器中断行为的指针
* @retval 无
*/
void GuiStar_EXTI_SetEXTI0_IRQHandler(void (*Function)(void))
{
GuiStar_EXTI0_IRQHandler=Function;
}
/**
* @brief 确定外部中断1处理器的行为
* @param *Function 它是一个指向定时器中断行为的指针
* @retval 无
*/
void GuiStar_EXTI_SetEXTI1_IRQHandler(void (*Function)(void))
{
GuiStar_EXTI1_IRQHandler=Function;
}
/**
* @brief 确定外部中断2处理器的行为
* @param *Function 它是一个指向定时器中断行为的指针
* @retval 无
*/
void GuiStar_EXTI_SetEXTI2_IRQHandler(void (*Function)(void))
{
GuiStar_EXTI2_IRQHandler=Function;
}
/**
* @brief 确定外部中断3处理器的行为
* @param *Function 它是一个指向定时器中断行为的指针
* @retval 无
*/
void GuiStar_EXTI_SetEXTI3_IRQHandler(void (*Function)(void))
{
GuiStar_EXTI3_IRQHandler=Function;
}
/**
* @brief 确定外部中断4处理器的行为
* @param *Function 它是一个指向定时器中断行为的指针
* @retval 无
*/
void GuiStar_EXTI_SetEXTI4_IRQHandler(void (*Function)(void))
{
GuiStar_EXTI4_IRQHandler=Function;
}
/**
* @brief 确定外部中断15_10处理器的行为
* @param *Function 它是一个指向定时器中断行为的指针
* @retval 无
*/
void GuiStar_EXTI_SetEXTI15_10_IRQHandler(void (*Function)(void))
{
GuiStar_EXTI15_10_IRQHandler=Function;
}
/**
* @brief 确定外部中断9_5处理器的行为
* @param *Function 它是一个指向定时器中断行为的指针
* @retval 无
*/
void GuiStar_EXTI_SetEXTI9_5_IRQHandler(void (*Function)(void))
{
GuiStar_EXTI9_5_IRQHandler=Function;
}
/**
* @brief 外部中断配置函数
* @param GPIOx 选择GPIO端口(ABCDEFG)
* @param GPIO_Pin_x 选择GPIO引脚(0~16)
* @param EXTITrigger 选择什么边沿触发
* EXTI_Trigger_Rising 上升沿触发;
* EXTI_Trigger_Falling 下降沿触发;
* EXTI_Trigger_Rising_Falling 双边沿触发;
* @attention 此函数内部并没有配置GPIO的模式,请根据需要自行配置模式
* @retval
*/
void GuiStar_EXTI_Init(GPIO_TypeDef* GPIOx, u16 GPIO_Pin_x, EXTITrigger_TypeDef EXTITrigger)
{
u8 GPIO_PortSourceGPIOx;
u8 GPIO_PinSourcex=0;
for(;((1<<GPIO_PinSourcex) & (GPIO_Pin_x))==0;)
{
GPIO_PinSourcex++;
};
if(GPIOx==GPIOA)
{
GPIO_PortSourceGPIOx=GPIO_PortSourceGPIOA;
}
if(GPIOx==GPIOB)
{
GPIO_PortSourceGPIOx=GPIO_PortSourceGPIOB;
}
if(GPIOx==GPIOC)
{
GPIO_PortSourceGPIOx=GPIO_PortSourceGPIOC;
}
if(GPIOx==GPIOD)
{
GPIO_PortSourceGPIOx=GPIO_PortSourceGPIOD;
}
if(GPIOx==GPIOE)
{
GPIO_PortSourceGPIOx=GPIO_PortSourceGPIOE;
}
if(GPIOx==GPIOF)
{
GPIO_PortSourceGPIOx=GPIO_PortSourceGPIOF;
}
if(GPIOx==GPIOG)
{
GPIO_PortSourceGPIOx=GPIO_PortSourceGPIOG;
}
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);//开启AFIO的时钟
GPIO_EXTILineConfig(GPIO_PortSourceGPIOx,GPIO_PinSourcex);//配置外部引脚
EXTI_InitTypeDef EXTI_InitStruct;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitTypeDef NVIC_InitStruct;
if(GPIO_PinSourcex==0)//选中外部中断线
{
EXTI_InitStruct.EXTI_Line = EXTI_Line0;
NVIC_InitStruct.NVIC_IRQChannel = EXTI0_IRQn;
}
if(GPIO_PinSourcex==1)
{
EXTI_InitStruct.EXTI_Line = EXTI_Line1;
NVIC_InitStruct.NVIC_IRQChannel = EXTI1_IRQn;
}
if(GPIO_PinSourcex==2)
{
EXTI_InitStruct.EXTI_Line = EXTI_Line2;
NVIC_InitStruct.NVIC_IRQChannel = EXTI2_IRQn;
}
if(GPIO_PinSourcex==3)
{
EXTI_InitStruct.EXTI_Line = EXTI_Line3;
NVIC_InitStruct.NVIC_IRQChannel = EXTI3_IRQn;
}
if(GPIO_PinSourcex==4)
{
EXTI_InitStruct.EXTI_Line = EXTI_Line4;
NVIC_InitStruct.NVIC_IRQChannel = EXTI4_IRQn;
}
if(GPIO_PinSourcex==5)
{
EXTI_InitStruct.EXTI_Line = EXTI_Line5;
NVIC_InitStruct.NVIC_IRQChannel = EXTI9_5_IRQn;
}
if(GPIO_PinSourcex==6)
{
EXTI_InitStruct.EXTI_Line = EXTI_Line6;
NVIC_InitStruct.NVIC_IRQChannel = EXTI9_5_IRQn;
}
if(GPIO_PinSourcex==7)
{
EXTI_InitStruct.EXTI_Line = EXTI_Line7;
NVIC_InitStruct.NVIC_IRQChannel = EXTI9_5_IRQn;
}
if(GPIO_PinSourcex==8)
{
EXTI_InitStruct.EXTI_Line = EXTI_Line8;
NVIC_InitStruct.NVIC_IRQChannel = EXTI9_5_IRQn;
}
if(GPIO_PinSourcex==9)
{
EXTI_InitStruct.EXTI_Line = EXTI_Line9;
NVIC_InitStruct.NVIC_IRQChannel = EXTI9_5_IRQn;
}
if(GPIO_PinSourcex==10)
{
EXTI_InitStruct.EXTI_Line = EXTI_Line10;
NVIC_InitStruct.NVIC_IRQChannel = EXTI15_10_IRQn;
}
if(GPIO_PinSourcex==11)
{
EXTI_InitStruct.EXTI_Line = EXTI_Line11;
NVIC_InitStruct.NVIC_IRQChannel = EXTI15_10_IRQn;
}
if(GPIO_PinSourcex==12)
{
EXTI_InitStruct.EXTI_Line = EXTI_Line12;
NVIC_InitStruct.NVIC_IRQChannel = EXTI15_10_IRQn;
}
if(GPIO_PinSourcex==13)
{
EXTI_InitStruct.EXTI_Line = EXTI_Line13;
NVIC_InitStruct.NVIC_IRQChannel = EXTI15_10_IRQn;
}
if(GPIO_PinSourcex==14)
{
EXTI_InitStruct.EXTI_Line = EXTI_Line14;
NVIC_InitStruct.NVIC_IRQChannel = EXTI15_10_IRQn;
}
if(GPIO_PinSourcex==15)
{
EXTI_InitStruct.EXTI_Line = EXTI_Line15;
NVIC_InitStruct.NVIC_IRQChannel = EXTI15_10_IRQn;
}
EXTI_InitStruct.EXTI_LineCmd = ENABLE;//使能选中的外部中断线
EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;//选择中断事件
EXTI_InitStruct.EXTI_Trigger = EXTITrigger;//选择触发源
EXTI_Init(&EXTI_InitStruct);
//配置NVIC中断
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 1;
NVIC_Init(&NVIC_InitStruct);
}
void EXTI0_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line0)==SET)
{
GuiStar_EXTI0_IRQHandler();
EXTI_ClearITPendingBit(EXTI_Line0);
}
}
void EXTI1_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line1)==SET)
{
GuiStar_EXTI1_IRQHandler();
EXTI_ClearITPendingBit(EXTI_Line1);
}
}
void EXTI2_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line2)==SET)
{
GuiStar_EXTI2_IRQHandler();
EXTI_ClearITPendingBit(EXTI_Line2);
}
}
void EXTI3_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line3)==SET)
{
GuiStar_EXTI3_IRQHandler();
EXTI_ClearITPendingBit(EXTI_Line3);
}
}
void EXTI4_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line4)==SET)
{
GuiStar_EXTI4_IRQHandler();
EXTI_ClearITPendingBit(EXTI_Line4);
}
}
void EXTI15_10_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line10)==SET)
{
GuiStar_EXTI15_10_IRQHandler();
EXTI_ClearITPendingBit(EXTI_Line10);
}
else if(EXTI_GetITStatus(EXTI_Line11)==SET)
{
GuiStar_EXTI15_10_IRQHandler();
EXTI_ClearITPendingBit(EXTI_Line11);
}
else if(EXTI_GetITStatus(EXTI_Line12)==SET)
{
GuiStar_EXTI15_10_IRQHandler();
EXTI_ClearITPendingBit(EXTI_Line12);
}
else if(EXTI_GetITStatus(EXTI_Line13)==SET)
{
GuiStar_EXTI15_10_IRQHandler();
EXTI_ClearITPendingBit(EXTI_Line13);
}
else if(EXTI_GetITStatus(EXTI_Line14)==SET)
{
GuiStar_EXTI15_10_IRQHandler();
EXTI_ClearITPendingBit(EXTI_Line14);
}
else if(EXTI_GetITStatus(EXTI_Line15)==SET)
{
GuiStar_EXTI15_10_IRQHandler();
EXTI_ClearITPendingBit(EXTI_Line15);
}
}
void EXTI9_5_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line5)==SET)
{
GuiStar_EXTI9_5_IRQHandler();
EXTI_ClearITPendingBit(EXTI_Line5);
}
else if(EXTI_GetITStatus(EXTI_Line6)==SET)
{
GuiStar_EXTI9_5_IRQHandler();
EXTI_ClearITPendingBit(EXTI_Line6);
}
else if(EXTI_GetITStatus(EXTI_Line7)==SET)
{
GuiStar_EXTI9_5_IRQHandler();
EXTI_ClearITPendingBit(EXTI_Line7);
}
else if(EXTI_GetITStatus(EXTI_Line8)==SET)
{
GuiStar_EXTI9_5_IRQHandler();
EXTI_ClearITPendingBit(EXTI_Line8);
}
else if(EXTI_GetITStatus(EXTI_Line9)==SET)
{
GuiStar_EXTI9_5_IRQHandler();
EXTI_ClearITPendingBit(EXTI_Line9);
}
}
|