加速:
#include<reg52.h>
#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<x;i++)
  for(j=0;j<112;j++);
}
//电机顺时针转动
void MotorCW(void)
{
 uchar i;
 for(i=0;i<4;i++)
  {
   MotorData=phasecw[i];
   Delay_xms(speed);
  }
}
//停转
void MotorStop(void)
{
 MotorData=0x00;
}
void main(void)
{
 uint i;
 Delay_xms(50);//等待系统稳定
 speed=25;
 while(1)
 {
 for(i=0;i<10;i++)
  {
   MotorCW();  
  }  
  speed--;     //加速
  if(speed<4)  
  {
   speed=25;    
   MotorStop();
   Delay_xms(500);
  }  
 }
}
减速:
#include<reg52.h>
#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;i<x;i++)
  for(j=0;j<112;j++);
}
void MotorCW(void)
{
 uchar i;
 for(i=0;i<4;i++)
  {
   MotorData=phasecw[i];
   Delay_xms(speed);
  }
}
void MotorStop(void)
{
 MotorData=0x00;
}
void main(void)
{
 uint i;
 Delay_xms(50);
 speed=4;
 while(1)
 {
 for(i=0;i<10;i++)
  {
   MotorCW();  
  }  
  speed++;     //减速
  if(speed>25)  
  {
   speed=4;    
   MotorStop();
   Delay_xms(500);
  }  
 }
}
正反转:
#include<reg52.h>
#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<x;i++)
  for(j=0;j<112;j++);
}
void MotorCW(void)
{
 uchar i;
 for(i=0;i<4;i++)
  {
   MotorData=phasecw[i];
   Delay_xms(4);
  }
}
void MotorCCW(void)
{
 uchar i;
 for(i=0;i<4;i++)
  {
   MotorData=phaseccw[i];
   Delay_xms(4);
  }
}
void MotorStop(void)
{
 MotorData=0x00;
}
void main(void)
{
 uint i;
 Delay_xms(50);
 while(1)
 {
  for(i=0;i<500;i++)
  {
   MotorCW();   //顺时针转动
  } 
  MotorStop();  //停转
  Delay_xms(500);
  for(i=0;i<500;i++)
  {
   MotorCCW();  //逆时针转动
  } 
  MotorStop();  //停转
  Delay_xms(500);  
 }
}
 
                   
                   
                   
                   
                             本文介绍了一种使用51单片机实现电机控制的方法,包括电机的加速、减速和正反转控制。通过定义电机导通相序,利用延时函数实现速度控制,展示了如何在单片机上实现电机的基本操作。
本文介绍了一种使用51单片机实现电机控制的方法,包括电机的加速、减速和正反转控制。通过定义电机导通相序,利用延时函数实现速度控制,展示了如何在单片机上实现电机的基本操作。
           
       
           
                 
                 
                 
                 
                 
                
               
                 
                 
                 
                 
                
               
                 
                 扫一扫
扫一扫
                     
              
             
                   4万+
					4万+
					
 被折叠的  条评论
		 为什么被折叠?
被折叠的  条评论
		 为什么被折叠?
		 
		  到【灌水乐园】发言
到【灌水乐园】发言                                
		 
		 
    
   
    
   
             
            


 
            