标题: ULN2003步进电机只能接单片机P0口吗 [打印本页]

作者: 蓝琪    时间: 2018-12-5 23:24
标题: ULN2003步进电机只能接单片机P0口吗
如题,ULN2003步进电机只能接单片机P0口吗?接到其他IO口电机不转动,程序里也改为了其他IO口
#include<reg52.h>
#define uchar unsigned char
#define uint  unsigned int
#define MotorData P0                  //步进电机控制接口定义
uchar phasecw[4] ={0x08,0x04,0x02,0x01};//正转 电机导通相序 D-C-B-A
uchar phaseccw[4]={0x01,0x02,0x04,0x08};//反转 电机导通相序 A-B-C-D
//ms延时函数
void Delay_xms(uint x)
{
uint i,j;
for(i=0;i<x;i++)
  for(j=0;j<112;j++);
}
//顺时针转动
void MotorCW(void)
{
uchar i;
for(i=0;i<4;i++)
  {
   MotorData=phasecw[i];
   Delay_xms(4);//转速调节
  }
}
//逆时针转动
void MotorCCW(void)
{
uchar i;
for(i=0;i<4;i++)
  {
   MotorData=phaseccw[i];
   Delay_xms(4);//转速调节
  }
}
//停止转动
void MotorStop(void)
{
MotorData=0x00;
}
//主函数
void main(void)
{
uint i;
Delay_xms(50);//等待系统稳定
while(1)
{
  for(i=0;i<500;i++)
  {
   MotorCW();   //顺时针转动
  }
  MotorStop();  //停止转动
  Delay_xms(500);
  for(i=0;i<500;i++)
  {
   MotorCCW();  //逆时针转动
  }
  MotorStop();  //停止转动
  Delay_xms(500);  
}
}



作者: 江蓬玮    时间: 2018-12-6 09:28
GPIO都可以接啊
作者: che100    时间: 2018-12-6 09:52
其他的GPIO口也可以,如果内部无上拉,最好外部接上拉10K电阻
作者: 蓝琪    时间: 2018-12-6 10:08
江蓬玮 发表于 2018-12-6 09:28
GPIO都可以接啊

好的,谢谢,已经解决了
作者: Bensenner    时间: 2018-12-6 10:14
我记得是都可以把
作者: yang1597    时间: 2018-12-6 10:46
大佬厉害  已采纳
作者: lhd123    时间: 2018-12-6 11:57
不是一定的
作者: maimai    时间: 2020-2-29 22:09
请问用这个程序仿真是不是只能正转呀




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1