黄工无刷电机学习
直播中

刘继牛

7年用户 1020经验值
私信 关注
[问答]

步进电机是如何实现正反转的

步进电机是如何实现正反转的?怎样去编写其代码?

回帖(1)

江端淳

2021-10-14 17:06:45
  main.c
  #include《reg51.h》
  #include《function.h》
  #include《keyscan.h》
  #define speed 1***it PH1 = P1^0; //定义管脚
  ***it PH2 = P1^1;
  ***it I01 = P1^2;
  ***it I11 = P1^3;
  ***it I02 = P1^4;
  ***it 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;
  }
  }
举报

更多回帖

发帖
×
20
完善资料,
赚取积分