stm32步进电机驱动源程序如下:
- #include "led.h"
- #include "delay.h"
- #include "sys.h"
- #include "usart.h"
- #include "master_slave.h"
- #include "stm32f10x_tim.h"
- //#include "key.h"
- //#include "timer.h"
- int main(void)
- {
- delay_init(); //延时函数初始化
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
- uart_init(115200); //串口初始化为115200
- LED_Init(); //LED端口初始化
-
- LED0=0;
- TIM3_CH1_init();
- delay_ms(200);
-
-
- while(1)
- {
- LED0=1;
- TIM2_TIM3_PWM(2000, 12); //每次少10个脉冲
- delay_ms(200);
-
- LED0=0;
- TIM2_TIM3_PWM(2000, 25); //每次少10个脉冲
- delay_ms(250);
-
- LED0=1;
- TIM2_TIM3_PWM(2000, 16); //每次少10个脉冲
- delay_ms(100);
-
- LED0=0;
- TIM2_TIM3_PWM(2000, 35); //每次少10个脉冲
- delay_ms(150);
-
- }
- }
复制代码
所有资料51hei提供下载:
频率 脉冲可控,驱动步进电机.rar
(2.19 KB, 下载次数: 154)
|