STM32F103的GPIO作为中止来完成外部中止触发,相关程序如下:
端口装备:
void GPIO_Configuration(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC , ENABLE);
GPIO_InitStructure.GPIO_Pin = IR_int_IN|IR_int_OUT; //IR_int 作为输入
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING ; //输入
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
//时钟装备
void RCC_Configuration(void)
{
SystemInit();
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
RCC_APB2PeriphClockCmd( | RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, ENABLE);
}
//中止装备
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure the NVIC Preemption Priority Bits */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); // 抢占式优先等级
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; //指定中止源
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; // 指定呼应优先等级1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/////////////////GPIO中止处理函数/////////////
void EXTI9_5_IRQHandler(void)
{
IWDG_ReloadCounter();//喂狗
if (EXTI_GetITStatus(EXTI_Line6) != RESET)
{
//增加中止处理程序
speakertest();
EXTI_ClearFlag(EXTI_Line6);
}
if (EXTI_GetITStatus(EXTI_Line7) != RESET)
{
//增加中止处理程序
speakertest();
EXTI_ClearFlag(EXTI_Line7);
}
}