標(biāo)題: 51單片機(jī)控制步進(jìn)電機(jī)正轉(zhuǎn)反轉(zhuǎn) [打印本頁]

作者: 21753很難    時間: 2019-3-9 11:00
標(biāo)題: 51單片機(jī)控制步進(jìn)電機(jī)正轉(zhuǎn)反轉(zhuǎn)
/*******************************************************
接線方式:
IN1 ---- P00
IN2 ---- P01
IN3 ---- P02
IN4 ---- P03
+   ---- +5V
-   ---- GND
*********************/
#include<reg52.h>
#define uchar unsigned char
#define uint  unsigned int
#define MotorData P0                    //步進(jìn)電機(jī)控制接口定義
uchar phasecw[4] ={0x08,0x04,0x02,0x01};//正轉(zhuǎn) 電機(jī)導(dǎo)通相序 D-C-B-A
uchar phaseccw[4]={0x01,0x02,0x04,0x08};//反轉(zhuǎn) 電機(jī)導(dǎo)通相序 A-B-C-D
//ms延時函數(shù)
void Delay_xms(uint x)
{
uint i,j;
for(i=0;i<x;i++)
  for(j=0;j<112;j++);
}
//順時針轉(zhuǎn)動
void MotorCW(void)
{
uchar i;
for(i=0;i<4;i++)
  {
   MotorData=phasecw[i];
   Delay_xms(4);//轉(zhuǎn)速調(diào)節(jié)
  }
}
//逆時針轉(zhuǎn)動
void MotorCCW(void)
{
uchar i;
for(i=0;i<4;i++)
  {
   MotorData=phaseccw[i];
   Delay_xms(4);//轉(zhuǎn)速調(diào)節(jié)
  }
}
//停止轉(zhuǎn)動
void MotorStop(void)
{
MotorData=0x00;
}
//主函數(shù)
void main(void)
{
uint i;
Delay_xms(50);//等待系統(tǒng)穩(wěn)定
while(1)
{
  for(i=0;i<500;i++)
  {
   MotorCW();   //順時針轉(zhuǎn)動
  }
  MotorStop();  //停止轉(zhuǎn)動
  Delay_xms(500);
  for(i=0;i<500;i++)
  {
   MotorCCW();  //逆時針轉(zhuǎn)動
  }
  MotorStop();  //停止轉(zhuǎn)動
  Delay_xms(500);  
}
}
還有單獨(dú)控制正轉(zhuǎn)反轉(zhuǎn)設(shè)定時間自動停噢!


VD`U026Q5II}4$0O1IJCR9P.png (5.01 KB, 下載次數(shù): 180)

圖1

圖1

步進(jìn)電機(jī).zip

415.69 KB, 下載次數(shù): 408, 下載積分: 黑幣 -5


作者: bwx227    時間: 2020-2-24 00:36
這正是我想找的
作者: smartphone    時間: 2020-3-1 12:10
我也要學(xué)習(xí)學(xué)習(xí),感謝分享。
作者: cyf7175    時間: 2020-3-12 20:59
下來學(xué)習(xí),謝謝樓主分享
作者: Liangkan    時間: 2020-3-16 22:12

下載了,謝謝樓主分享
作者: 隨便起的名字    時間: 2020-3-18 15:46
謝謝樓主分享。
作者: mykent    時間: 2020-3-21 20:35
好經(jīng)驗(yàn),好分享,謝謝
作者: 18000653707    時間: 2020-4-23 23:50
正是我想要的
作者: 季月寶貝    時間: 2020-4-28 14:17
好經(jīng)驗(yàn),好分享,謝謝
作者: 18000653707    時間: 2020-5-15 12:56
終于找的了,哈哈哈
作者: 18000653707    時間: 2020-5-15 13:04
我的程序和你這個一樣,我想要設(shè)定時間自動停止的,不知道下載的壓縮包里有沒有
作者: W—CR7    時間: 2021-4-13 16:45
不知道里面有沒有原理圖啊,初學(xué)不太會

作者: haide1998    時間: 2024-5-13 15:16
路過學(xué)習(xí),謝謝分享!
作者: 白水大蝦2016    時間: 2024-5-20 09:58
路過學(xué)習(xí)一下,以前有個程序反轉(zhuǎn),這個我試試。謝謝哈!
作者: jovew    時間: 2024-5-20 11:37
如何控制轉(zhuǎn)動步數(shù)?
我需要 正轉(zhuǎn)100步,或者 反轉(zhuǎn) 200步,怎么寫程序?
作者: xlhlydd    時間: 2024-5-29 10:01
謝謝樓主的辛勤勞動
作者: donglw    時間: 2024-6-2 17:49
缺少PID控制程序,不能實(shí)現(xiàn)實(shí)時調(diào)速功能。




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1