標(biāo)題: 利用脈沖高低控制步進(jìn)電機(jī)正反轉(zhuǎn),為什么我的程序?qū)崿F(xiàn)不了,但是把驅(qū)動(dòng)器上的AB相 [打印本頁]

作者: 1049769176    時(shí)間: 2016-12-24 09:50
標(biāo)題: 利用脈沖高低控制步進(jìn)電機(jī)正反轉(zhuǎn),為什么我的程序?qū)崿F(xiàn)不了,但是把驅(qū)動(dòng)器上的AB相
//利用脈沖高低控制步進(jìn)電機(jī)正反轉(zhuǎn),為什么我的程序?qū)崿F(xiàn)不了,但是把驅(qū)動(dòng)器上的AB相接反就可以實(shí)現(xiàn)反向轉(zhuǎn)動(dòng),但正轉(zhuǎn)就又不可以了
#include <REG52.H>
#define uint unsigned int
#define uchar unsigned char
sbit pul=P1^0;
sbit dir=P1^1;
sbit k1=P3^4;
sbit k2=P3^5;
uchar t=10;

void delay(uint xms)
{
        uint i,j;
        for(i=xms;i>0;i--)
                for(j=112;j>0;j--);
}

void main()
{
        if(k1==0)
        {
                delay(20);
                if(k1==0)
                {
                        while(1)
                        {       
                                while(t--)
                                {
                                        dir=1;
                                        pul=1;
                                        delay(5);
                                        pul=0;
                                        delay(5);
                                }
                                delay(500);
                                while(t--)
                                {
                                        dir=0;
                                        pul=1;
                                        delay(5);
                                        pul=0;
                                        delay(5);
                                }
                               
                        }
                }
        }
}


作者: chemali    時(shí)間: 2016-12-24 21:50
第一個(gè)循環(huán)t--執(zhí)行完,第二個(gè)t--就執(zhí)行不了了。
作者: yyn123456    時(shí)間: 2018-4-23 14:33
chemali 發(fā)表于 2016-12-24 21:50
**** 作者被禁止或刪除 內(nèi)容自動(dòng)屏蔽 ****

你這個(gè)t代表的是什么




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