标题: 单片机控制步进电机任意角度调节程序 [打印本页]

作者: 燦洋    时间: 2019-6-20 21:42
标题: 单片机控制步进电机任意角度调节程序


单片机源程序如下:
  1. #include <reg51.h>
  2. //*  单双八拍工作方式:A-AB-B-BC-C-CD-D-DA                                       *
  3. unsigned char code shun[8] = {0x08,0x0c,0x04,0x06,0x02,0x03,0x01,0x09};
  4. unsigned char code ni[8] = {0x09,0x01,0x03,0x02,0x06,0x04,0x0c,0x08};
  5. void delay(char x)//延时程序
  6. {                          
  7.    char i;
  8.    while(x--)
  9.    {
  10.      for(i=0; i<120; i++);
  11.    }
  12. }
  13. void  motor_1(float a)//a即想要转的圈数
  14. {
  15.    unsigned char b;
  16.    unsigned int  c;
  17.    for (c=0; c<8*64*a; c++)
  18.     {
  19.       for (b=0; b<8; b++)
  20.         {
  21.           P1 = shun[b];
  22.          delay(1);
  23.          }
  24.     }
  25. }
  26. void  motor_2(float a)//a即想要转的圈数
  27. {
  28.    unsigned char b;
  29.    unsigned int  c;
  30.    for (c=0; c<8*64*a; c++)
  31.     {
  32.       for (b=0; b<8; b++)
  33.         {
  34.           P1 = ni[b];
  35.          delay(1);
  36.          }
  37.     }
  38. }
  39. void main()//主程序
  40. {   
  41.         while(1)
  42.         {
  43.        motor_1(0.5); //转2圈(可以改动)         
  44.        delay(1000);
  45.            P1 = 0;                //防止电机发热
  46.            motor_2(0.5); //转2圈(可以改动)         
  47.        delay(1000);
  48.            P1 = 0;                //防止电机发热
  49.         }
  50. }
复制代码

所有资料51hei提供下载:
步进电机.zip (24.35 KB, 下载次数: 55)


作者: pandabentobe    时间: 2019-7-25 11:15
for (c=0; c<8*64*a; c++)                     //??????8*64*a  这是怎么得来的算式呀
    {
      for (b=0; b<8; b++)
        {
          P1 = ni[b];
         delay(1);
         }
作者: 晓风凌殇    时间: 2020-2-6 21:21

for (c=0; c<8*64*a; c++)    64是减速比




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