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

📄 lcd_part_12864j.lst

📁 C51单片机对st7920并行方式驱动128*64液晶驱动,实现任意位置坐标位置写入图片;自动画线;自动画圆;任意位置反显等功能。
💻 LST
📖 第 1 页 / 共 3 页
字号:
 215          *                               LCD实际显示最大128*64,后面数据消隐
 216          * 参数        :  参数名称:    输入/输出       类型                    描述
 217          *                                       Byte[]            input                 uchar           数据组(max 65535 byte)
 218          *                                         x                   input                     uchar           起始行位置数据(0-127)
 219          *                                         y                   input                     uchar           起始列位置数据(0-63)
 220          *                                       xrange            input                 uchar           图像行分辨率(1-255)
 221          *                                       yrange            input                 uchar           图像列分辨率(1-255)
 222          * 返回值      :正确:1; 错误:0,x或y值超范围
 223          * 作者        :lujian
 224          * 创建日期    :2003-12-19
 225          * 全局变量    :
 226          * 全局静态变量:
 227          * 局部静态变量:dstate, start, end,  xstd, xetd, xedl, tlen, ovxend, xend, yend;
 228          *----------------------------------------修改历史------------------------------------------
 229          * 当前版本    :0.0.2                    修改人:lujian                  修改日期:2009-3-16
 230          * 修改说明    :
 231          ******************************************************************************************/
 232          
 233          bit lcd_display(uchar Byte[], uchar x, uchar y, uchar xrange, uchar yrange)
 234          {
 235   1              uchar dstate, start, end,  xstd, xetd, xedl, tlen, ovxend;
 236   1              uint xend, yend;
 237   1              uchar xsdl, dlen,  gcount, g, g1, temp1, yt, sd1, sd2, ed1, ed2;
 238   1              uint bcount;
 239   1              bit error = 1;
 240   1      
 241   1      //-------------------------------------------------------
C51 COMPILER V8.15   LCD_PART_12864J                                                       03/17/2009 18:11:02 PAGE 5   

 242   1      // Boundary detection
 243   1      
 244   1              yend = y + yrange;
 245   1              xend = x + xrange;
 246   1              if(xend > 0x00ff || y > 0x00ff || x > 127 || y > 63)
 247   1                      return FALSE;
 248   1      
 249   1              wr_lcd(comm,DISPLAY_OFF);               //Entry mode set
 250   1      
 251   1              if(xend > 128)
 252   1              {
 253   2                      ovxend = xend;
 254   2                      xrange = 128 - x;
 255   2                      xend = 128; 
 256   2                      error = 0;
 257   2              }
 258   1      
 259   1              if(yend > 64)
 260   1              {
 261   2                      yrange = 64 - y;
 262   2                      yend = 64; 
 263   2                      error = 0;
 264   2              }
 265   1              
 266   1              start = (x /16)*16;
 267   1              xstd = x % 16;                                  //开始位置LCD原始数据的位数
 268   1              xetd = xend % 16;
 269   1              if(xetd!=0)
 270   1                      xetd = 16 - xetd;                       //结尾位置LCD原始数据的位数
 271   1              end = xend + xetd;
 272   1              tlen = end - start;
 273   1      
 274   1              yt = 0;
 275   1              bcount = 0;
 276   1      //-------------------------------------------------------
 277   1      
 278   1      //main program
 279   1      
 280   1      //-------------------------------------------------------
 281   1      // preprocessing
 282   1              for(yt = y;yt < yend; yt++)
 283   1              {       
 284   2                      dlen = xrange;
 285   2                      xsdl = xstd;
 286   2                      xedl = xetd;
 287   2      
 288   2                      if(xsdl != 0)                           //If the start data equal to zero, do not need to read data. 
 289   2                      {
 290   3                              temp1 = x /16;                  //Reading the start data form lcd.
 291   3                              XYadr(temp1,yt);
 292   3                              rd_lcd();
 293   3                              sd1 = rd_lcd();
 294   3                              sd2 = rd_lcd();
 295   3                      }
 296   2      
 297   2                      if(xedl != 0)                           //If the end of data's number equal to zero, do not need to read data.
 298   2                      {
 299   3                              temp1 = xend /16;               //Reading the end of data form lcd
 300   3                              XYadr(temp1,yt);
 301   3                              rd_lcd();
 302   3                              ed1 = rd_lcd();
 303   3                              ed2 = rd_lcd();
C51 COMPILER V8.15   LCD_PART_12864J                                                       03/17/2009 18:11:02 PAGE 6   

 304   3                      }
 305   2      
 306   2                      temp1 = x /16;
 307   2                      XYadr(temp1,yt);
 308   2                      dstate = 0;
 309   2                      g1 = 7;
 310   2                      g = 0;
 311   2                      gcount = 0;
 312   2      //-------------------------------------------------------
 313   2      
 314   2      //  writing lcd's data program
 315   2      
 316   2      //-------------------------------------------------------
 317   2      //  set data into the launcher
 318   2                      while(tlen > g)
 319   2                      {
 320   3                              if(gcount == 0)                 //data empty!!装子弹!!
 321   3                              {
 322   4                                      switch (dstate)
 323   4                                      {
 324   5                                  case 0:                             //processing start data 
 325   5                                              if(xstd > 8)
 326   5                                              {
 327   6                                                      if(xsdl > 8)                            //开始位置LCD原始数据大于8bit,
 328   6                                                      {                                                       //st7920 横向为16bit数据,数据需读两次
 329   7                                                              B = sd1;                                //开始位置LCD原始数据(0-7)
 330   7                                                              gcount = 8;
 331   7                                                              xsdl = xsdl - 8;
 332   7                                                      }
 333   6                                                      else
 334   6                                                      {       
 335   7                                                              B = sd2;                                //开始位置LCD原始数据(8-15)
 336   7                                                              gcount = xsdl;
 337   7                                                              dstate = 1;
 338   7                                                      }
 339   6                                              }
 340   5                                              else
 341   5                                              {
 342   6                                                      B = sd1;                                        //开始位置LCD原始数据(0-7)
 343   6                                                      gcount = xsdl;
 344   6                                                      dstate = 1;
 345   6                                              }
 346   5                                              break;
 347   5                                      
 348   5                                  case 1:                             //processing data
 349   5                                              if(dlen > 8)
 350   5                                              {
 351   6                                                       B = Byte[bcount];                                                        //写入8bit数据处理
 352   6                                                       dlen = dlen - 8;
 353   6                                                       gcount = 8;
 354   6                                                       bcount++;
 355   6                                              }
 356   5                                              else
 357   5                                              {
 358   6                                                       B = Byte[bcount];                                                         //写入数据不足8bit结尾处理
 359   6                                                       gcount = dlen;
 360   6                                                       if(ovxend > 128)
 361   6                                                              bcount = bcount + ((ovxend - 128)/8);      //大于128bit的数据组需要跳读才能正常显示
 362   6                                                       bcount++;                                                                         //横向多出部分进行消隐
 363   6                                                       dstate = 2;
 364   6                                              }
 365   5                                              break;
C51 COMPILER V8.15   LCD_PART_12864J                                                       03/17/2009 18:11:02 PAGE 7   

 366   5                                      
 367   5                                  case 2:                             //processing end data 
 368   5                                              if(xetd > 8)
 369   5                                              {
 370   6                                                      if(xedl > 8)
 371   6                                                      {
 372   7                                                              temp1 = 16 - xedl;                      //结尾位置LCD原始数据大于8bit,
 373   7                                                              B = ed1;                                        //st7920 横向为16bit数据,数据需读两次
 374   7                                                              B = B << temp1;                         //结尾位置LCD原始数据(0-7)
 375   7                                                              gcount = xedl - 8;
 376   7                                                              xedl = 0;
 377   7                                                      }
 378   6                                                      else
 379   6                                                      {
 380   7                                                              gcount = 0;                                     //结尾位置LCD原始数据(8-15)
 381   7                                                              g = tlen + 1;                           //jumping Out the writing lcd's data program
 382   7                                                              dstate = 0;                                     //由于结尾原始数据无需修改,直接跳出
 383   7                                                      }
 384   6                                              }
 385   5                                              else
 386   5                                              {
 387   6                                                      temp1 = 8 - xedl;                               //结尾位置LCD原始数据小于8bit(8-15)
 388   6                                                      B = ed2;
 389   6                                                      B = B << temp1;
 390   6                                                      gcount = xedl;
 391   6                                                      dstate = 0;
 392   6                                              }
 393   5                                      break;
 394   5                                      default:
 395   5                                              break;
 396   5                                      }
 397   4                              }
 398   3      //-------------------------------------------------------
 399   3      // Target's data process
 400   3                              if(gcount != 0)
 401   3                              {
 402   4                                      switch (g1)                             //击中目标!!
 403   4                                      {
 404   5                                  case 7:
 405   5                                              P0_7 = B_7;
 406   5                                              g1--;
 407   5                                              break;
 408   5                                  case 6:
 409   5                                              P0_6 = B_7;
 410   5                                              g1--;
 411   5                                              break;
 412   5                                  case 5:
 413   5                                              P0_5 = B_7;
 414   5                                              g1--;
 415   5                                              break;
 416   5                                  case 4:
 417   5                                              P0_4 = B_7;
 418   5                                              g1--;
 419   5                                              break;
 420   5                                      case 3:
 421   5                                              P0_3 = B_7;
 422   5                                              g1--;
 423   5                                              break;
 424   5                                      case 2:
 425   5                                              P0_2 = B_7;
 426   5                                              g1--;
 427   5                                              break;
C51 COMPILER V8.15   LCD_PART_12864J                                                       03/17/2009 18:11:02 PAGE 8   

 428   5                                      case 1:
 429   5                                              P0_1 = B_7;
 430   5                                              g1--;
 431   5                                              break;
 432   5                                      case 0:
 433   5                                              P0_0 = B_7;
 434   5                                              wr_lcd(dat,P0);         //writing lcd's data
 435   5                                              g1 = 7; 

⌨️ 快捷键说明

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