硬件选择:某宝上有卖,一块驱动板加一个5V小步进电机大概是10块钱,这种套装一般用来做摄像头转动等等,因为电机跟驱动板较小,力量小,易发热。

一共3种程序,减速、加速、正反转,需要哪种自己选择。 ****************************************************
*** 减速: 接线方式: IN1 ---- P00 IN2 ---- P01 IN3 ---- P02 IN4 ---- P03 + ---- +5V -
---- GND *********************/ #include<reg52.h> #define uchar unsigned char #
define uint unsigned int #define MotorData P0 //步进电机控制接口定义 uchar phasecw[4] ={
0x08,0x04,0x02,0x01};//正转 电机导通相序 D-C-B-A uchar phaseccw[4]={0x01,0x02,0x04,0x08}
;//反转 电机导通相序 A-B-C-D uchar speed; //ms延时函数 void Delay_xms(uint x) { uint i,j;
for(i=0;i<x;i++) for(j=0;j<112;j++); } //顺时针转动 void MotorCW(void) { uchar i; for
(i=0;i<4;i++) { MotorData=phasecw[i]; Delay_xms(speed);//转速调节 } } //停止转动 void
MotorStop(void) { MotorData=0x00; } //主函数 void main(void) { uint i; Delay_xms(50
);//等待系统稳定 speed=4; while(1) { for(i=0;i<10;i++) { MotorCW(); //顺时针转动 } speed++;
//减速 if(speed>25) { speed=4; //重新开始减速运动 MotorStop(); Delay_xms(500); } } } *****
************************************************** 加速: 接线方式: IN1 ---- P00 IN2 --
-- P01 IN3 ---- P02 IN4 ---- P03 + ---- +5V - ---- GND *********************/ #
include<reg52.h> #define uchar unsigned char #define uint unsigned int #define
MotorData P0//步进电机控制接口定义 uchar phasecw[4] ={0x08,0x04,0x02,0x01};//正转 电机导通相序
D-C-B-A uchar phaseccw[4]={0x01,0x02,0x04,0x08};//反转 电机导通相序 A-B-C-D uchar speed;
//ms延时函数 void Delay_xms(uint x) { uint i,j; for(i=0;i<x;i++) for(j=0;j<112;j++);
} //顺时针转动 void MotorCW(void) { uchar i; for(i=0;i<4;i++) { MotorData=phasecw[i];
Delay_xms(speed);//转速调节 } } //停止转动 void MotorStop(void) { MotorData=0x00; }
//主函数 void main(void) { uint i; Delay_xms(50);//等待系统稳定 speed=25; while(1) { for(
i=0;i<10;i++) { MotorCW(); //顺时针转动 } speed--; //减速 if(speed<4) { speed=25;
//重新开始减速运动 MotorStop(); Delay_xms(500); } } } **********************************
********************* 正反转: 接线方式: IN1 ---- P00 IN2 ---- P01 IN3 ---- P02 IN4 ----
P03+ ---- +5V - ---- GND *********************/ #include<reg52.h> #define
uchar unsigned char #define uint unsigned int #define MotorData P0 //步进电机控制接口定义
uchar phasecw[4] ={0x08,0x04,0x02,0x01};//正转 电机导通相序 D-C-B-A uchar phaseccw[4]={
0x01,0x02,0x04,0x08};//反转 电机导通相序 A-B-C-D //ms延时函数 void Delay_xms(uint x) { uint
i,j; for(i=0;i<x;i++) for(j=0;j<112;j++); } //顺时针转动 void MotorCW(void) { uchar i
; for(i=0;i<4;i++) { MotorData=phasecw[i]; Delay_xms(4);//转速调节 } } //逆时针转动 void
MotorCCW(void) { uchar i; for(i=0;i<4;i++) { MotorData=phaseccw[i]; Delay_xms(4)
;//转速调节 } } //停止转动 void MotorStop(void) { MotorData=0x00; } //主函数 void main(void
) { uint i; Delay_xms(50);//等待系统稳定 while(1) { for(i=0;i<500;i++) { MotorCW();
//顺时针转动 } MotorStop(); //停止转动 Delay_xms(500); for(i=0;i<500;i++) { MotorCCW();
//逆时针转动 } MotorStop(); //停止转动 Delay_xms(500); } }
驱动板原理图:

技术
今日推荐
PPT
阅读数 99
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:766591547
关注微信