找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2412|回复: 2
收起左侧

单片机控制步进电机任意角度调节程序

[复制链接]
ID:438858 发表于 2019-6-20 21:42 | 显示全部楼层 |阅读模式

部分程序

部分程序
@@5KKD$%$S{`)HD)P34NY4O.png

单片机源程序如下:
  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)
回复

使用道具 举报

ID:212386 发表于 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);
         }
回复

使用道具 举报

ID:70316 发表于 2020-2-6 21:21 | 显示全部楼层

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

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表