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

📄 1335c51.lst

📁 这是一个成熟的用于驱动步进马达的程序,我们用于调试螺钉的.
💻 LST
📖 第 1 页 / 共 5 页
字号:
 644   1              uint t;
 645   1              int     xerr=0,yerr=0,delta_x,delta_y,distance;
 646   1              int     incx,incy;
 647   1              uint row,col;
 648   1              delta_x = xt-x0;                                                        //计算坐标增量
 649   1              delta_y = yt-y0;
 650   1              col     = x0;
 651   1              row     = y0;
 652   1              if(delta_x>0) 
 653   1                      {
 654   2                              incx=1;                                         //设置单步方向
 655   2                      }
 656   1              else 
 657   1          {
 658   2              if( delta_x==0  ) 
 659   2                      {
 660   3                              incx=0;                         //垂直线
 661   3                      }
 662   2                      else 
 663   2                              {
 664   3                                      incx=-1;
 665   3                                      delta_x=-delta_x;
 666   3                              }
 667   2              }
 668   1              if(delta_y>0) 
 669   1                      {
 670   2                              incy=1;
 671   2                      }
 672   1              else
 673   1          {
 674   2              if( delta_y==0  ) 
 675   2                      {
C51 COMPILER V8.15   1335C51                                                               10/29/2008 21:06:48 PAGE 12  

 676   3                              incy=0;                         //水平线
 677   3                      }
 678   2                      else 
 679   2                              {
 680   3                                      incy=-1;
 681   3                                      delta_y=-delta_y;
 682   3                              }
 683   2              }
 684   1              if(     delta_x > delta_y )     
 685   1                      {
 686   2                              distance=delta_x;       //选取基本增量坐标轴
 687   2                      }
 688   1              else 
 689   1                      {
 690   2                              distance=delta_y;
 691   2                      }
 692   1      
 693   1              for( t=0;t <= distance+1; t++ )
 694   1              {                                                                                       //画线输出
 695   2                      Point((uint)col,row,att);                               //画点
 696   2                      xerr += delta_x ;
 697   2                      yerr += delta_y ;
 698   2                      
 699   2                      if(     xerr > distance )
 700   2                      {
 701   3                              xerr-=distance;
 702   3                              col+=incx;
 703   3                      }
 704   2                      if(     yerr > distance )
 705   2                      {
 706   3                              yerr-=distance;
 707   3                              row+=incy;
 708   3                      }
 709   2              }
 710   1      }
 711          
 712          #if 0
              
              /********************************************/
              /*画矩形        */
              /********************************************/
              void Rectangle(uint x0, uchar y0, uint xt, uchar yt, uchar att)
              {
                  Linexy(x0, y0, x0, yt,att);
                  Linexy(x0, yt, xt, yt,att);
                  Linexy(xt, yt, xt, y0,att);
                  Linexy(xt, y0, x0, y0,att);
              }
              
              #endif
 726          
 727          
 728          // 写指令代码子程序
 729          void WriteCommand( uchar CommandByte ) 
 730          {
 731   1              LCD_CS_LOW;    //选通
 732   1          LCD_A0=1;    //1为写命令或读数据
 733   1          LCD_WR=0;  
 734   1          LCD_RD=1;    //确定读信号不起作用
 735   1          LCM_DATA=CommandByte;  //向1335中写入指令代码     
 736   1          LCD_WR=1;
 737   1          LCD_CS_UP;
C51 COMPILER V8.15   1335C51                                                               10/29/2008 21:06:48 PAGE 13  

 738   1              LCM_DATA=0xff; 
 739   1              //LcmCmdPort = CommandByte;
 740   1      }
 741          
 742          //---------------------------
 743          // 写参数及显示数据子程序
 744          void WriteData( uchar dataW ) 
 745          {
 746   1              LCD_CS_LOW;    //选通
 747   1          LCD_A0=0;    //0为写数据、参数和读忙标志        
 748   1          LCD_RD=1;    //确定读信号不起作用
 749   1          LCM_DATA=dataW;  //向1335中写入指令代码    
 750   1          LCD_WR=0;   
 751   1          LCD_WR=1;
 752   1          LCD_CS_UP;
 753   1              LCM_DATA=0xff;
 754   1              //LcmWdataPort = dataW;
 755   1      }
 756          
 757          //---------------------------
 758          // 读参数及显示数据子程序
 759          uchar ReadDataLcm( void ) 
 760          {
 761   1              uchar Lcmdat;
 762   1          LCM_DATA=0xff;
 763   1          LCD_CS_LOW;    //选通
 764   1          LCD_A0=1;    //0为写数据、参数和读忙标志        
 765   1          LCD_RD=0;    //  
 766   1          LCD_WR=1;
 767   1          Lcmdat=LCM_DATA;
 768   1          LCD_RD=1;
 769   1          LCD_CS_UP;
 770   1              LCM_DATA=0xff;    
 771   1              return Lcmdat;
 772   1      }
 773          
 774          /*=====================================
 775           初始化子程序
 776          ======================================*/
 777          void LcmInition( void ) 
 778          {
 779   1      
 780   1              uchar i;
 781   1              delay_xms(500);                 // 足够的延时确保Lcm已经准备好  
 782   1              WriteCommand( SystemSet );                      // 系统参数设置
 783   1              for (i=0;i<8;i++) {                             
 784   2                      WriteData( ParaSysTable8[i] );  //
 785   2              }
 786   1      
 787   1              WriteCommand( Scroll );                         //设定显示区域起始地址
 788   1              for (i=0;i<10;i++) {
 789   2                      WriteData( ParaScrTableA[i] );
 790   2              }
 791   1      
 792   1              WriteCommand( HdotScr );                // 写入点位移指令代码
 793   1              WriteData( 0 );                                 // 写入P1参数
 794   1              WriteCommand( Ovlay );                  // 显示合成方式设置
 795   1              WriteData( 0x08 );                                      // 0000 0100 显示一区文本,二区图形属性,二重"或"合成
 796   1              WriteCommand( DispOn );                 // 写入指令代码
 797   1              WriteData( 0x54 );                              // 显示 1~4 区开显示,光标关显示
 798   1              LcmClear();
 799   1      //      BuildCgram(0,15);               //
C51 COMPILER V8.15   1335C51                                                               10/29/2008 21:06:48 PAGE 14  

 800   1      }
 801          
 802          #if 0
              /*============================================
               建立 cgram,将显示字符送入cgram中
              
                入口参数约定:Base.... 起始
              =============================================*/
              void BuildCgram( uchar Base, uchar EndlCode ) 
              {
              
              uchar iCgram,ii,ij;
              
                      WriteCommand( CgramAdr );               // CGRAMADR 代码
                      WriteData( 0 );                                 // 设置SAG=07000H
                      WriteData( 0x70 );                              // 汉字模在cgram中的编码0x70~0x73
              
                      WriteCommand( CsrW );                   // CSRW 代码,光标指针设置
                      WriteData( 0 );                                 // 设置CSR=07400H(字符代码=80H)
                      WriteData( 0x74 );                              // 汉字模在cgram中的编码0x70~0x73
                      WriteCommand( CsrDirR );                // CSRDIR 代码
                      WriteCommand( mWrite );                 // 代码0x42,数据写入指令
                      for (ii=0;ii<EndlCode;ii++)
                      {
                              for (ij=0;ij<2;ij++)
                              {
                                      for (iCgram=0;iCgram<32;iCgram+=2) 
                                              WriteData( Cdotlib[(Base+ii)*32+ij+iCgram] );   // 将制定的数据块写入 cgram
                              }
                              
                      }
              }
              
              
              
                      
              
              /*============================================================================
               汉字写入子程序(文本方式)
               在文本方式下显示汉字,  首先要建立汉字Cgram, 要定义汉字代码.
               在文本方式下写汉字需要写入4 个代码以组成一个汉字 
               每8字节组成一个点阵Ascii小区,4个小区组合成一个汉字所以需要4个代码
               ============================================================================*/
              void PutCdotInAlpha( uchar Ox, uchar Oy, uchar Cnumber ) 
              {
              
              uint tempPtr;
              uchar tempCount;
                              
                      tempPtr = (uint)Oy * paraP9 + Ox;
                      WriteCommand( CsrDirD );                                        // CSRDIR 代码(下移)
              
                      for(tempCount=0;tempCount<2;tempCount++)
                       {
                              
                              WriteCommand( CsrW );                                   // CSRW 代码,光标指针设置
                              WriteData( (uchar)(tempPtr &0xff) );    // 设置光标地址CSR
                              WriteData( tempPtr /256 + BasePart1 );
                              WriteCommand( mWrite );                                 // 代码0x42,数据写入指令
              
                              WriteData( Cnumber++ );                                 // 写入汉字代码
              

⌨️ 快捷键说明

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