|
#define DJ_CLOSE 255 //关
#define DJ_OPEN 0 //开
#define STEPP 8 //每步的时间
#define TIMECT 160 //定时参数
#define ATURNC 1024//脉冲数
const uchar motortbf[]={0x10,0x30,0x20,0x60,0x40,0xC0,0x80,0x90};//正转脉冲
void delay(uint t)
{
uchar i;
uint j;
for (i=0;i
for (j=0;j
}
void a_step(uchar d,uint t) //步进电机走一步,d=0正转,,d=255反转
{
if (d&0x01)
{
if (np==0)
np=7;
else np--;
}
else
{
if (np==7)
np=0;
else np++;
}
OUTPUT=motortbf[np]; //步进电机
delay(t);
}
//调用:关闭
if (open_flag==OFF)//关闭
{
nowstep=ATURNC;
open_flag=ON;
np=0;
OUTPUT=0; //步进电机复位
}
if(nowstep>0)
{
a_step(DJ_CLOSE,STEPP);
nowstep--;
}
//调用:开启
if (open_flag==ON)//开启
{
nowstep=0;
open_flag=OFF;
np=0;
OUTPUT=0; //步进电机复位
}
if(nowstep
{
a_step(DJ_OPEN,STEPP);
nowstep++;
} |
|