<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 步進(jìn)電機(jī)正反轉(zhuǎn)程序

          步進(jìn)電機(jī)正反轉(zhuǎn)程序

          作者: 時(shí)間:2016-11-24 來(lái)源:網(wǎng)絡(luò) 收藏

          #include //51芯片管腳定義頭文件
          #include //內(nèi)部包含延時(shí)函數(shù) _nop_();
          #define uchar unsigned char
          #define uint unsigned int
          uchar code FFW[8]={0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09}; //四相八拍正轉(zhuǎn)編碼
          uchar code REV[8]={0x09,0x08,0x0c,0x04,0x06,0x02,0x03,0x01}; ////四相八拍反轉(zhuǎn)編碼
          sbit K1 = P3^2; //正轉(zhuǎn)
          sbit K2 = P3^3; //反轉(zhuǎn)
          sbit K3 = P3^4; //停止
          sbit BEEP = P3^6; //蜂鳴器
          /********************************************************/
          /*
          /* 延時(shí)t毫秒
          /* 11.0592MHz時(shí)鐘,延時(shí)約1ms
          /*
          /********************************************************/
          void delay(uint t)
          {
          uint k;
          while(t--)
          {
          for(k=0; k<125; k++)
          { }
          }
          }

          本文引用地址:http://www.ex-cimer.com/article/201611/320779.htm

          /**********************************************************/
          void delayB(uchar x) //x*0.14MS
          {
          uchar i;
          while(x--)
          {
          for (i=0; i<13; i++)
          { }
          }
          }

          /**********************************************************/
          void beep()
          {
          uchar i;
          for (i=0;i<100;i++)
          {
          delayB(4);
          BEEP=!BEEP; //BEEP取反
          }
          BEEP=1; //關(guān)閉蜂鳴器
          }

          /********************************************************/
          /*
          /*步進(jìn)電機(jī)正轉(zhuǎn)
          /*
          /********************************************************/
          void motor_ffw()
          {
          uchar i;
          uint j;
          for (j=0; j<8; j++) //轉(zhuǎn)1*n圈
          {
          if(K3==0)
          {break;} //退出此循環(huán)程序
          for (i=0; i<8; i++) //一個(gè)周期轉(zhuǎn)45度
          {
          P1 = FFW[i]; //取數(shù)據(jù)
          delay(2); //調(diào)節(jié)轉(zhuǎn)速
          }
          }
          }

          /********************************************************/
          /*
          /*步進(jìn)電機(jī)反轉(zhuǎn)
          /*
          /********************************************************/
          void motor_rev()
          {
          uchar i;
          uint j;
          for (j=0; j<8; j++) //轉(zhuǎn)1×n圈
          {
          if(K3==0)
          {break;} //退出此循環(huán)程序
          for (i=0; i<8; i++) //一個(gè)周期轉(zhuǎn)45度
          {
          P1 = REV[i]; //取數(shù)據(jù)
          delay(2); //調(diào)節(jié)轉(zhuǎn)速
          }
          }
          }

          /********************************************************
          *
          * 主程序
          *
          *********************************************************/

          main()
          {
          uchar r,N=64; //N 步進(jìn)電機(jī)運(yùn)轉(zhuǎn)圈數(shù)
          while(1)
          {
          if(K1==0)
          {
          beep();
          for(r=0;r {
          motor_ffw(); //電機(jī)正轉(zhuǎn)
          if(K3==0)
          {beep();break;} //退出此循環(huán)程序
          }
          }
          else if(K2==0)
          {
          beep();
          for(r=0;r {
          motor_rev(); //電機(jī)反轉(zhuǎn)
          if(K3==0)
          {beep();break;} //退出此循環(huán)程序
          }
          }
          else
          P1 = 0xf0;
          }
          }

          /********************************************************/



          評(píng)論


          技術(shù)專(zhuān)區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();