EEPROM读取debug不正常release正常
这个超级无语,研究和半天,突然发现调到release就正常了,表现为写入看起来正常读取不正常,这个无语了,不想研究了
STVP下载不能够成功运行
本文摘录于:https://blog.csdn.net/qlexcel/article/details/71270780只是做学习备份之用,绝无抄袭之意,有疑惑请联系本人!
现在我都只用三根线来调试仿真!
定时器消抖莫名其妙的跑不通流程
这里做了一个定时器消抖功能,但是莫名其妙的无语了,竟然跑不通消抖算法,IO中断函数设置标志位:
/*** @brief External Interrupt PORTB Interrupt routine.* @param None* @retval None*/
INTERRUPT_HANDLER ( EXTI_PORTB_IRQHandler, 4 )
{/* In order to detect unexpected events during development,it is recommended to set a breakpoint on the following instruction.*/if(GPIO_ReadInputPin(KEY_LIGHTN_GPIO,KEY_LIGHTN_PIN)==0){//uart_printf("KEY_LIGHTN Irq\r\n" );key_judge=KEY_TYPE_LIGHTN;}if(GPIO_ReadInputPin(KEY_SWITCHP_GPIO,KEY_SWITCHP_PIN)==0){//uart_printf("KEY_SWITCHP Irq\r\n" );key_judge=KEY_TYPE_SWITCHP;}
}/*** @brief External Interrupt PORTC Interrupt routine.* @param None* @retval None*/
INTERRUPT_HANDLER ( EXTI_PORTC_IRQHandler, 5 )
{/* In order to detect unexpected events during development,it is recommended to set a breakpoint on the following instruction.*/if(GPIO_ReadInputPin(KEY_LIGHTP_GPIO,KEY_LIGHTP_PIN)==0){//uart_printf("KEY_LIGHTP Irq\r\n" );key_judge=KEY_TYPE_LIGHTP;}if(GPIO_ReadInputPin(KEY_SWITCHN_GPIO,KEY_SWITCHN_PIN)==0){//uart_printf("KEY_SWITCHN Irq\r\n" );key_judge=KEY_TYPE_SWITCHN;}
}/*** @brief External Interrupt PORTD Interrupt routine.* @param None* @retval None*/
INTERRUPT_HANDLER ( EXTI_PORTD_IRQHandler, 6 )
{/* In order to detect unexpected events during development,it is recommended to set a breakpoint on the following instruction.*/if(GPIO_ReadInputPin(KEY_OnOff_GPIO,KEY_OnOff_PIN)==0){//uart_printf("KEY_OnOff Irq\r\n" );key_judge=KEY_TYPE_OnOff;}
}
定时器中断设置标志位,然后在while主循环调用消抖函数:
// 定时器 20ms
void TIMER_Initializes( void )
{TIM2_TimeBaseInit( TIM2_PRESCALER_16, 20000 ); TIM2_ClearFlag( TIM2_FLAG_UPDATE ); //清除标志位TIM2_ITConfig( TIM2_IT_UPDATE, ENABLE ); //使能更新UPDATE中断enableInterrupts(); //使能全局中断TIM2_SetCounter( 0 ); //计数值归零TIM2_Cmd( ENABLE ); //启动定时器
}
uint16_t _ticks = 0;
INTERRUPT_HANDLER ( TIM2_UPD_OVF_BRK_IRQHandler, 13 )
{/* In order to detect unexpected events during development,it is recommended to set a breakpoint on the following instruction.*/TIM2_ClearITPendingBit ( TIM2_IT_UPDATE ); //清除中断标志_ticks++;timer_bit_flag.timer20ms_flag = 1;if ( _ticks % 25 == 0 ){timer_bit_flag.timer500ms_flag = 1;}else if ( _ticks % 50 == 0 ){timer_bit_flag.timer1000ms_flag = 1;}
}
void main ( void )
{uint8_t uart_rec_len;CLK_DeInit();CLK_LSICmd ( ENABLE );CLK_HSICmd ( ENABLE );while ( SET != CLK_GetFlagStatus ( CLK_FLAG_HSIRDY ) );CLK_SYSCLKConfig ( CLK_PRESCALER_CPUDIV1 );CLK_HSIPrescalerConfig ( CLK_PRESCALER_HSIDIV1 ); //HSI = 16M (1分频)GPIO_Configuration();TIMER_Initializes();UART_Initializes();//ADC_Initializes();eeprom_init();timer1_init();enableInterrupts(); //使能全局中断if(g_config.PowerOff){rgb_SetCompare(0,0,0);uart_printf("Device PowerOff\r\n");}while ( 1 ){if ( timer_bit_flag.timer20ms_flag == 1 ){timer_bit_flag.timer20ms_flag = 0;user_timer_handler();}
消抖函数处理完成后调用key_handle函数进行处理,这里出现一个莫名其妙的问题,竟然没有进入下面的语句清除变量,无语了,我的天了,老哥撸代码十来年,搞了大半天,投降了,最后用了在中断中直接进行定时器消抖,无语了!记录再次,以后如果悟到了再来改
int8_t key_state_read(void)
{switch(key_judge){case KEY_TYPE_LIGHTP:if(GPIO_ReadInputPin(KEY_LIGHTP_GPIO,KEY_LIGHTP_PIN)==0) return ((uint8_t)KEY_TYPE_LIGHTP);else return 0;case KEY_TYPE_LIGHTN:if(GPIO_ReadInputPin(KEY_LIGHTN_GPIO,KEY_LIGHTN_PIN)==0) return ((uint8_t)KEY_TYPE_LIGHTN);else return 0;case KEY_TYPE_SWITCHP:if(GPIO_ReadInputPin(KEY_SWITCHP_GPIO,KEY_SWITCHP_PIN)==0) return ((uint8_t)KEY_TYPE_SWITCHP);else return 0;case KEY_TYPE_SWITCHN:if(GPIO_ReadInputPin(KEY_SWITCHN_GPIO,KEY_SWITCHN_PIN)==0) return ((uint8_t)KEY_TYPE_SWITCHN);else return 0;case KEY_TYPE_OnOff:if(GPIO_ReadInputPin(KEY_OnOff_GPIO,KEY_OnOff_PIN)==0) return ((uint8_t)KEY_TYPE_OnOff);else return 0;default:return 0;}}
void user_timer_handler(void)
{if(key_judge!=KEY_TYPE_IDLE){if(key_state_read()!=0){ key_loop++;if(key_loop==100){//uart_printf("loop long\r\n");key_handle(key_judge,KEY_ACTION_LONG);key_loop=0;key_judge=KEY_TYPE_IDLE;}}else{if((key_loop>=1)&&(key_loop<100)){ key_handle(key_judge,KEY_ACTION_SHORT);}key_loop=0;//没有进入这里清除变量key_judge=KEY_TYPE_IDLE;} }
}