按照野火的例程改变
把一个加成两个,给时钟的时候用或连接,然后先后初始化
中断服务函数也写了
第一个按键没有问题,第二个按键按得时候,led不会马上反转,而会在第一个按键按下的时候才反转
就是状态是由第二个按键决定的,但是第一个按键按下才会表现出来
下面是中断按键的c文件
- #include "bsp_exti_key.h"
- /**
- * @brief ÅäÖÃǶÌ×ÏòÁ¿ÖжϿØÖÆÆ÷NVIC
- * @param ÎÞ
- * @retval ÎÞ
- */
- static void NVIC_Configuration(void)
- {
- NVIC_InitTypeDef NVIC_InitStructure;
-
- /* Configure one bit for preemption priority Ñ¡ÔñÓÅÏȼ¶×é±ð*/
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
-
- /* ÅäÖÃÖжÏÔ´ */
- NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
-
- NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- }
- /**
- * @brief ÅäÖà PA0 ΪÏßÖжϿڣ¬²¢ÉèÖÃÖжÏÓÅÏȼ¶
- * @param ÎÞ
- * @retval ÎÞ
- */
- void EXTI_PA0_Config(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- EXTI_InitTypeDef EXTI_InitStructure;
- /* config the extiline clock and AFIO clock */
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO,ENABLE);
-
- /* config the NVIC */
- NVIC_Configuration();
- /* EXTI line gpio config*/
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; // ÉÏÀÊäÈë
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- /* EXTI line mode config */
- GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource0);
- EXTI_InitStructure.EXTI_Line = EXTI_Line0;
- EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //ϽµÑØÖжÏ
- EXTI_InitStructure.EXTI_LineCmd = ENABLE;
- EXTI_Init(&EXTI_InitStructure);
- }
- void EXTI_PC13_Config(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- EXTI_InitTypeDef EXTI_InitStructure;
- /* config the extiline clock and AFIO clock */
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO,ENABLE);
-
- /* config the NVIC */
- NVIC_Configuration();
- /* EXTI line gpio config*/
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; // ÉÏÀÊäÈë
- GPIO_Init(GPIOC, &GPIO_InitStructure);
- /* EXTI line mode config */
- GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource13);
- EXTI_InitStructure.EXTI_Line = EXTI_Line13;
- EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //ϽµÑØÖжÏ
- EXTI_InitStructure.EXTI_LineCmd = ENABLE;
- EXTI_Init(&EXTI_InitStructure);
- }
复制代码
这个问题我已经解决了。你遇到类似问题了吗?
一周热门 更多>