|
int main(void)
{
unsigned char n_Counter;
#ifdef DEBUG
debug();
#endif
RCC_Configuration(); // System Clocks Configuration
NVIC_Configuration(); // NVIC configuration
GPIO_Configuration(); // Configure the GPIO ports
TIM_TimeBaseStructure.TIM_Period = 0x0400;
TIM_TimeBaseStructure.TIM_Prescaler = 0x00;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); // Time base configuration
TIM_ETRClockMode2Config(TIM2, TIM_ExtTRGPSC_OFF, TIM_ExtTRGPolarity_NonInverted, 0);
TIM_SetCounter(TIM2, 0);
TIM_Cmd(TIM2, ENABLE);
while (1)
{
if (n_Counter<0x0400)
n_Counter = TIM_GetCounter(TIM2);
else
{ TIM_SetCounter(TIM2, 0);
TIM_Cmd(TIM2, ENABLE);
n_Counter = TIM_GetCounter(TIM2);
}
}
}这样写对吗 |
|