⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stepmotor.c

📁 0834实现数据的采集
💻 C
字号:
//start date:   2005.3.23
//competed date:
//function:     display text
#include <reg52.h>
#include <intrins.h>
#define  uchar unsigned char
#define  uint  unsigned int
#define  ulong unsigned long int
#define  FLASE  0
#define  TRUE   1
//========================================================
//========控制脚定义======================================

sbit CLK1_164=P3^1;
sbit DAT1_164=P3^0;
sbit LE_373 =P3^2;
//========函数声明========================================
void StepIM(uchar a,uchar b);
void  StopMotor();
void HC164_1(uchar a);
uchar code MOTOR1[]={0x2f,0x2b,0x2b,0x2d,0x2d,0x1d,0x1d,0x3d,0x35,0x15,0x15,0x25,0x25,0x23,0x23,0x27,
                     0x26,0x22,0x22,0x24,0x24,0x14,0x14,0x34,0x3c,0x1c,0x1c,0x2c,0x2c,0x2a,0x2a,0x2e};
uchar code MOTOR2[]={0x0f,0x0b,0x0b,0x2d,0x2d,0x19,0x19,0x39,0x31,0x11,0x11,0x25,0x25,0x03,0x03,0x07,
                     0x06,0x02,0x02,0x24,0x24,0x10,0x10,0x30,0x38,0x18,0x18,0x2c,0x2c,0x0a,0x0a,0x0e};
uchar code MOTOR3[]={0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
                     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08};
void HC164_1(uchar a)
{
     uchar i,temp;
     temp=a;
	 LE_373=0;
     CLK1_164=0;
     for(i=0;i<8;i++)
     {
       if(temp&0x80)
         DAT1_164=1;
       else
         DAT1_164=0;
         CLK1_164=1;
         temp=_crol_(temp,1);
         CLK1_164=0;	
     }
	 LE_373=1;
     DAT1_164=1;
	 LE_373=1;
	 LE_373=0;
	 CLK1_164=1;
}
/********************************************************************
* 名称: 步进电机驱动
* 功能: 控制步进电机速度及运行周期
* 调用: StepIM(uchar a,uchar b)
* 输入: speed,stepperset
* 说明: speed 调整电机转速:1代表每一步为1MS,每步3.75度。
* 返回值: StopFlag:1为stop ,0为run
***********************************************************************/
void  StepperDrive0()
{
  static uchar i;
        if(i>31)
        i=0;
        HC164_1(MOTOR1[i++]);
}
//=================================================
void  StepperDrive1()
{
  static uchar i;
        if(i>31)
        i=0;
        HC164_1(MOTOR2[i++]);
    
}
//=================================================
void  StepperDrive2()
{
  static uchar i;
        if(i>31)
        i=0;
        HC164_1(MOTOR3[i++]);
}



//=====步进电机停止工作=============
void  StopMotor()
{
   HC164_1(0x3f);
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -