赞
踩
// ##################################################################
// file name : MD127.h Use step motor Stepping motor for 1-2 phase excitation
// ##################################################################
// 使用MD127芯片驱动15mm步进电机 两相四线步进马达 小型2相4线步进电机
/* STEP ANGLE: 18 Reduction Ratio: 100
类型:微型步进电机
电机直径 :15 mm
电机高度:有标10.3 mm/无标9.4mm
输出 轴直径:1.5 mm
输出轴长度:7.55 mm
接线方式:二相四线
(1脚2脚为一组 3脚4脚为一组)
电阻值:17 欧
步进角:18 度
重量:约 10 g
*/
// P1.0 - A+
// |
// )
// )
// |
// P1.1 - A-
// P1.2 - B+
// |
// )
// )
// |
// P1.3 - B-
// ==================================================================
// Step Angle = 18 / 100 * 50 = 9 (Reduction Ratio = 100)
unsigned char test_127=0; //相指针变量
sbit IN1_127=P1^0;
sbit IN2_127=P1^1;
sbit IN3_127=P1^2;
sbit IN4_127=P1^3;
void md127_step(bit in1_fg,bit in2_fg,bit in3_fg,bit in4_fg)//相转换函数
{
IN1_127=in1_fg;
IN2_127=in2_fg;
IN3_127=in3_fg;
IN4_127=in4_fg;
}
void md127_standby(void) //钳住相函数
{
IN1_127=0;
IN2_127=0;
IN3_127=0;
IN4_127=0;
}
void md127_keepmode(void)//保持上一输入状态函数
{
IN1_127=1;
IN2_127=1;
IN3_127=1;
IN4_127=1;
}
void md127_forward(void)//正向前进函数
{
switch(test_127)
{
case 0:
md127_step(1,0,0,0);
md127_keepmode();
break;
case 1:
md127_step(1,0,1,0);
md127_keepmode();
break;
case 2:
md127_step(0,0,1,0);
cmd127_keepmode();
break;
case 3:
md127_step(0,1,1,0);
md127_keepmode();
break;
case 4:
md127_step(0,1,0,0);
md127_keepmode();
break;
case 5:
cmd127_step(0,1,0,1);
md127_keepmode();
break;
case 6:
md127_step(0,0,0,1);
md127_keepmode();
break;
case 7:
md127_step(1,0,0,1);
md127_keepmode();
break;
default:break;
}
test_127++;
if(test_127>7)
test_127=0;
}
void md127_reverse(void)//反向函数
{
switch(test_127)
{
case 0:
md127_step(1,0,0,1);
md127_keepmode();
break;
case 1:
md127_step(0,0,0,1);
md127_keepmode();
break;
case 2:
md127_step(0,1,0,1);
md127_keepmode();
break;
case 3:
md127_step(0,1,0,0);
md127_keepmode();
break;
case 4:
md127_step(0,1,1,0);
md127_keepmode();
break;
case 5:
md127_step(0,0,1,0);
md127_keepmode();
break;
case 6:
md127_step(1,0,1,0);
md127_keepmode();
break;
case 7:
md127_step(1,0,0,0);
md127_keepmode();
break;
default:break;
}
test_127++;
if(test_127>7)
test_127=0;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。