mcu:ch32v003j4m6
于Pin5/6引腳連接了一個TM1650,Pin7上連接了TM1650的按鍵中斷輸出,當(dāng)前代碼能進入中斷,讀取到按鍵值。
但,僅能中斷一次,第二次按鍵就無法產(chǎn)生中斷。
請看代碼如下:
初始化代碼 void?TM1650_Init(void) { GPIO_InitTypeDef?GPIO_InitStructure?= {?0?}; EXTI_InitTypeDef?EXTI_InitStructure?= {?0?}; NVIC_InitTypeDef?NVIC_InitStructure?= {?0?}; //?Configure?PC1(SDA)?and?PC2(SCL)?as?output RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO?|?RCC_APB2Periph_GPIOC,?ENABLE); GPIO_InitStructure.GPIO_Pin?=?GPIO_Pin_1?|?GPIO_Pin_2; GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_Out_OD; GPIO_InitStructure.GPIO_Speed?=?GPIO_Speed_50MHz; GPIO_Init(GPIOC,?&GPIO_InitStructure); //?Configure?PC4?as?input?for?key?interrupt GPIO_InitStructure.GPIO_Pin?=?GPIO_Pin_4; GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_IPU; GPIO_Init(GPIOC,?&GPIO_InitStructure); //?Configure?EXTI?for?PC4 GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,?GPIO_PinSource4); 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); //?Configure?NVIC?for?EXTI7_0 NVIC_InitStructure.NVIC_IRQChannel?=?EXTI7_0_IRQn;?//?Changed?from?EXTI4_IRQn?to?EXTI7_0_IRQn NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority?=?1; NVIC_InitStructure.NVIC_IRQChannelSubPriority?=?2; NVIC_InitStructure.NVIC_IRQChannelCmd?=?ENABLE; NVIC_Init(&NVIC_InitStructure); //?Initialize?TM1650 GPIO_SetBits(GPIOC,?GPIO_Pin_1);????//?SDA?High GPIO_SetBits(GPIOC,?GPIO_Pin_2);????//?SCL?High Delay_Ms(500); TM1650_SetSystem(0x00,?0x08,?0x00,?0x01);//?1級亮度+7段模式+正常工作模式+開顯示 Delay_Ms(10); TM1650_WriteDIG(0x68,?0); TM1650_WriteDIG(0x6A,?11); TM1650_WriteDIG(0x6C,?11); TM1650_WriteDIG(0x6E,?11); }
中斷代碼 void?EXTI7_0_IRQHandler(void)?__attribute__((interrupt("WCH-Interrupt-fast"))); //?EXTI7_0?Interrupt?Handler?for?TM1650?Key void?EXTI7_0_IRQHandler(void)?//?Changed?from?EXTI4_IRQHandler?to?EXTI7_0_IRQHandler { if?(EXTI_GetITStatus(EXTI_Line4)?!=?RESET) { uint8_t?key_value?=?TM1650_ReadKey(); UART_Send_Info(key_value); EXTI_ClearITPendingBit(EXTI_Line4); } }