//有加减速的,我自己写的。大概原理你们应该能理解,我写的不是太难。

#ifndef __motor_h
#define __motor_h
///////////
#include "stm32f10x.h"
#include "delay.h"
//////////
//作者QQ750273008 祁成 2018.5.29
//两相四线,步进电机线圈节拍:A-AB-B-A'B-A'-A'B'-B'-AB'
static const u8 motor[]={0X00,0x08,0x0A,0X02,0X06,0X04,0X05,0X01,0X09};//步进电机,停止+8种节拍
//typedef enum {FALSE = 0, TRUE = !FALSE} bool;
typedef struct
{
u8 num; //电机轴的编号0~0xFF
const u8 *R8; //步进电机节拍:停止+8种节拍
u8 r8; //电机当前节拍位置
int add; //当前绝对位置
int go; //预计移动
//加减速参数
u32 dead; //最小死区时间(最快速度)//迷你滑台小于0x2000 步进电机丢步
u32 delay; //电机转一拍停留时间(必须大于死区延时)
u16 VF; //加减速曲线,(值越大,加减速越快)
}motors;
//电机默认参数表
static motors zhou={0,motor,1,1,0,0xFFF,0xfffff,255};
//static motors zhou={1,(u8*)motor,1,1,300};
//当前可用轴
static motors
zhouX={0xF1,motor,1,1,0,300},
zhouY={0xF2,motor,1,1,0,300},
zhouZ={0xF3,motor,1,1,0,300},
zhouA={0xFA,motor,1,1,0,300},
zhouB={0xFB,motor,1,1,0,300},
zhouC={0xFC,motor,1,1,0,300};
static motors zhou1={0x01,motor,1,1,0,0x1800,0xffff,255};
//static motors zhou1,zhou2,zhou3,zhou4,zhou5,zhou6,zhou7,zhou8,zhou9;
//static motors zhou10,zhou11,zhou12,zhou13,zhou14,zhou15;
//////////////
void motor_init(void);//初始化
u8 motorGo(motors *x,int go);//轴移动
u8 motorGoto(motors *x,int Goto);//轴定位
#endif
|