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

📄 ledsubfuc.lst

📁 在51上控制LED屏的显示和输出
💻 LST
📖 第 1 页 / 共 2 页
字号:
 297   1              NOP;
 298   1              
 299   1      }
 300          
 301          
 302            
 303          bit  sendbyte(uchar c)          //if  ACK=1 the data of sended  is ok  
C51 COMPILER V7.02a   LEDSUBFUC                                                            05/26/2005 13:15:53 PAGE 6   

 304          {                               //if  ACK-0 the data of sended  is not received
 305   1              uchar BitCnt;
 306   1              bit ACK;
 307   1      
 308   1              for(BitCnt=0;BitCnt<8;BitCnt++)     // data`length is eight
 309   1                      {
 310   2                              if((c<<BitCnt)&0x80)
 311   2                                      {
 312   3                                              SDA=1;
 313   3                                      }
 314   2                      else  
 315   2                                      {
 316   3                                      SDA=0;
 317   3                              }
 318   2              NOP;
 319   2                      
 320   2              SCL=1;                //begin receive data
 321   2              NOP;               //delay
 322   2              NOP;                
 323   2              NOP;
 324   2              NOP;
 325   2              NOP;
 326   2              SCL=0;
 327   2                      
 328   2                     }
 329   1      
 330   1              NOP;
 331   1              NOP;
 332   1                      
 333   1              SDA=1;                //begin receive ACK
 334   1              NOP;
 335   1              NOP;
 336   1              SCL=1;
 337   1              NOP;
 338   1              NOP;
 339   1              NOP;
 340   1                      
 341   1              if(SDA==1)
 342   1                      {
 343   2                              ACK=0;        //Is receive ACK?
 344   2                      }
 345   1             else 
 346   1                      {
 347   2                              ACK=1; 
 348   2              }
 349   1              SCL=0;
 350   1              NOP;
 351   1              NOP;
 352   1                      
 353   1              return(ACK);
 354   1                      
 355   1      }
 356          
 357          
 358          uchar  rcvbyte()
 359          {
 360   1              uchar retc;
 361   1              uchar BitCnt;
 362   1      
 363   1              retc=0;
 364   1              SDA=1;              //set receive`state 
 365   1              for(BitCnt=0;BitCnt<8;BitCnt++)
C51 COMPILER V7.02a   LEDSUBFUC                                                            05/26/2005 13:15:53 PAGE 7   

 366   1                      {
 367   2                              NOP;
 368   2                              
 369   2                              SCL=0;          //begin receive data
 370   2                              NOP;           //delay
 371   2                              NOP;          
 372   2                              NOP;
 373   2                              NOP;
 374   2                              NOP;
 375   2                              SCL=1;          //make data valid
 376   2                              NOP;
 377   2                              NOP;
 378   2                              
 379   2                              retc=retc<<1;
 380   2                              if(SDA==1)retc=retc+1;           
 381   2                              NOP;
 382   2                              NOP;
 383   2                      }
 384   1              SCL=0;
 385   1              NOP;
 386   1              NOP;
 387   1              
 388   1              return(retc);
 389   1      }
 390          
 391            
 392          
 393          void ack_i2c(bit a)
 394          {
 395   1      
 396   1              if(a==0)
 397   1                      {
 398   2                              SDA=0;        //is not last byte
 399   2                      }
 400   1              else
 401   1                      {
 402   2                              SDA=1;     //is last byte
 403   2                      }
 404   1              NOP;
 405   1              NOP;
 406   1              NOP;
 407   1              SCL=1;
 408   1              NOP;
 409   1              NOP;               
 410   1              NOP;
 411   1              NOP;
 412   1              NOP;
 413   1                      
 414   1              SCL=0;                 //begin receive data  again
 415   1              NOP;
 416   1              NOP;
 417   1                      
 418   1      }
 419          
 420           
 421          
 422          void  pcf8563_init(void)
 423          {
 424   1              uchar i;
 425   1              
 426   1      
 427   1             for (i=0;i<50;i++)  
C51 COMPILER V7.02a   LEDSUBFUC                                                            05/26/2005 13:15:53 PAGE 8   

 428   1                      {
 429   2                              NOP;
 430   2              }
 431   1             start_i2c();              //write control word
 432   1             while(~sendbyte(0xa2));                //send  slave address      1010001|r/w
 433   1             while(~sendbyte(0x00));                //send  word address 
 434   1             while(~sendbyte(0x00));                //send  data
 435   1             while(~sendbyte(0x01));                //enable the interrupt of timer  (TIE=1)
 436   1             start_i2c();
 437   1              while(~sendbyte(0xa2));                //send  slave address      1010001|r/w
 438   1             while(~sendbyte(0x0e));                //send  word address
 439   1             while(~sendbyte(0x83));                //enable the timer,  the frequency  is 1/60Hz  
 440   1             while(~sendbyte(0x05));                //the time of  timer's interrupet is 5min    
 441   1              stop_i2c();
 442   1              get_time(time);
 443   1              if (time[6]==0x00)
 444   1                      {                          // set default time
 445   2                              time[0]=0x00;            //sec
 446   2                              time[1]=0x30;            //min
 447   2                              time[2]=0x05;            //hour
 448   2                              time[3]=0x19;            //date
 449   2                              time[4]=0x04;            //week
 450   2                              time[5]=0x05;            //month
 451   2                          time[6]=0x05;            //year
 452   2                              
 453   2                              set_time(time);   
 454   2                      }
 455   1              
 456   1      }
 457          
 458          
 459          
 460          
 461           
 462          void set_time(uchar time[])
 463          {
 464   1              uchar i;
 465   1              start_i2c();
 466   1              while(~sendbyte(0xa2));
 467   1              while(~sendbyte(0x02));
 468   1              for(i=0;i<7;i++)
 469   1                      {
 470   2                              while(~sendbyte(time[i]));
 471   2                      }
 472   1            stop_i2c();
 473   1      }
 474           
 475          
 476          void get_time(uchar time[])
 477          {
 478   1              uchar i;
 479   1              bit a;
 480   1              a=0;
 481   1      
 482   1             start_i2c();
 483   1              while(~sendbyte(0xa2));               //send  slave  address
 484   1              while(~sendbyte(0x02));               //send word address  
 485   1              start_i2c();
 486   1              while(~sendbyte(0xa3));                    
 487   1             for (i=0; i<7; i++)
 488   1                      {
 489   2                              time[i]=rcvbyte();
C51 COMPILER V7.02a   LEDSUBFUC                                                            05/26/2005 13:15:53 PAGE 9   

 490   2                              if (i==6){
 491   3                                      a=1;
 492   3                                      }
 493   2                              ack_i2c(a);
 494   2                      }
 495   1             stop_i2c();
 496   1          
 497   1           
 498   1      }
 499          
 500          
 501          
 502          /************************24C01*****************************************/
 503          
 504          void  get_c_code(uchar *ptr, uchar cnt)
 505          {     
 506   1             uchar i;
 507   1               bit a;
 508   1               a=0;
 509   1             start_i2c();
 510   1              while(~sendbyte(0xa0));              //write address 
 511   1              while(~sendbyte(0x00));
 512   1             start_i2c();
 513   1               while(~sendbyte(0xa1));            //begin read data
 514   1              for (i=0; i<cnt; i++)
 515   1                      {
 516   2                               *(ptr+i) = rcvbyte();
 517   2                               if (i==(cnt-1))
 518   2                                      {
 519   3                                              a=1;
 520   3                                      }
 521   2                               ack_i2c(a);
 522   2                      }
 523   1              stop_i2c();
 524   1      }
 525                  
 526          
 527          
 528          void store_c_code (uchar *ptr, uchar  cnt)
 529          {      
 530   1              uchar i, j, res;
 531   1      
 532   1              i =(uchar) cnt/16;
 533   1              res = (uchar)cnt%16;
 534   1              while (i>0)
 535   1                      {                                                                      //send  16 byte data
 536   2                              start_i2c();
 537   2                              while (~sendbyte(0xa0))
 538   2                                      {
 539   3                                           delay15();
 540   3                                      }
 541   2                              while (~sendbyte(0x00))
 542   2      
 543   2                              for (j=0; j<16; j++)
 544   2                                      {
 545   3                                              while (~sendbyte(*(ptr+j)));
 546   3                                      }
 547   2                              ptr+=16;
 548   2                              stop_i2c();
 549   2                              i--;
 550   2                      }
 551   1              if (res>0) {                                                      //send  reserved data
C51 COMPILER V7.02a   LEDSUBFUC                                                            05/26/2005 13:15:53 PAGE 10  

 552   2                              
 553   2                      start_i2c();
 554   2                      while (~sendbyte(0xa0))
 555   2                                      {
 556   3                                           delay15();
 557   3                                      }
 558   2                      for (j=0; j<res; j++ )
 559   2                              {
 560   3                                      while(~sendbyte(*(ptr+j)));
 561   3                              }
 562   2                      stop_i2c();
 563   2                      
 564   2                      }
 565   1      }
 566          
 567          
 568          
 569          
 570          
 571          
 572          
 573          
 574          
 575          
 576          
 577          
 578          
 579          
 580          
 581          
 582          
 583          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1093    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     11      17
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----       7
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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