步进电机正反转

main.c

#include<reg51.h>
#include<function.h>
#include<keyscan.h>

#define speed 1


sbit PH1 = P1^0;      //定义管脚
sbit PH2 = P1^1;
sbit I01 = P1^2;
sbit I11 = P1^3;
sbit I02 = P1^4;
sbit I12 = P1^5;

void delay(int time){ 
  int i,j;

  for(j=0; j <= time; j++)
   for(i =0 ; i <= 120; i++);
}



void init()
{
    PH1 = 0;
    I01 = 0;
    I11 = 0;

    PH2 = 1;
    I02 = 1;
    I12 = 1;
    delay(speed);
    PH1 = 0;
    I01 = 0;
    I11 = 0;

    PH2 = 1;
    I02 = 1;
    I12 = 1;
    delay(speed);   
}


void Go1() //    !a=>!b=>a=>b=>!a
{
    PH1 = 0;
    I01 = 0;
    I11 = 0;

    PH2 = 0;
    I02 = 1;
    I12 = 1;
    delay(speed);
//okay; 
    PH1 = 1;
    I01 = 1;
    I11 = 1;

    PH2 = 0;
    I02 = 0;
    I12 = 0;
    delay(speed);

    PH1 = 1;
    I01 = 0;
    I11 = 0;

    PH2 = 1;
    I02 = 1;
    I12 = 1;
    delay(speed);


    PH1 = 0;
    I01 = 1;
    I11 = 1;

    PH2 = 1;
    I02 = 0;
    I12 = 0;
    delay(speed);

    PH1 = 0;
    I01 = 0;
    I11 = 0;

    PH2 = 0;
    I02 = 1;
    I12 = 1;
    delay(speed);


}
void Go2()
{
    PH1 = 0;
    I01 = 0;
    I11 = 0;

    PH2 = 1;
    I02 = 1;
    I12 = 1;
    delay(speed);   
    PH1 = 1;
    I01 = 1;
    I11 = 1;

    PH2 = 1;
    I02 = 0;
    I12 = 0;
    delay(speed);

    PH1 = 1;
    I01 = 0;
    I11 = 0;

    PH2 = 0;
    I02 = 1;
    I12 = 1;
    delay(speed);


    PH1 = 0;
    I01 = 1;
    I11 = 1;

    PH2 = 0;
    I02 = 0;
    I12 = 0;
    delay(speed);

    PH1 = 0;
    I01 = 0;
    I11 = 0;

    PH2 = 1;
    I02 = 1;
    I12 = 1;
    delay(speed);


}


void main()
{
    uchar key;
    initialKeyScan();
    init();
    while(1)
    {
        key = keyScan();

        switch(key)
        {
            case 0x00:{Go1(); break;}


            case 0x01:{Go2(); break;}
        }
        key = 0x10;


    }

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值