標(biāo)題: 51單片機(jī)驅(qū)動(dòng)步進(jìn)電機(jī) [打印本頁(yè)]

作者: a8556432    時(shí)間: 2017-9-25 20:04
標(biāo)題: 51單片機(jī)驅(qū)動(dòng)步進(jìn)電機(jī)
#include <reg52.h>

//4相8拍  
unsigned char code tableCCW[8]={0x08,0x0c,0x04,0x06,0x02,0x03,0x01,0x09};   //逆時(shí)針旋轉(zhuǎn)相序表  
unsigned char code tableCW[8]={0x09,0x01,0x03,0x02,0x06,0x04,0x0c,0x08};    //順時(shí)針旋轉(zhuǎn)相序表  
unsigned char code ZZ[8]={0xd5,0xf5,0x75,0x7d,0x5d,0x5f,0x57,0xd7};//28BYJ-48正時(shí)鐘旋轉(zhuǎn)相序表
void BGdelay(unsigned int n)//步進(jìn)延時(shí)
{
unsigned int i;
for(n;n>0;n--)
for(i=96;i>0;i--);
}

void motorTurn_ccw()      //轉(zhuǎn)1圈,逆時(shí)針  
{     
    int i,j;  
    for(j=0;j<8;j++)       //電機(jī)內(nèi)部的轉(zhuǎn)子旋轉(zhuǎn)一周  
    {  

        for(i=0;i<8;i++)    //旋轉(zhuǎn)45度, 8*5.625°=45°  
        {  
          //  P2=tableCW[i];
                   P2=ZZ[i];
            BGdelay(2);      //調(diào)節(jié)轉(zhuǎn)速  
        }  
    }  
}  

void interrupt_0() interrupt 0
{           int r;  
         int N=64;
     for(r=0;r<N;r++)  
          {  
                motorTurn_ccw();  //電機(jī)逆時(shí)針轉(zhuǎn)  

          }  

}

void main()  
{  

     //減速步進(jìn)電機(jī),減速比1/64,所以N=64時(shí),步進(jìn)電機(jī)外主軸轉(zhuǎn)一圈   
   // P2=0xff;     
           EA=1;
         EX0 =1;
         IT0=0;
    while(1);  






    }  







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