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

📄 240160b.lst

📁 基于C8051F020单片机的LCD显示程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
 244           调用方式(Function):LcdClr() 
 245           函数描述(Description):清显示 32K RAM区(清屏)子程序
 246           入口参数(Parameters):无
 247           返回值(Returns):无
 248           创建时间:16:07,PM,2004.4.19
 249           修改时间:无
 250           修改原因:无
 251          ******************************************************************************/
 252          void LcdClr(void){
 253   1      
 254   1              Uint i1=32768;
 255   1              
 256   1              WriteCmd( 0x4c );                               // 光标移动方向定义:自动右移0x4c
 257   1              WriteCmd( 0x46 );                               // 光标Locate,定位0x46
 258   1              WriteData( 0 );                                 // 写入参数CSRL设置参数光标指针低8位
 259   1              WriteData( 0 );                                 // 写入参数CSRH设置参数光标指针高8位
 260   1              WriteCmd( 0x42 );                               // 数据写入指令,代码0x42
 261   1      
 262   1              while(i1--)     WriteData( 0x00);       // 写入数据0
 263   1      }
 264          
 265          
 266          //-----------------------------------------------------------------------------
 267          // 函数:void Locatexy(Uchar x,Uchar y)
 268          //-----------------------------------------------------------------------------
 269          /******************************************************************************
 270           调用方式(Function):Locatexy(x,y)
 271           函数描述(Description):光标位定位,用于在1区图形方式下
 272           入口参数(Parameters):
 273                                                    x...水平方向字节单位坐标,即可以以半个汉字宽度设定水平坐标
 274                                                            取值范围:0...39
 275                                                    y...垂直方向以行线定位的坐标,可以定位到点单位
 276                                                        取值范围:0...239
 277                                                    左上角约定坐标为(0,0)
 278           返回值(Returns):无
 279           创建时间:16:07,PM,2004.4.20
 280           修改时间:无
 281           修改原因:无
 282          ******************************************************************************/
 283          void Locatexy(Uchar x,Uchar y) {
 284   1              
 285   1              Uint temp;
 286   1          
 287   1              temp = (Uint)y*paraP9+x;
 288   1          WriteCmd( CsrW );               // 光标Locate,定位
 289   1          WriteData( (Uchar)(temp & 0xff) );  // 写入参数CSRL设置参数光标指针低8位
 290   1          WriteData( (Uchar)(temp /256 ) );   // 写入参数CSRH设置参数光标指针高8位
 291   1      }
 292          
 293          
 294          //-----------------------------------------------------------------------------
 295          // 函数:Uchar dprintf(Uchar x,Uchar y,char code *ptr,bit attrib)
 296          //-----------------------------------------------------------------------------
 297          /******************************************************************************
 298           调用方式(Function):dprintf(x,y,*ptr,attrib)
 299           函数描述(Description):ASCII(8*16) 及 汉字(16*16) 混合字符串显示函数
 300           入口参数(Parameters):
 301                                                    x,y显示字符串的左上角xy坐标
 302                                                    x...8点一字节位置,取值范围:0...29
 303                                                    y...一条扫描线定位,取值范围:0...159
C51 COMPILER V7.09   240160B                                                               08/23/2004 10:54:00 PAGE 6   

 304                                                    *ptr...字符串指针,本函数所指的是flash字串
 305                                                    attrib:属性参数,为0:反显;为:1正常显示
 306           返回值(Returns):输出字串长度,留意汉字一个算两个
 307           其它假定:调用时汉字必须在字库数组中已经存在,否则将输出不正确的结果
 308           创建时间:16:07,PM,2004.4.20
 309           修改时间:无
 310           修改原因:无
 311          ******************************************************************************/
 312          /********************************************************/
 313          /* ASCII(8*16) 及 汉字(16*16) 显示函数                          */
 314          /********************************************************/
 315          Uchar dprintf(Uchar x,Uchar y,char code *ptr,bit attrib)
 316          {
 317   1      
 318   1          Uchar  c1,c2;
 319   1          Uchar i,j,uLen,uRow,uCol,temp;
 320   1          Uint  k;
 321   1      
 322   1          uRow = x;
 323   1          uCol = y;
 324   1          uLen=0;
 325   1          WriteCmd( CsrDirD );                        // 光标移动方向定义:自动下移
 326   1          Locatexy(uRow,uCol);                    //起点定位
 327   1          while ( (Uchar)ptr[uLen] >= 0x10 ){uLen++;};            //探测字串长度
 328   1          i=0;
 329   1          while(i<uLen)
 330   1          {
 331   2              c1 = ptr[i];
 332   2              c2 = ptr[i+1];
 333   2      //ascii字符与汉字内码的区别在于128做分界,大于界线的为汉字码
 334   2              if(c1 <=128)                        // ASCII
 335   2              {
 336   3                  if (c1 >= 0x10) {
 337   4                      WriteCmd( mWrite );         // 写数据(命令)
 338   4                      for(j=0;j<16;j++) 
 339   4                                              if(attrib)WriteData( ASC_MSK[(c1-0x20)*16 +j ]);
 340   4                                              else WriteData(~(ASC_MSK[(c1-0x20)*16 +j ]));
 341   4                  }
 342   3                  uRow++;                                  // 列数加1
 343   3              }
 344   2              else                                // 中文
 345   2              {
 346   3                  for(j=0;j<sizeof(Cdotlib)/sizeof(Cdotlib[0]);j++)   // 查找定位
 347   3                  {
 348   4                      if((c1 == Cdotlib[j].Index[0]) && (c2 == Cdotlib[j].Index[1]))
 349   4                          break;
 350   4                  }
 351   3                  for(k=0;k<2;k++)                // 分16行输出
 352   3                  {
 353   4                      Locatexy(uRow+k,uCol);
 354   4                      WriteCmd( mWrite );     // 写数据(命令)
 355   4      
 356   4                      for(temp=0;temp<16;temp++)
 357   4                                              if(attrib) WriteData( Cdotlib[j].Msk[temp*2 + k]);
 358   4                                              else WriteData(~( Cdotlib[j].Msk[temp*2 + k]));
 359   4                  }
 360   3                  uRow +=2;                       // 光标右移一大格
 361   3                  i++;
 362   3              }
 363   2              if(uRow >= 30)          // 光标后移,原来为40
 364   2              {
 365   3                  uCol += 16;
C51 COMPILER V7.09   240160B                                                               08/23/2004 10:54:00 PAGE 7   

 366   3                  uRow = 0;
 367   3                  if( uCol >= 160 ) uCol = 0; //共有160点行
 368   3              }
 369   2      
 370   2              Locatexy(uRow,uCol);
 371   2              i++;
 372   2          }
 373   1          return uLen;                //返回字串长度,汉字按2字节计算
 374   1      }
 375          
 376          //x...8点一字节位置,取值范围:0...29
 377          //y...一条扫描线定位,取值范围:0...159
 378          void MyGraph(Uchar x,Uchar y,Uchar Weight,Uchar Height,Uchar code *ptr,bit attrib){
 379   1              
 380   1              Uchar uRow,uCol,temp,nbyte;
 381   1          Uint  k;
 382   1      
 383   1          uRow = x;
 384   1          uCol = y;
 385   1          WriteCmd( CsrDirD );                        // 光标移动方向定义:自动下移
 386   1          Locatexy(uRow,uCol);                    //起点定位
 387   1              nbyte=(Uchar)(Weight/8);
 388   1              for(k=0;k<nbyte;k++)                    // 分16行输出
 389   1                  {
 390   2                      Locatexy(uRow+k,uCol);
 391   2                      WriteCmd( mWrite );             // 写数据(命令)
 392   2      
 393   2                      for(temp=0;temp<Height;temp++)
 394   2                                              if(attrib) WriteData(ptr[temp*nbyte+k]);
 395   2                                              else WriteData(~(ptr[temp*nbyte+k]));
 396   2                  }
 397   1              
 398   1      }
 399          
 400          /*====================================================
 401          ;  绘点子程序,携入参数X坐标的最高位决定写或擦点
 402           ====================================================*/
 403          void Point(Uint Px,Uchar Py,Uchar attr){
 404   1      
 405   1              Uint tempPtr;
 406   1              Uchar tempD,tempP;
 407   1                      
 408   1              tempPtr = (Uint)Py * paraP9 + (Px & 0x7fff)/8;  // 去除最高位(显示属性)
 409   1              WriteCmd( CsrDirD );                                            // CSRDIR 代码(光标自动下移)
 410   1              WriteCmd( CsrW );                                                       // 设置光标地址
 411   1              WriteData( (Uchar)(tempPtr & 0xff) );
 412   1              WriteData( (Uchar)(tempPtr /256) );
 413   1              WriteCmd( mRead );                                                      // 读显示ram指令
 414   1              tempD = ReadfromLcd();                                                  // 读取当前显示数据
 415   1              tempP = 1<<(Uchar)(7-Px & 0x0007);
 416   1      
 417   1      // 根据预定属性决定写点或擦除
 418   1              if( attr )tempD |= tempP;       // 画点
 419   1              else tempD &= ~tempP;                           // 消点
 420   1      
 421   1              WriteCmd( CsrW );                                               // 重新设置光标地址
 422   1              WriteData( (Uchar)(tempPtr & 0xff) );
 423   1              WriteData( (Uchar)(tempPtr /256) );
 424   1              WriteCmd( mWrite );                                             // 代码0x42,数据写入指令
 425   1              WriteData( tempD );                                                     // 写入合成数据
 426   1      
 427   1      }
C51 COMPILER V7.09   240160B                                                               08/23/2004 10:54:00 PAGE 8   

 428          void SYSCLK_Init(void){
 429   1       
 430   1         Uchar i;                              // delay counter
 431   1      
 432   1         OSCXCN = 0x66;                            // start external oscillator with
 433   1                                           // 22.1184MHz crystal
 434   1      
 435   1         for (i=0; i < 254; i++) ;         // wait for osc to start
 436   1      
 437   1         while (!(OSCXCN & 0x80)) ;        // Wait for crystal osc. to settle
 438   1      
 439   1         OSCICN = 0x88;                    // select external oscillator as SYSCLK
 440   1                                           // source and enable missing clock
 441   1                                           // detector
 442   1      }
 443          
 444          
 445          void PORT_Init(void)
 446          {
 447   1      
 448   1              XBR0=0x00;                          // 1:Enable; UART0,SMBUS
 449   1              XBR1=0x00;
 450   1              XBR2=0x40;                              // Enable crossbar and weak pull-ups
 451   1      
 452   1              P0MDOUT |=0xf0;                                 // enable P07~P04 as push-pull outputs,4个按键(P03~P00)为开漏
 453   1              P1MDOUT |=0xff;                 // enable P1 as push-pull outputs
 454   1              P2MDOUT |=0xfc;         //0xfc          // enable P27~P22 as push-pull outputs,P21(SCLK),P20(SDA)配置为开漏
 455   1              P3MDOUT |=0x3f;         //                      // enable P3.5~P3.0 as push-pull outputs,P3.7(IRQ),P3.6(Ctime)为开漏
 456   1              P74OUT  |=0xf3;         //                      // 
 457   1      }
 458          void main(void){
 459   1      
 460   1      
 461   1              WDTCN = 0xde;                       // disable watchdog timer
 462   1              WDTCN = 0xad;
 463   1              SYSCLK_Init();                                          // 切换到外部晶振
 464   1      //      OSCICN=0x14;                                            // 内部晶振16M运行,2M:0x14;4M:0x15;8M:0x16;16M:0x17
 465   1      
 466   1              PORT_Init();                                            // 端口初始化
 467   1      
 468   1              LcdInit();
 469   1              LcdClr();
 470   1      
 471   1              EL_ON=1;                                                        //开背光
 472   1      
 473   1      
 474   1              dprintf(0,50,"2004/04/25重庆东电",0);
 475   1      
 476   1              MyGraph(23,111,48,48,Ico_RP,1); //显示一副图片
 477   1      
 478   1              while(1);
 479   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    939    ----
   CONSTANT SIZE    =   1979    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----      18
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----       2
C51 COMPILER V7.09   240160B                                                               08/23/2004 10:54:00 PAGE 9   

END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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