⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainline.lst

📁 用电键控制步进电机朝各个方向做曲线
💻 LST
字号:
C51 COMPILER V7.50   MAINLINE                                                              09/10/2005 16:30:06 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE MAINLINE
OBJECT MODULE PLACED IN .\mainline.obj
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE ..\control\mainline.c BROWSE DEBUG OBJECTEXTEND PRINT(.\mainline.lst) OBJEC
                    -T(.\mainline.obj)

line level    source

   1          #include "reg52.h"
   2          #include "intrins.h"
   3          #include "math.h"
   4          #include <absacc.h>
   5          #include "VIIC_C51.h"
   6          #include "ZLG7290.h"
   7          
   8          sbit KEY_INT=P3^2;
   9          sbit PA1=P2^0;
  10          sbit PB1=P2^1;
  11          sbit PC1=P2^2;
  12          sbit PA2=P2^4;
  13          sbit PB2=P2^5;
  14          sbit PC2=P2^6;
  15            //端口定义
  16          
  17          #define stepleng 0.2  //c=单步距离
  18          #define a0 1160
  19          #define b0 1492  //物体在原点的两悬线长度
  20          
  21          bit dir;
  22          char sta1,sta2;
  23          //unsigned int linex,liney;
  24          unsigned char key;
  25          unsigned char send[8]={00,00,00,00,00,00,00,00};//定义发送缓冲区 0~3--y 4~6--x 7--sign
  26          unsigned int x,y,a,b;
  27          int za,zb;
  28          int numa,numb;
  29          unsigned char disp_buf[8]={0,0,0,0,0,0,0,0};//定义全局变量
  30          
  31          unsigned char display(unsigned char  *sd)//显示程序
  32          { 
  33   1          disp_buf[0] = sd[0];                        
  34   1          disp_buf[1] = sd[1];                
  35   1          disp_buf[2] = sd[2];   
  36   1          disp_buf[3] = sd[3];
  37   1          disp_buf[4] = sd[4];
  38   1          disp_buf[5] = sd[5];
  39   1          disp_buf[6] = sd[6];        
  40   1          disp_buf[7] = sd[7];
  41   1      
  42   1          ZLG7290_SendBuf(disp_buf,8);
  43   1          return 0;
  44   1      }
  45          
  46                  unsigned char delay(unsigned char  no)
  47          { 
  48   1              unsigned char  i,j;                                     //延时参数
  49   1      
  50   1              for(; no>0; no--)
  51   1              { 
  52   2                      for(i=0; i<10; i++)
  53   2                      for(j=0; j<100; j++);
  54   2              }
C51 COMPILER V7.50   MAINLINE                                                              09/10/2005 16:30:06 PAGE 2   

  55   1              return 0; 
  56   1      }
  57          
  58          void runner1(unsigned  int num,bit dir)//输入转动的步数、方向,完成电机1转动(相对3相电机) 
  59          {
  60   1              unsigned  int i; 
  61   1              if(dir)
  62   1              {
  63   2                      for(i=0;i<=num;i++)
  64   2                      {
  65   3                              sta1++;
  66   3                              sta1=sta1%6;
  67   3                              delay(2);
  68   3                              if (sta1==0)PC1=1;
  69   3                              if (sta1==1)PB1=0;
  70   3                              if (sta1==2)PA1=1;
  71   3                              if (sta1==3)PC1=0;
  72   3                              if (sta1==4)PB1=1;
  73   3                              if (sta1==5)PA1=0;
  74   3                      }
  75   2              }
  76   1              else
  77   1                {
  78   2                 for(i=0;i<=num;i++)
  79   2                      {
  80   3                      sta1--;
  81   3                      if (sta1<0)sta1=5;
  82   3                       delay(2);
  83   3                              if (sta1==0)PB1=1;
  84   3                              if (sta1==1)PA1=0;
  85   3                              if (sta1==2)PC1=1;
  86   3                              if (sta1==3)PB1=0;
  87   3                              if (sta1==4)PA1=1;
  88   3                              if (sta1==5)PC1=0;
  89   3                      }
  90   2                }
  91   1      }
  92          
  93          void runner2(unsigned  int num,bit dir)//输入转动的步数、方向,完成电机1转动(相对3相电机) 
  94          {
  95   1              unsigned  int i; 
  96   1              if(~dir)
  97   1              {
  98   2                      for(i=0;i<=num;i++)
  99   2                      {
 100   3                              sta1++;
 101   3                              sta1=sta1%6;
 102   3                              delay(2);
 103   3                              if (sta1==0)PC2=1;
 104   3                              if (sta1==1)PB2=0;
 105   3                              if (sta1==2)PA2=1;
 106   3                              if (sta1==3)PC2=0;
 107   3                              if (sta1==4)PB2=1;
 108   3                              if (sta1==5)PA2=0;
 109   3                      }
 110   2              }
 111   1              else
 112   1                {
 113   2                 for(i=0;i<=num;i++)
 114   2                      {
 115   3                      sta1--;
 116   3                      if (sta1<0)sta1=5;
C51 COMPILER V7.50   MAINLINE                                                              09/10/2005 16:30:06 PAGE 3   

 117   3                       delay(2);
 118   3                              if (sta1==0)PB2=1;
 119   3                              if (sta1==1)PA2=0;
 120   3                              if (sta1==2)PC2=1;
 121   3                              if (sta1==3)PB2=0;
 122   3                              if (sta1==4)PA2=1;
 123   3                              if (sta1==5)PC2=0;
 124   3                      }
 125   2                }
 126   1      }
 127          
 128          
 129          unsigned int point_A (unsigned int x,unsigned int y)//变量转换xy-a
 130          {
 131   1              unsigned int lineA;
 132   1              unsigned int tmp;
 133   1              tmp=(1150-y)*(1150-y)+(x+150)*(x+150);
 134   1              tmp=sqrt(tmp);
 135   1              lineA=tmp;
 136   1              return lineA;
 137   1      }
 138          
 139          unsigned int point_B (unsigned int x,unsigned int y) //变量转换xy-b
 140          {
 141   1              unsigned int lineB;
 142   1              unsigned int tmp;
 143   1              tmp=(1150-y)*(1150-y)+(950-x)*(950-x);
 144   1              tmp=sqrt(tmp);
 145   1              lineB=tmp;
 146   1              return lineB;
 147   1      }
 148          /*
 149          unsigned int loc_X (int lineA,int lineB)//变量转换ab-x
 150          {
 151                  unsigned int loc;
 152                  loc = (lineA*lineA-lineB*lineB)/2200+400;
 153                  return loc;
 154          }
 155          
 156          
 157          void circle (unsigned int x,unsigned int y)//画圆程序  
 158          {
 159                  unsigned char i;
 160                  unsigned int x1,y1;
 161                  float tmp1,tmp2;
 162                  unsigned int linex,liney;
 163                  unsigned int linex1,liney1;
 164                  x1=x-250;
 165                  y1=y;
 166                  linex=point_A(x1,y1);
 167                  liney=point_B(x1,y1);
 168                  for (i=0;i<360;i++)
 169                          {
 170                  //取绝对坐标
 171                  tmp1=sin(3.1415926*(1-i/180));
 172                          tmp2=cos(3.1415926*(1-i/180));
 173          
 174                          x1=x1+x1+25*tmp2;
 175                          y1=y1+25*tmp1;
 176                          linex1=point_A(x1,y1);
 177                          liney1=point_B(x1,y1);
 178                          za=linex-linex1;
C51 COMPILER V7.50   MAINLINE                                                              09/10/2005 16:30:06 PAGE 4   

 179                          zb=liney-liney1;
 180                          if (za>=0)runner1(za,1);
 181                          else runner1(-za,0);
 182                          if (zb>=0)runner1(zb,1);
 183                          else runner1(-zb,0);            
 184                          }
 185          }
 186          
 187          void mypath (void)//将物体直线运动 5mm*200
 188          {unsigned int x=0,y=0,i,ta,tb;//ta,tb a,b前一个状态长
 189           ta=a0;tb=b0;
 190           for(i=0;i<=200;i++)
 191           {
 192            a=point_A(x,y);
 193            b=point_B(x,y);
 194            za=ta-a;//za,zb a,b的增量
 195            zb=tb-b;
 196            numa=za/stepleng;
 197            numb=zb/stepleng;
 198            runner1(numa,1);//  1/0表示挂线伸缩的方向
 199            runner2(numb,1);
 200            x=x+5;
 201            y=y+5;
 202            ta=a;
 203            tb=b;
 204           }
 205           
 206          }
 207          
 208          */
 209          
 210          void main()
 211          {
 212   1              
 213   1      PA1=0; 
 214   1      PB1=1;
 215   1      PC1=1;
 216   1      sta1=0;//电机1初始化
 217   1      PA2=0; 
 218   1      PB2=1;
 219   1      PC2=1;
 220   1      sta2=0;//电机2初始化
 221   1      
 222   1      
 223   1      
 224   1      display(send);
 225   1      
 226   1      runner1(1500,1);
 227   1      for(;;);
 228   1      
 229   1      
 230   1      }
 231          
 232          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    586    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     35    ----
C51 COMPILER V7.50   MAINLINE                                                              09/10/2005 16:30:06 PAGE 5   

   IDATA SIZE       =   ----    ----
   BIT SIZE         =      1       2
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -