找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2168|回复: 3
收起左侧

分享一个基于MSP430F149的步进电机入门教程,附Lv8731驱动芯片及驱动手册

[复制链接]
ID:914689 发表于 2021-8-4 21:05 | 显示全部楼层 |阅读模式
#include  <msp430x14x.h>

#define Step_A P4OUT=0xfe;
#define Step_B P4OUT=0xfd;
#define Step_C P4OUT=0xfb;
#define Step_D P4OUT=0xf7;

#define Step_AB P4OUT=0xfc;
#define Step_BC P4OUT=0xf9;
#define Step_CD P4OUT=0xf3;
#define Step_DA P4OUT=0xf6;

#define Step_OFF P4OUT=0xf0;

unsigned char a[4]={0xfe,0xfd,0xfb,0xf7},i;


void DelayUs2x(unsigned char t);
void DelayMs(unsigned char t);

/********************主函数**********************/
void main(void)
{
       unsigned char temp;
       unsigned int Speed;               //旋转一周时间
       Speed=4;
      
       WDTCTL = WDTPW + WDTHOLD;                    // 关狗
      
    /*------选择系统主时钟为8MHz-------*/
       BCSCTL1 &= ~XT2OFF;                          //打开XT2高频晶体振荡器
       do
        {
        IFG1 &= ~OFIFG;                             //清除晶振失败标志
        for (temp = 0xFF; temp > 0; temp--);        //等待8MHz晶体起振
        }
       while ((IFG1 & OFIFG));                      //等待晶振运行起来
       BCSCTL2 |= SELM1 + SELS + DIVM_3 +DIVS_3;
      
       P1DIR = 0xff;P1OUT = 0xff;
       P2DIR = 0xff;P2OUT = 0xff;
       P3DIR = 0xff;P3OUT = 0xff;
       P4DIR = 0xff;P4OUT = 0xff;
       P5DIR = 0xff;P5OUT = 0xff;
       P6DIR = 0xff;P6OUT = 0xff;


       while(1)
        {
            /*Step_AB               
            DelayMs(Speed);                    //电机转速调整,数字越小,转速越快
            Step_BC                           //四相八拍运行方式即 A-AB-B-BC-C-CD-D-DA-A.
            DelayMs(Speed);
            Step_CD
            DelayMs(Speed);
            Step_DA
            DelayMs(Speed);*/
            
                 /*Step_A               
                 DelayMs(Speed);                    //电机转速调整,数字越小,转速越快
                 Step_AB                            //四相四拍运行方式
                 DelayMs(Speed);
                 Step_B
                 DelayMs(Speed);
                 Step_BC
                 DelayMs(Speed);
                 Step_C
                 DelayMs(Speed);
                 Step_CD
                 DelayMs(Speed);
                 Step_D
                 DelayMs(Speed);
                 Step_DA
                 DelayMs(Speed);*/
              
                 Step_DA               
                 DelayMs(Speed);                    //电机转速调整,数字越小,转速越快
                 Step_D                            //四相四拍运行方式
                 DelayMs(Speed);
                 Step_CD
                 DelayMs(Speed);
                 Step_C
                 DelayMs(Speed);
                 Step_BC
                 DelayMs(Speed);
                 Step_B
                 DelayMs(Speed);
                 Step_AB
                 DelayMs(Speed);
                 Step_A
                 DelayMs(Speed);
         
          /*for(i=0;i<4;i++)
          {
            P4OUT=a[ i];
            DelayMs(Speed);
          }*/
         
         
         
         
        }
}







/*------------------------------------------------
uS延时函数,大致延时
长度 T=tx2+5 uS
------------------------------------------------*/
void DelayUs2x(unsigned char t)
{   
while(--t);
}
/*------------------------------------------------
mS延时函数
------------------------------------------------*/
void DelayMs(unsigned char t)
{
     
while(t--)
{
     //大致延时1mS
     DelayUs2x(245);
     DelayUs2x(245);
}
}
屏幕截图 2021-08-04 205654.png
屏幕截图 2021-08-04 205615.png

430F149步进.rar

5.03 MB, 下载次数: 18, 下载积分: 黑币 -5

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:966040 发表于 2021-9-14 17:34 | 显示全部楼层
有MSP430F149的中文用户手册吗?
回复

使用道具 举报

ID:966040 发表于 2021-9-14 17:35 | 显示全部楼层
MSP430F149的用户手册有吗?
回复

使用道具 举报

ID:966040 发表于 2021-9-15 20:29 | 显示全部楼层
你们用的啥IDE?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表