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

作者: jianchen221    時(shí)間: 2018-4-16 13:17
標(biāo)題: 步進(jìn)電機(jī)正反轉(zhuǎn)
源代碼如下:
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar steptabt[]={0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09};
uchar steptabf[]={0x09,0x08,0x0c,0x04,0x06,0x02,0x03,0x01};
uint freq,ftim;
uchar num,fx;
sbit key1=P2^0;
sbit key2=P2^1;
sbit key3=P2^2;

void t0isr() interrupt 1
{
        TH0=(65536-ftim)/256;
        TL0=(65536-ftim)%256;
        P1=steptabt[num];               
        if(fx==0)
        {
        num++;
        num%=8;
        }
        else
        {
        if(num==0)num=7;
        else num--;
        }
}

main()
{
        TMOD=0x01;
        freq=1/10;       
        ftim=1000000/2/freq;
        TH0=(65536-ftim)/256;
        TL0=(65536-ftim)%256;
        ET0=1;
        EA=1;
        while(1)
        {
        if(key1==0){fx=0;TR0=1;}
        if(key2==0){fx=1;TR0=1;}
        if(key3==0){TR0=0;}
        }
}

電機(jī).zip

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






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