分享

正反转可控步进电机(仿真图 代码)

 幽州浅水 2019-12-01

正反转可控步进电机(仿真图+代码)

proteus电子元器件:80C51 BUTTON CAP CAP-ELEC CRYSTAL LED-RRD MOTOR-STEPPER RES ULN2003A

源代码如下:

#include <reg52.h>

#define uint unsigned int

#define uchar unsigned char

uchar code FFW[]=

{

0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09

};

uchar code REV[]=

{

0x09,0x08,0x0c,0x04,0x06,0x02,0x03,0x01

};

sbit K1 = P3^0;

sbit K2 = P3^1;

sbit K3 = P3^2;

void DelayMS(uint ms)

{

uchar i;

while(ms--)

{

for(i=0;i<120;i++);

}

}

void SETP_MOTOR_FFW(uchar n)

{

uchar i,j;

for(i=0;i<5*n;i++)

{

for(j=0;j<8;j++)

{

if(K3 == 0) break;

P1 = FFW[j];

DelayMS(25);

}

}

}

void SETP_MOTOR_REV(uchar n)

{

uchar i,j;

for(i=0;i<5*n;i++)

{

for(j=0;j<8;j++)

{

if(K3 == 0) break;

P1 = REV[j];

DelayMS(25);

}

}

}

void main()

{

uchar N = 3;

while(1)

{

if(K1 == 0)

{

P0 = 0xfe;

SETP_MOTOR_FFW(N);

if(K3 == 0) break;

}

else if(K2 == 0)

{

P0 = 0xfd;

SETP_MOTOR_REV(N);

if(K3 == 0) break;

}

else

{

P0 = 0xfb;

P1 = 0x03;

}

}

}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多