void timer2_init(void) { TIM2_NVIC_Configuration(); TIM2_Configuration(); // timer2_disable(); }
/* * 函数名:main * 描述 :主函数 * 输入 :无 * 输出 :无 */ int main(void) { /* 配置系统时钟为 72M */ SystemInit(); /* led 端口配置 */ LED_GPIO_Config(); /* TIM2 定时配置 */ TIM2_NVIC_Configuration(); TIM2_Configuration(); /* TIM2 开始计时 */ START_TIME; while(1) { if ( time == 1000 ) /* 1s 时间到 */ { time = 0; /* LED1 取反 */ GPIO_WriteBit(GPIOE, GPIO_Pin_5, (BitAction)((1-GPIO_ReadOutputDataBit(GPIOE, GPIO_Pin_5)))); } } }
/** * @brief * @param 无 * @retval 无 */ int main(void) { /* USART1 115200 8-N-1, */ USART1_Config(); NVIC_Configuration(); /* 10us*/ SysTick_Init(); MOTOR_GPIO_Config(); TIM2_Configuration(); TIM2_NVIC_Configuration(); RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 , ENABLE); //printf(READY); printf("POLARGRAPH ON!"); setAcceleration(&motorA,currentAcceleration); setAcceleration(&motorB,currentAcceleration); mmPerStep = mmPerRev / motorStepsPerRev; stepsPerMM = motorStepsPerRev / mmPerRev; motorA._name = 0; motorB._name = 1; setAcceleration(&motorA,currentAcceleration); setAcceleration(&motorB,currentAcceleration); pixel_drawSquarePixel(990,486,18,23); for(;;) { if(getNewComms) { exec_executeBasicCommand(); getNewComms = 0; } } }
int main(void) { uint16_t i; NVIC_Configuration(); delay_init(); //延时函数初始化 uart_init(9600); //串口初始化为9600 Dac1_Init(); //DAC通道1初始化 TIM2_NVIC_Configuration(); TIM2_Configuration(25*360/STEP); //生成数据 for(i=0; i<360; i++) { sine_table1[i] = (uint16_t)((sin((i*PI)/180) + 1)*4095/2); sine_table2[i] = (uint16_t)((sin((i*PI)/180 + PHA_DIFF) + 1)*4095/2); } while(1) { } }
/** * @brief 主函数 * @param 无 * @retval 无 */ int main(void) { /* led 端口配置 */ LED_GPIO_Config(); /* TIM2 定时配置 */ TIM2_Configuration(); /* 实战定时器的中断优先级 */ TIM2_NVIC_Configuration(); /* TIM2 重新开时钟,开始计时 */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 , ENABLE); while(1) { if ( time == 1000 ) /* 1000 * 1 ms = 1s 时间到 */ { time = 0; /* LED1 取反 */ LED1_TOGGLE; } } }