博士
最后登录1970-1-1
在线时间 小时
注册时间2015-10-25
|
直接上代码
- void KEY_GPIO_Config(void)
- {
- GPIO_InitTypeDef GPIO_InitStruct;
- NVIC_InitTypeDef NVIC_InitStructure;
- EXTI_InitTypeDef EXTI_InitStructure;
-
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOC,ENABLE);
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
-
- GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;
- GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_DOWN;
- GPIO_Init(GPIOA , &GPIO_InitStruct);
-
- GPIO_InitStruct.GPIO_Pin = GPIO_Pin_13;
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;
- GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_DOWN;
- GPIO_Init(GPIOC , &GPIO_InitStruct);
-
- NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
-
- NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
-
- /* ᬽó EXTI ÖD¶ÏÔ′ μ½key1òy½Å */
- SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA,EXTI_PinSource0);
-
- EXTI_InitStructure.EXTI_Line = EXTI_Line0;
- EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
- EXTI_InitStructure.EXTI_LineCmd = ENABLE;
- EXTI_Init(&EXTI_InitStructure);
-
- /* ᬽó EXTI ÖD¶ÏÔ′ μ½key2 òy½Å */
- SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC,EXTI_PinSource13);
-
- EXTI_InitStructure.EXTI_Line = EXTI_Line13;
- EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
- EXTI_InitStructure.EXTI_LineCmd = ENABLE;
- EXTI_Init(&EXTI_InitStructure);
- }
复制代码 以上是按键配置
- void EXTI0_IRQHandler(void)
- {
- if(EXTI_GetITStatus(EXTI_Line0) != RESET)
- {
- LED_G_Toggle;
- EXTI_ClearITPendingBit(EXTI_Line0);
- }
- }
- void EXTI15_10_IRQHandler(void)
- {
- if(EXTI_GetITStatus(EXTI_Line13) != RESET)
- {
- LED_R_Toggle;
- EXTI_ClearITPendingBit(EXTI_Line13);
- }
- }
复制代码 以上是中断里面的
按下K1,绿灯闪烁,这是可以的
按下K2,没反应。
下载例程两个按键均有用
|
|