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

📄 lcd12864_1.lst

📁 51开发环境
💻 LST
📖 第 1 页 / 共 2 页
字号:
 262   1      
 263   1                     
 264   1      }
 265          
 266          
 267          //====================================================================
 268          //   显示一张128*64 的函数
 269          //   参数: pictureName 是你需要显示的图片数组名称,可以放在外部文件
 270          //====================================================================
 271          void DrawPicture(uchar* pictureName)
 272          {
 273   1         unsigned char i,j,row, col ;
 274   1         unsigned int x;
 275   1         row = 0; col=0;
 276   1          for(j=0;j<128;j++){
 277   2           x=j*0x08; 
 278   2           for(i=0;i<8;i++)
 279   2            {
 280   3                cbyte=*(pictureName+x);
 281   3                Wrdata(cbyte,row,col);
 282   3                x++;
 283   3              row++;
 284   3            }   
 285   2           row=0;
 286   2           col++;    
 287   2          }  
 288   1            
 289   1      }
 290          
 291          
 292          //=============================================
 293          //   SetPixel(uchar x, uchar y)
 294          //    0<x<128 , 0<y<64
 295          //=============================================
 296          SetPixel(uchar x, uchar y)
 297          {
 298   1        uchar pixeler;
 299   1        pixeler=pixel[y%8];
 300   1          y=y/8;
 301   1        Wrdata(pixeler,y,x);
 302   1      }
 303          
C51 COMPILER V6.23a  LCD12864_1                                                            04/11/2008 15:27:31 PAGE 6   

 304          //=============================================
 305          //
 306          //==============================================
 307          /*
 308          void Line(uchar x0, uchar y0, uchar x1, uchar y1)
 309          {
 310              float k; //斜率
 311              float x;
 312              uchar y; // 点坐标
 313              int buf;
 314              if(x0)
 315              if(x0>x1)  //起点的X坐标要是较少的
 316              {
 317                 buf=x0;
 318                 x0=x1;
 319                 x1=buf;
 320                 buf=y0;
 321                 y0=y1;
 322                 y1=buf;
 323          
 324              }
 325          
 326              if(x1!=x0)
 327              k=(float)(y1-y0)/(x1-x0);
 328              else
 329              k=9999;
 330          
 331              for(x=x0;x<x1;x+=0.01)
 332              {   y=k*(x-x0)+y0;
 333                 SetPixel(x,y);
 334              }
 335          
 336          }*/
 337          
 338          
 339          
 340          //===================================================
 341          //                 主函数
 342          //===================================================
 343          void main(void)
 344          {  
 345   1        // 你可以增加任意长度的英文单词,程序会循环显示
 346   1        code uchar introduce[]=
 347   1         "Hello,Welcome to ## 51kaifa ##  ^_^   "
 348   1         "This sentance is used for testing the moving LCD."
 349   1         "Firstly,you must know the principle of LCD driver."
 350   1         "Secondly,you can add the code here, what ever enlish characters!! "
 351   1         "Welcome contacting me with my email: wabil2007@yahoo.com.cn "
 352   1         ;
 353   1           void  wait();
 354   1           ulong disdplayLenth=4500;   //设置你需要显示这句子的长度
 355   1           uchar temp1,temp2; //临时变量,用于各种运算          
 356   1            TMOD=0x11; //开启计数器,在中断部分计算时间变量
 357   1            ET0=EA=1;
 358   1            TR0=1;
 359   1            // 初始化时间结构成员
 360   1            time.hour=11;
 361   1            time.min=11;
 362   1            time.sec=11; 
 363   1          
 364   1          Lcminit(); //初始化LCM
 365   1          Lcmcls();
C51 COMPILER V6.23a  LCD12864_1                                                            04/11/2008 15:27:31 PAGE 7   

 366   1                            
 367   1           DrawPicture(picture2); //显示载入界面图  
 368   1           delay1s();
 369   1           charNum=37;
 370   1           Prints("Loading..." ); //显示Loading..字样    
 371   1           
 372   1            charNum=49;
 373   1           while(charNum<65)   
 374   1           {Prints(" " );}   //清理最后一行,用来显示进度条
 375   1           
 376   1           charNum=49;
 377   1           while(charNum<65)   
 378   1           {Prints(">" ); delay(20000);} //进度条用>>>>>>>>>
 379   1         
 380   1           Lcmcls();
 381   1           charNum=23;
 382   1           Prints("^_^           " );
 383   1           Printc(HZ_TIAN   ); //输出一个汉字需要两个字节
 384   1           Printc(HZ_TIAN+1 ); 
 385   1           Printc(HZ_DAO    ); //输出一个汉字需要两个字节
 386   1           Printc(HZ_DAO+1  );
 387   1           Printc(HZ_CHOU   ); //输出一个汉字需要两个字节
 388   1           Printc(HZ_CHOU+1 );  
 389   1           Printc(HZ_QIN    ); //输出一个汉字需要两个字节
 390   1           Printc(HZ_QIN+1  ); 
 391   1           wait();
 392   1        
 393   1         Lcmcls();
 394   1         charNum=1;  //记录屏幕中字符的位置变量,令它归1
 395   1         
 396   1         while(disdplayLenth--)
 397   1          {      
 398   2            DisplayInLine(introduce,1);
 399   2          }
 400   1         Lcmcls();
 401   1         Format("\n" );
 402   1         Prints(" you have taken " );
 403   1         temp1=time.sec;
 404   1         Printd(temp1-11);
 405   1         Prints(" seconds since beginning C51." );   //计算处从你开机到现在用了多少秒 
 406   1         
 407   1         while(time.sec-temp1<4)  //wait 4 second
 408   1         
 409   1         ;
 410   1         Lcmcls();
 411   1         
 412   1         charNum=1;
 413   1         Prints("===============" );
 414   1         charNum=49;
 415   1         Prints("===============" );
 416   1         while(1)
 417   1         {
 418   2            charNum=18;
 419   2            Prints("TIME NOW IS_      " );
 420   2            if(time.hour<10) Printd(0);
 421   2            Printd(time.hour);
 422   2            Prints(":" );
 423   2            if(time.min<10) Printd(0);
 424   2            Printd(time.min);
 425   2            Prints(":" );
 426   2            if(time.sec<10) Printd(0);
 427   2            Printd(time.sec);
C51 COMPILER V6.23a  LCD12864_1                                                            04/11/2008 15:27:31 PAGE 8   

 428   2            
 429   2          }   
 430   1           
 431   1           
 432   1      
 433   1      
 434   1      }
*** WARNING C280 IN LINE 355 OF LCD12864_1.C: 'temp2': unreferenced local variable
 435          
 436          
 437          /***************约1S延时********************/
 438          void delay1s(void)
 439          {
 440   1          delay(50000);
 441   1          delay(50000);
 442   1          
 443   1      
 444   1      }
 445          /***************用于测试的延时子程序********************/
 446          void wait()
 447          {
 448   1        delay(50000);
 449   1        delay(50000);
 450   1        delay(50000);
 451   1        delay(50000);
 452   1        delay(50000);
 453   1      }
 454          
 455          //***************************************************************
 456          //     Name : Ontimer0()
 457          //     Usage: to count some time register and do some time-work
 458          //****************************************************************
 459          void OnTimer0(void) interrupt 1  // using as 
 460          {
 461   1       
 462   1        TH0=(65535-1000)/256;
 463   1        TL0=(65535-1000)%256;                     
 464   1      //  handle some time work code here...
 465   1         time.msec++;
 466   1        if(time.msec>999)
 467   1        {
 468   2          time.msec=0;
 469   2          time.sec++;
 470   2          time.allsec++;
 471   2          // time.allsec records the seconds time 
 472   2         // that since the program is start 32bit large~~136 years' seconds
 473   2        }
 474   1        
 475   1        if(time.sec>59)
 476   1        {
 477   2           time.sec=0;
 478   2           time.min++;
 479   2        }
 480   1             
 481   1              
 482   1      }
 483          
 484          
 485          /***************微秒级延时*****************/
 486          void delay(unsigned int  time)
 487          { unsigned int i;
 488   1          for(i=0;i<time;i++);
C51 COMPILER V6.23a  LCD12864_1                                                            04/11/2008 15:27:31 PAGE 9   

 489   1       }
 490          
 491          
 492          
 493          //***********初始化LCD*******************/
 494          
 495          void Lcminit (void)
 496          { 
 497   1          cbyte=DISPOFF;
 498   1          WrL(cbyte);
 499   1          WrR(cbyte);
 500   1          cbyte=DISPON;
 501   1          WrL(cbyte);
 502   1          WrR(cbyte);
 503   1          cbyte=DISPFIRST;
 504   1          WrL(cbyte);
 505   1          WrR(cbyte);
 506   1          Lcmcls();
 507   1          Locatexy(0,0);
 508   1      }
 509          
 510          /***************LCD清屏********************/
 511          void Lcmcls(void)
 512          { uchar  i,j;
 513   1          for(i=0;i<8;i++){
 514   2            delay(6);
 515   2              for(j=0;j<LIMIT;j++){
 516   3                delay(6);
 517   3                Wrdata(0x0,i,j);
 518   3               }
 519   2           }
 520   1      }
 521          
 522          /**************写左区***************/
 523          
 524          void WrL(uchar x)
 525          {
 526   1         
 527   1         P0=0xFF;//P0口送FF,准备读
 528   1         lck = 0;
 529   1         P1 = 0x2a;//ELCD=1

⌨️ 快捷键说明

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