51单片机——控制步进电机加速、减速及反转

加速:

#include
#define uchar unsigned char
#define uint  unsigned int
#define MotorData P1                    
uchar phasecw[4] ={0x08,0x04,0x02,0x01};//正转 电机导通相序 D-C-B-A
uchar phaseccw[4]={0x01,0x02,0x04,0x08};//反转 电机导通相序 A-B-C-D
uchar speed;
//延时
void Delay_xms(uint x)
{
 uint i,j;
 for(i=0;i

减速:

#include
#define uchar unsigned char
#define uint  unsigned int
#define MotorData P1                    
uchar phasecw[4] ={0x08,0x04,0x02,0x01};
uchar phaseccw[4]={0x01,0x02,0x04,0x08};
uchar speed;

void Delay_xms(uint x)
{
 uint i,j;
 for(i=0;i25)  
  {
   speed=4;    
   MotorStop();
   Delay_xms(500);
  }  
 }
}

正反转:

#include
#define uchar unsigned char
#define uint  unsigned int
#define MotorData P1                
uchar phasecw[4] ={0x08,0x04,0x02,0x01};
uchar phaseccw[4]={0x01,0x02,0x04,0x08};

void Delay_xms(uint x)
{
 uint i,j;
 for(i=0;i

你可能感兴趣的:(单片机)