ut_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOC,&GPIO_InitStructure);
/*配置GPIOD的第一个管角为浮动输入*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOD,&GPIO_InitStructure);
/*配置GPIOB的第9个管脚为浮动输入*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB,&GPIO_InitStructure);
}
/**************************************************************
* 函数 SysTick_Configuration
* 描述 设置SysTick
* 输入 无
* 输出 无
* 返回值 无
***************************************************************/
void SysTick_Configuration(void)
{
/*配置 HCLK 时钟做为SysTick 时钟源*/
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8); //系统时钟8分频 72MHz
NVIC_SystemHandlerPriorityConfig(SystemHandler_SysTick, 8,2);
/*SysTick Interrupt each 1000Hz with HCLK equal to 72MHz*/
SysTick_SetReload(9000);//中断周期1ms
/*Enable the SysTick Interrupt */
SysTick_ITConfig(ENABLE);//打开中断
SysTick_CounterCmd(SysTick_Counter_Enable);
SysTick_CounterCmd(SysTick_Counter_Clear);
}
/******************************************************************************
* 函数名 EXTI_Configuration
* 描述 配置EXTI线
* 输入 无
* 输出 无
* 返回值 无
******************************************************************************/
void EXTI_Configuration(void){
/*将EXTI线0连接到PA0*/
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD,GPIO_PinSource4);
/*配置EXTI线0上出现下降沿,则产生中断*/
EXTI_InitStructure.EXTI_Line = EXTI_Line4;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
EXTI_GenerateSWInterrupt(EXTI_Line4);
/*将EXTI线9连接到PB9上*/
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource9);
/*将EXTI线9上出现下降沿产生中断*/
EXTI_InitStructure.EXTI_Line = EXTI_Line9;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
EXTI_GenerateSWInterrupt(EXTI_Line9);
}
中断函数:
void EXTI4_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line4)!= RESET){
EXTI_ClearITPendingBit(EXTI_Line4);
if(Ledflag == 0){
Ledflag = 1;
GPIOC->ODR |= 0X00000080;
}
else{
Ledflag = 0;
GPIOC->ODR &= 0XFFFFFF7F;
}
}
}
注:时钟设置的时候最好加上这句:
RCCRCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);// 使能AFIO时钟
|