<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>

新聞中心

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

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

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

#include //51芯片管腳定義頭文件
#include //內部包含延時(shí)函數 _nop_();
#define uchar unsigned char
#define uint unsigned int
uchar code FFW[8]={0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09}; //四相八拍正轉編碼
uchar code REV[8]={0x09,0x08,0x0c,0x04,0x06,0x02,0x03,0x01}; ////四相八拍反轉編碼
sbit K1 = P3^2; //正轉
sbit K2 = P3^3; //反轉
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://dyxdggzs.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)電機正轉
/*
/********************************************************/
void motor_ffw()
{
uchar i;
uint j;
for (j=0; j<8; j++) //轉1*n圈
{
if(K3==0)
{break;} //退出此循環(huán)程序
for (i=0; i<8; i++) //一個(gè)周期轉45度
{
P1 = FFW[i]; //取數據
delay(2); //調節轉速
}
}
}

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

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

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

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



關(guān)鍵詞: 步進(jìn)電機正反轉程

評論


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

關(guān)閉
国产精品自在自线亚洲|国产精品无圣光一区二区|国产日产欧洲无码视频|久久久一本精品99久久K精品66|欧美人与动牲交片免费播放
<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>