标题: 四相步进电机正反那个旋转180度单片机程序,电机正反转函数中i代表什么,为什么小... [打印本页]

作者: 午夜里    时间: 2021-6-14 14:38
标题: 四相步进电机正反那个旋转180度单片机程序,电机正反转函数中i代表什么,为什么小...
#include "motor_bujin.h"


/****
******电机转速调节
*****/
void StepDelay(unsigned int t)
{                           
        unsigned int k;
        while(t--)
        {
                for(k=0; k<80; k++)
                { }
        }
}

/****
*******电机正转函数
*****/
void  Motor_Foreward()
{
        unsigned int i;

        for(i=0;i<256;i++)
        {
                GPIO_MOTOR_1 = 1;
                GPIO_MOTOR_2 = 0;
                GPIO_MOTOR_3 = 0;
                GPIO_MOTOR_4 = 1;
                StepDelay(1);
               
                GPIO_MOTOR_1 = 0;
                GPIO_MOTOR_2 = 0;
                GPIO_MOTOR_3 = 0;
                GPIO_MOTOR_4 = 1;
                StepDelay(1);
               
                GPIO_MOTOR_1 = 0;
                GPIO_MOTOR_2 = 0;
                GPIO_MOTOR_3 = 1;
                GPIO_MOTOR_4 = 1;
                StepDelay(1);
               
                GPIO_MOTOR_1 = 0;
                GPIO_MOTOR_2 = 0;
                GPIO_MOTOR_3 = 1;
                GPIO_MOTOR_4 = 0;
                StepDelay(1);
               
                GPIO_MOTOR_1 = 0;
                GPIO_MOTOR_2 = 1;
                GPIO_MOTOR_3 = 1;
                GPIO_MOTOR_4 = 0;
                StepDelay(1);
               
                GPIO_MOTOR_1 = 0;
                GPIO_MOTOR_2 = 1;
                GPIO_MOTOR_3 = 0;
                GPIO_MOTOR_4 = 0;
                StepDelay(1);
               
                GPIO_MOTOR_1 = 1;
                GPIO_MOTOR_2 = 1;
                GPIO_MOTOR_3 = 0;
                GPIO_MOTOR_4 = 0;
                StepDelay(1);
               
                GPIO_MOTOR_1 = 1;
                GPIO_MOTOR_2 = 0;
                GPIO_MOTOR_3 = 0;
                GPIO_MOTOR_4 = 0;
                StepDelay(1);
        }
}

/****
*****电机反转函数
*****/
void  Motor_Reversal()
{
        unsigned int i;

        for(i=0;i<256;i++)
        {
                GPIO_MOTOR_1 = 1;
                GPIO_MOTOR_2 = 0;
                GPIO_MOTOR_3 = 0;
                GPIO_MOTOR_4 = 0;
                StepDelay(1);
               
                GPIO_MOTOR_1 = 1;
                GPIO_MOTOR_2 = 1;
                GPIO_MOTOR_3 = 0;
                GPIO_MOTOR_4 = 0;
                StepDelay(1);
               
                GPIO_MOTOR_1 = 0;
                GPIO_MOTOR_2 = 1;
                GPIO_MOTOR_3 = 0;
                GPIO_MOTOR_4 = 0;
                StepDelay(1);
               
                GPIO_MOTOR_1 = 0;
                GPIO_MOTOR_2 = 1;
                GPIO_MOTOR_3 = 1;
                GPIO_MOTOR_4 = 0;
                StepDelay(1);
               
                GPIO_MOTOR_1 = 0;
                GPIO_MOTOR_2 = 0;
                GPIO_MOTOR_3 = 1;
                GPIO_MOTOR_4 = 0;
                StepDelay(1);
               
                GPIO_MOTOR_1 = 0;
                GPIO_MOTOR_2 = 0;
                GPIO_MOTOR_3 = 1;
                GPIO_MOTOR_4 = 1;
                StepDelay(1);
               
                GPIO_MOTOR_1 = 0;
                GPIO_MOTOR_2 = 0;
                GPIO_MOTOR_3 = 0;
                GPIO_MOTOR_4 = 1;
                StepDelay(1);
               
                GPIO_MOTOR_1 = 1;
                GPIO_MOTOR_2 = 0;
                GPIO_MOTOR_3 = 0;
                GPIO_MOTOR_4 = 1;
                StepDelay(1);
        }
}







欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1