The stc timer is abnormal (how to modify the initial value timing time is 100ms)

Solution: Manually calculate the initial value, or add UL after the data type
Reason: The data type is wrong, resulting in overflow (probably)
Study notes: How to time 10ms for 51 single-chip microcomputer (STC89C52)

 TIM_InitStructure.TIM_ClkSource = TIM_CLOCK_12T;	//指定时钟源,     TIM_CLOCK_1T,TIM_CLOCK_12T,TIM_CLOCK_Ext
    TIM_InitStructure.TIM_ClkOut    = ENABLE;					//是否输出高速脉冲, ENABLE或DISABLE
    TIM_InitStructure.TIM_Value     = 65536UL - (MAIN_Fosc / (10000UL*12));		//初值
    TIM_InitStructure.TIM_Run       = ENABLE;					//是否初始化后启动定时器, ENABLE或DISABLE
    Timer_Inilize(Timer2,&TIM_InitStructure);					//初始化Timer4	  Timer0,Timer1,Timer2,Timer3,Timer4
    NVIC_Timer2_Init(ENABLE,NULL);		//中断使能, ENABLE/DISABLE; 无优先级

insert image description here
insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/GQ_Sonofgod/article/details/125758869