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

📄 main.lst

📁 步进电机控制的C程序
💻 LST
字号:
C51 COMPILER V8.08   MAIN                                                                  12/21/2008 10:38:58 PAGE 1   


C51 COMPILER V8.08, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN main.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE main.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include <REGX52.H>
   2          //#include <SST89X5XXRD2.H>
   3          #include<math.h>
   4          #define uchar unsigned char 
   5          #define uint unsigned int
   6          
   7          char code sxf[][4]={" ","1  ","2  ","4  ","8  ","16 ","32 ","64 ","128","256","5  ","10 ","20 ","40 ","80 
             -","160","   "};
   8          
   9          char code workshow[][4]={"OFF","ON "};
  10          char code runflash[][4] = {"ON-","ON_"};
  11          char dirshow[][4]= {"R->","<-F"};
  12          uchar idata recbuf[30];//串口接收缓冲区
  13          uchar outbuf[10];//串口发送缓冲区;
  14          uchar reclen;   
  15          uchar sendlen;  // 发送计数器
  16          uchar *sendbuf; // 发送指针
  17          bit work;               // 运行控制      0--停止,1--转动
  18          uchar k=0;
  19          bit dir;  // 运转方向
  20          uint steplen;    // 运动步数
  21          uchar uxifen;   // 细分值 
  22          
  23          sbit  s0 = P2^0; //细分设置
  24          sbit  s1 = P2^1; //细分设置
  25          sbit  s2 = P2^2; //细分设置
  26          sbit  s3 = P2^3;  //细分设置
  27          #define  XIFEN  P2
  28          #define XFMASK 0xf0
  29          sbit KEYUP = P2^6;
  30          sbit KEYDN = P2^7;
  31          
  32          sbit  QA   = P1^0;
  33          sbit  QB   = P2^5;
  34          
  35          sbit  FREE = P2^4;  // 脱机控制 
  36          uchar phase[]={0,1,3,2,0,1,3,2}; // 相位控制
  37          uchar zx[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
  38          bit ReadVer;
  39          
  40          uint position =0;
  41          uint posmax=60000;
  42          
  43          sbit  KEY1 = P2^4;
  44          sbit  KEY2 = P2^5;
  45          sbit  KEY3 = P2^6;
  46          sbit  KEY4 = P2^7;
  47                                                     
  48          //函数声明
  49          void sysinit(void);    // 系统初始化
  50          void xifenset(uint i); //细分设置函数
  51          void delay(uint t);   // 延时函数 //
  52          void LcdReset(void);/*初始化*/
  53          void lcd_cls();/*清除显示*/
  54          void ePut_str(char x,char y,char *strpoint); /*在当前显示位置显示LCD 字符串*/
C51 COMPILER V8.08   MAIN                                                                  12/21/2008 10:38:58 PAGE 2   

  55          //void lcd_string(char *strpoint) ;
  56          void showx(char x,char y,unsigned int n);
  57          void Delay50ms(uchar n); // 延时n*50ms
  58          void Delayms(uint n);//延时n(ms);
  59          //void show(); //
  60          void senddata(uchar m);//串口发送程序
  61          void SendStr(unsigned char *buf);// 发送字符串
  62          
  63          bit bwork;
  64          //%*3011020
  65          
  66          void bytewrite (unsigned  int um, unsigned char dat)     ;
  67          unsigned char byteread(unsigned int um);
  68          
  69          
  70          void main(void)
  71          {
  72   1          uchar i;uchar p;
  73   1              sysinit(); //初始化
  74   1              //senddata('O');
  75   1          LcdReset();
  76   1              lcd_cls();
  77   1              P0=0xFE;
  78   1          EA=1;
  79   1              SendStr("V数字共交显微控制 V1.0");
  80   1              Delay50ms(4); // 延时2s
  81   1              ePut_str(0,0,"Run:OFF XF:     ");
  82   1              ePut_str(0,1,"Dir:    ST:     ");
  83   1              position = (byteread(10)<<8) | byteread(11);
  84   1              delay(1000);     
  85   1              while(1)
  86   1         { 
  87   2               if(work) ET0 = 1;
  88   2               else ET0 =0;
  89   2               KEYUP=1;KEYDN=1;
  90   2               if(KEYUP==0) {
  91   3                  work=1;
  92   3                  dir=1;steplen=10;
  93   3                      ET0=1;
  94   3                      }
  95   2               if(KEYDN==0) {
  96   3                  work=1;
  97   3                      dir=0;steplen=10;
  98   3                      ET0=1;}
  99   2      
 100   2               ePut_str(4,0,workshow[work]);  
 101   2               ePut_str(11,0,sxf[uxifen]);
 102   2               showx (15,0,work);
 103   2               ePut_str(4,1,dirshow[dir]);
 104   2               showx (11,1,steplen);
 105   2               if(ReadVer){ReadVer=0;SendStr("V数字共交显微控制 V1.0"); }
 106   2               //P0 = zx[uxifen];
 107   2         } 
 108   1      }
*** WARNING C280 IN LINE 72 OF MAIN.C: 'i': unreferenced local variable
*** WARNING C280 IN LINE 72 OF MAIN.C: 'p': unreferenced local variable
 109          
 110          void timer0(void) interrupt 1
 111          {
 112   1         uchar p=0;
 113   1         static int t=0;   
 114   1      
C51 COMPILER V8.08   MAIN                                                                  12/21/2008 10:38:58 PAGE 3   

 115   1         if((work ==1) && steplen)
 116   1         { 
 117   2                       p = k&0x03;
 118   2                       QA =  phase[p]&0x01;
 119   2                       QB =  (phase[p]>>1)&0x01;
 120   2       
 121   2                       if(work==1 && steplen) steplen--;      
 122   2      
 123   2                       if(dir) { k--;if(position) position--;}        // 正向控制       
 124   2                       else    { k++;if((position<posmax)) position++;}          // 反向控制   
 125   2      
 126   2         } 
 127   1                 /*
 128   1                 else if( work==3 )   
 129   1                 {
 130   1                       p = k&0x03;
 131   1                       QA =  phase[p]&0x01;
 132   1                       QB =  (phase[p]>>1)&0x01;
 133   1                   if(dir) { k--;position--;}         // 正向控制       
 134   1                       else    { k++;position++;}        // 反向控制   
 135   1                 }
 136   1                 */
 137   1                 else 
 138   1                 { 
 139   2                   QA=0;QB=0; work=0;ET0=0;
 140   2                       TI =0;SBUF = '$';while(!TI) ;
 141   2                       TI =0;SBUF = position>>8;
 142   2                       bytewrite(10,(uchar)(position>>8));
 143   2                       bytewrite(11,(uchar)position);
 144   2                 }               
 145   1      }
*** WARNING C280 IN LINE 113 OF MAIN.C: 't': unreferenced local variable
 146          
 147          //**************************************************************//
 148          // 细分设置函数 //
 149          //**************************************************************//
 150          void xifenset(uchar i)
 151          {  uchar res;
*** WARNING C235 IN LINE 151 OF MAIN.C: parameter 1: different types
 152   1         uchar k=0;
 153   1         i = i&0x0f;
 154   1         k |=(i & 0x08)>>3;
 155   1         k |=(i & 0x04)>>1;    
 156   1         k |=(i & 0x02)<<1;
 157   1         k |=(i & 0x01)<<3;
 158   1      
 159   1         res = XIFEN;
 160   1         res = (res & 0xF0) | ((~k) & 0x0F);
 161   1         XIFEN = res;
 162   1         uxifen = i+1;      
 163   1      }
 164          
 165          
 166          void senddata(uchar m)
 167          {
 168   1         TI=0;SBUF=m;
 169   1      }                                 
 170          //==========串口中断处理函数===========================
 171          // 格式1 "%*xdttttr\r" 其中: x为细分值;d=0正转,d=1反转;tttt为步数;r=0不控制,r=1执行;
 172          // 格式2 "#*s\r"  其中:s=0读状态及参数;s=1正转;s=2反转;s=3停止;
 173          #define DDIV  2
 174          #define DDIR  3
C51 COMPILER V8.08   MAIN                                                                  12/21/2008 10:38:58 PAGE 4   

 175          #define DRUN  4
 176          #define DTIME 5
 177          
 178          void uart0(void) interrupt 4
 179          {
 180   1              uchar res;
 181   1              static uchar index=0;
 182   1              if(RI)
 183   1              {//接收中断处理
 184   2                      RI = 0;
 185   2                      res = SBUF;
 186   2                      recbuf[index]=res;               
 187   2                      if(res!='*' && index==1) {index=0;recbuf[index]=res;}            
 188   2                      if(index) index++;
 189   2                      if(res=='%'||res=='#')       {index=1;recbuf[0]=res; }
 190   2                      
 191   2                      if(res==0x0a && index >3)// 收到有效的控制码
 192   2                      {
 193   3                      recbuf[index]=0;// 添加字符串结束符
 194   3                      reclen = index;         
 195   3                      index =0;               
 196   3                      if(recbuf[0]=='%' && reclen==11)                
 197   3                      {                  
 198   4                         xifenset(recbuf[DDIV]&0x0f); // 设置细分数
 199   4                         dir = recbuf[DDIR]&0x01;  // 正反转
 200   4                         work = recbuf[DRUN] & 0x03;
 201   4                         steplen =(recbuf[DTIME]&0x0f);  steplen<<=4;
 202   4                         steplen |=(recbuf[DTIME+1]&0x0f);steplen<<=4;
 203   4                         steplen |=(recbuf[DTIME+2]&0x0f);steplen<<=4;
 204   4                         steplen |=(recbuf[DTIME+3]&0x0f);
 205   4                      }
 206   3                      else if(recbuf[0]=='#' && reclen==5)
 207   3                      {  //index =0; 
 208   4                         switch(recbuf[2]&0x0f)
 209   4                         {
 210   5                            case 0: work =0;break;
 211   5                                case 1: work =1;dir = 0; break;
 212   5                                case 2: work =1;dir = 1; break;
 213   5                                case 3: work =0;break;
 214   5                                case 8: ReadVer=1; break;
 215   5                                default: work =0; break;                 
 216   5                         }
 217   4                      }
 218   3                      }               
 219   2                      if(index>=20) index =0;   // 如果收到乱码重置  
 220   2              }                
 221   1              else 
 222   1              { // 发送中断处理
 223   2                      TI=0;
 224   2                      if(sendlen) 
 225   2                      {
 226   3                              sendlen--;
 227   3                              if(sendlen) SBUF = *sendbuf++;           
 228   3                      }               
 229   2              }
 230   1      
 231   1      }
 232          void SendStr(unsigned char *buf)
 233          { 
 234   1        unsigned char len=0;
 235   1        while(sendlen);
 236   1        while(buf[len]) len++;
C51 COMPILER V8.08   MAIN                                                                  12/21/2008 10:38:58 PAGE 5   

 237   1        sendlen = len;
 238   1        TI=0;
 239   1        sendbuf = buf;
 240   1        SBUF = *sendbuf++;  
 241   1       
 242   1      }
 243          
 244          //**************************************************************//
 245          //系统初始化//
 246          //**************************************************************//
 247          void sysinit(void)
 248          {
 249   1              // == 定时器0 工作在 1ms, Fosc =11.052MHz
 250   1          TMOD=0x02;
 251   1              TH0=0x00;
 252   1              TL0=0x00;
 253   1      
 254   1          TMOD &=0x0f;
 255   1          TMOD|=0x20;
 256   1          SCON=0x50;
 257   1          PCON|=0x80;
 258   1          TH1=0xfd;
 259   1          TL1=0xfd;
 260   1          TR1=1;
 261   1      
 262   1          P3 = 0xff;
 263   1      
 264   1              TR0=1;
 265   1              ET0=0;
 266   1      
 267   1              ES=1; //允许串口中断
 268   1          PS=0; //串口中断优先级别最高
 269   1          //EA=1; //开所有中断 
 270   1      }
 271          
 272          //**************************************************************//
 273          // 延时函数 //
 274          //**************************************************************//
 275           void delay(uint N)
 276           {
 277   1         uint i;
 278   1         for(i=0;i<N;i++);
 279   1       }
 280          
 281           void Delayms(unsigned int ms)
 282          {
 283   1          unsigned int i,j;
 284   1          for(i=0;i<ms;i++)
 285   1          for(j=0;j<113;j++);
 286   1      }
 287          
 288          void Delay50ms(unsigned char ms)
 289          {
 290   1          unsigned int i;
 291   1          unsigned char j;
 292   1          for(j=0;j<ms;j++)
 293   1          for(i=0;i<9135;i++);
 294   1      }
 295          
 296          


C51 COMPILER V8.08   MAIN                                                                  12/21/2008 10:38:58 PAGE 6   

MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1030    ----
   CONSTANT SIZE    =    140    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     50       5
   IDATA SIZE       =     30    ----
   BIT SIZE         =      4    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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