将int main(void)函数里面的TIM_ARRPreloadConfig(TIM3, ENABLE);挪到下面的位置,似乎就不能装进影子寄存器了!!! void TIM_TimeBaseInit(TIM_TypeDef* TIMx, TIM_TimeBaseInitTypeDef* TIM_TimeBaseInitStruct) { /* Check the parameters */ assert_param(IS_TIM_123458_PERIPH(TIMx)); assert_param(IS_TIM_COUNTER_MODE(TIM_TimeBaseInitStruct->TIM_CounterMode)); assert_param(IS_TIM_CKD_DIV(TIM_TimeBaseInitStruct->TIM_ClockDivision)); /* Select the Counter Mode and set the clock division */ TIMx->CR1 = (uint16_t)0x0002; TIM_ARRPreloadConfig(TIM3, ENABLE); TIMx->CR1 &= CR1_CKD_Mask & CR1_CounterMode_Mask; TIMx->CR1 |= (uint32_t)TIM_TimeBaseInitStruct->TIM_ClockDivision | TIM_TimeBaseInitStruct->TIM_CounterMode; /* Set the Autoreload value */ TIMx->ARR = TIM_TimeBaseInitStruct->TIM_Period ;
/* Set the Prescaler value */ TIMx->PSC = TIM_TimeBaseInitStruct->TIM_Prescaler; if (((*(uint32_t*)&TIMx) == TIM1_BASE) || ((*(uint32_t*)&TIMx) == TIM8_BASE)) { /* Set the Repetition Counter value */ TIMx->RCR = TIM_TimeBaseInitStruct->TIM_RepetitionCounter; }
/* Generate an update event to reload the Prescaler value immediatly */ TIMx->EGR = TIM_PSCReloadMode_Immediate; }
以前的程序是数据先装进影子寄存器再令 APRE=1的,这样APRE的值根本没起作用。现在把那条语句挪位置先让APRE=1,这样就装不进影子寄存器了!!!!
可惜没示波器啊,MDK软件仿真不可信的!!
还有 我估计很有可能影子寄存器的初始值是65535
我就有个万利板子 根据灯的亮度做如上判断的!
|