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

📄 distm.lst

📁 一个分选系统的软件:用SmallRtos操作系统
💻 LST
📖 第 1 页 / 共 3 页
字号:
 285   1            RTIME9=date[0];
 286   1            RTIMEB=0x0a;
 287   1            RTIMEA=0x29;
 288   1            i=RTIMEC;
 289   1      }
 290          
 291          void read_time(void)
 292          {uint8 i;//,temp0,temp1,temp2;
 293   1            do{i=RTIMEA;} while((i&0x80)==0x80);//RTIMEA==00 oprate valid
 294   1            date[5]=RTIME0;date[4]=RTIME2;date[3]=RTIME4;
 295   1            //date[2]=RTIME7;date[1]=RTIME8;date[0]=RTIME9;      
 296   1            //temp0=date[5];
 297   1            //disp[0]=temp0&0x0f;
 298   1            //disp[1]=(temp0&0xf0)>>4;
 299   1            //temp1=date[4];disp[2]=temp1&0x0f;disp[3]=(temp1&0xf0)>>4;
 300   1            //temp2=date[3];disp[4]=temp2&0x0f;disp[5]=(temp2&0xf0)>>4;
 301   1            //display();                
 302   1      }                
C51 COMPILER V7.06   DISTM                                                                 06/20/2005 15:36:06 PAGE 6   

 303          void read_date(void)
 304          {uint8 i;//,temp0,temp1,temp2;
 305   1            do{i=RTIMEA;} while((i&0x80)==0x80);
 306   1            date[2]=RTIME7;date[1]=RTIME8;date[0]=RTIME9;
 307   1            //temp0=date[2];disp[0]=temp0&0x0f;disp[1]=(temp0&0xf0)>>4;
 308   1            //temp1=date[1];disp[2]=temp1&0x0f;disp[3]=(temp1&0xf0)>>4;
 309   1            //temp2=date[0];disp[4]=temp2&0x0f;disp[5]=(temp2&0xf0)>>4;//+0x80;
 310   1            //display();
 311   1      }
 312          uint8 BCD_D(uint8 bcd)
 313          {
 314   1              return(((bcd&0xf0)>>4)*10+(bcd&0x0f));
 315   1      }
 316          //uchar D_BCD(uchar d)
 317          //{
 318          //      return(((d/10)<<4)+(d-(d/10)*10));
 319          //}             
 320          void init52(void)
 321          {
 322   1              IE=0xb3;//EA ET2 ES ET0 EX0
 323   1              TMOD=0x21;// 16 bit timer and bound = mode 2 
 324   1              TCON=0x01;//negative trigger interrupt0
 325   1              PCON=0x00;//0x80 bound double
 326   1              SCON=0xd0;//50 8,n,1 parity:odd or even
 327   1              TH1=tab[0];
 328   1              TL1=tab[0];
 329   1              TH0=0xff;// FFc2H 7.4khz ffbf 7khz
 330   1              TL0=0xb3;//ffb4 6khz ff7d 3.5khz
 331   1              TR0=1;
 332   1              //TH2=0xff;// FFc2H 7.4khz ffbf 7khz
 333   1              //TL2=0xb3;//ffb4 6khz ff7d 3.5khz
 334   1              //TR2=1;
 335   1              TR1=1;
 336   1              //P13=1;
 337   1              trans_over=1;
 338   1      }
 339          
 340          void delay(uint16 t)
 341          {uint16 i;//t=1 40us
 342   1              for(i=0;i<t;i++)_nop_();
 343   1              for(i=0;i<t;i++)_nop_();
 344   1      }       
 345          void eerom_start(void)
 346          {
 347   1             CS0=1; _nop_();       
 348   1             SCK=1; _nop_();
 349   1             CS0=0; _nop_();
 350   1      }
 351          
 352          void spi_writebits(uint8 byte,uint8 num_of_bits)
 353          {//SK上升沿数据有效
 354   1              uint8 count;
 355   1              byte=byte<<(8-num_of_bits);
 356   1              for(count=0;count<num_of_bits;count++){
 357   2                      SCK=0;_nop_();_nop_();
 358   2                      byte<<=1;_nop_();_nop_();
 359   2                      SIN=CY;_nop_();_nop_();
 360   2                      SCK=1;_nop_();_nop_();}
 361   1      }               
 362          uint8 spi_readbyte()
 363          {//SK下降沿数据有效
 364   1              uint8 count,byte;
C51 COMPILER V7.06   DISTM                                                                 06/20/2005 15:36:06 PAGE 7   

 365   1              for(count=0;count<8;count++){
 366   2                      SCK=1;_nop_();_nop_();
 367   2                      SCK=0;_nop_();_nop_();
 368   2                      byte<<=1;
 369   2                      if(SO){byte++;}
 370   2                      //byte<<=1;
 371   2                      _nop_();_nop_();}
 372   1                      return (byte);
 373   1      }       
 374          void buffer1write(uint16 len,uint16 start_addr)
 375          {uint16 i;
 376   1              uint8 m;
 377   1              eerom_start();
 378   1              spi_writebits(0x84,8);
 379   1              spi_writebits(0x00,8);
 380   1              spi_writebits(0x00,7);
 381   1              //spi_writebits(0x00,8);
 382   1              spi_writebits((uint8)(start_addr>>8),1);
 383   1              spi_writebits((uint8)(start_addr),8);
 384   1              for(i=0;i<len;i++)
 385   1              {       
 386   2                      m=*(sp+i);
 387   2                      spi_writebits(*(sp+i),8);}
 388   1                      spi_writebits(mon>>8,8);
 389   1                      spi_writebits((uint8)(mon),8);
 390   1              CS0=1;
 391   1      }       
 392          void buffer1topageprogerase(uint16 page)
 393          {//uint i;
 394   1              eerom_start();
 395   1              spi_writebits(0x83,8);
 396   1              spi_writebits(0x00,3);
 397   1              spi_writebits((uint8)(page>>8),4);
 398   1              spi_writebits((uint8)(page),8);
 399   1              spi_writebits(0x00,4);
 400   1              spi_writebits(0x00,5);
 401   1              CS0=1;
 402   1      }       
 403          
 404          void buffer2_read(uint16 len,uint16 byteaddr)
 405          {
 406   1              uint8 m;
 407   1              uint16 i;
 408   1              //k=len+1;
 409   1              eerom_start();
 410   1      
 411   1              spi_writebits(0x56,8);
 412   1              spi_writebits(0x00,8);
 413   1              spi_writebits(0x00,7);
 414   1              spi_writebits((uint8)(byteaddr>>8),1);
 415   1              spi_writebits((uint8)(byteaddr),8);
 416   1              spi_writebits(0x00,8);
 417   1              //spi_writebits(0x00,8);//多这一行每次丢失一字节
 418   1              for(i=0;i<len;i++)
 419   1              {
 420   2              m=spi_readbyte();
 421   2              *(sp0+i)=m;
 422   2              //_nop_();//04423
 423   2              //_nop_();
 424   2              }       
 425   1              
 426   1              CS0=1;
C51 COMPILER V7.06   DISTM                                                                 06/20/2005 15:36:06 PAGE 8   

 427   1      }
 428                  
 429          void page_buffer2_trans(uint16 page)
 430          { 
 431   1              eerom_start();
 432   1              spi_writebits(0x55,8);
 433   1              spi_writebits(0x00,3);
 434   1              spi_writebits((uint8)(page>>8),4);
 435   1              spi_writebits((uint8)(page),8);
 436   1              spi_writebits(0x00,4);
 437   1              spi_writebits(0x00,5);
 438   1              CS0=1;
 439   1              delay(400);
 440   1      }       
 441                                  
 442          void bytes_write(uint8 n)
 443          {/*byteaddr:一页内的字节地址.pa:页地址。n:写字节长度 12bit*/
 444   1      /*写数据时可同时读操作*/
 445   1              uint16 count;//highbyte,
 446   1              //uchar lowbyte,i;
 447   1              
 448   1              count=byteaddr0;
 449   1              byteaddr0+=n;
 450   1              //if(byteaddr0>0xfe){byteaddr0=0;count=0;mon++;}//a page
 451   1              //if(mon>0x0fff) mon=1;                       //4096 page
 452   1              sp=&ram0;
 453   1              sp0=&ram1;//pa=0;
 454   1      
 455   1           buffer1write(0x100,0);//byte lenths=0x100
 456   1           delay(400);
 457   1           buffer1topageprogerase(mon);//mon6m7d
 458   1           //AutoProgViaBuffer1(0x00,20);
 459   1           delay(400);
 460   1       
 461   1           page_buffer2_trans(mon);//pageaddr
 462   1           delay(400);
 463   1           buffer2_read(0x107,0);
 464   1           //lowbyte=mon;
 465   1           //highbyte=mon>>8;
 466   1      if(mon>0x0ff){
 467   2              _nop_();}
 468   1              if(byteaddr0>0xfe){byteaddr0=0;count=0;mon++;}//a page
 469   1              if(mon>0x0fff) mon=1;                       //4096 page
 470   1      
 471   1           pa=mon;
 472   1           *(&pa+1)=mon>>8;
 473   1              sp=&pa; 
 474   1              buffer1write(2,260);
 475   1              delay(400);//buffertopateprogerase(1);       
 476   1           buffer1topageprogerase(0); //pageaddr
 477   1           delay(400);
 478   1              //pageprogviabuf1(1,0x104,2);     
 479   1      
 480   1      }
 481          void selct_page_addr(void)
 482          {uint8 lowbyte,highbyte;
 483   1                      sp0=&pa;
 484   1           page_buffer2_trans(0);//pageaddr
 485   1           delay(400);
 486   1           buffer2_read(2,260);
 487   1           delay(400);
 488   1           highbyte=pa;
C51 COMPILER V7.06   DISTM                                                                 06/20/2005 15:36:06 PAGE 9   

 489   1           lowbyte=*(&pa+1);
 490   1           mon=highbyte+(lowbyte<<8);
 491   1      }
 492          void storage(void)
 493          {//num_in应该存到EEPROM
 494   1              uint8 i,j;
 495   1              //sp=&ram0;
 496   1              j=cjtemp+6;
 497   1              read_date();
 498   1              read_time();
 499   1                   memdata[cjtemp]=date[0];
 500   1                   memdata[cjtemp+1]=date[1];
 501   1                   memdata[cjtemp+2]=date[2];
 502   1                   memdata[cjtemp+3]=date[3];
 503   1                   memdata[cjtemp+4]=date[4];
 504   1                   memdata[cjtemp+5]=date[5];
 505   1                   for(i=0;i<j;i++){
 506   2                      *(sp+num_in)=memdata[i];num_in++;
 507   2                      if(num_in>0xff){
 508   3                               bytes_write(0xff);
 509   3                               num_in=0;
 510   3                               sp=&ram0;}
 511   2                         }
 512   1                   cjtemp=0;//variable=0;//04/10/18
 513   1                   //andata10=andata00;
 514   1                   //andata11=andata01;
 515   1                   
 516   1                   //old_out=out_xdata;
 517   1      }
 518          void serial_INT(void) interrupt 4 using 2
 519          {
 520   1          uint8 i;
 521   1      
 522   1          if(TI){trans_over=1;TI=0;}
 523   1      
 524   1          if(RI){
 525   2              i=SBUF;
 526   2              if(!head00_over){
 527   3                  if(i==0xfc){ head00_over=1;}}
 528   2              //else if(!head01_over){if(i==0xfc){head01_over=1;}}    
 529   2              else if(!head02_over){ //re0_c=0;
 530   3                           if(i==0x33){rcv_inf00=7;head02_over=1;}
 531   3                           else if(i==0x01){head02_over=1;rcv_inf00=1;}
 532   3                           else if(i==0x02){rcv_inf00=2;head00_over=0;head01_over=0;head02_over=0;}
 533   3                           else if(i==0x03){head02_over=1;rcv_inf00=3;}
 534   3                           else if(i==0x04){head02_over=1;rcv_inf00=4;}
 535   3                           else if(i==0x05){rcv_inf00=5;head00_over=0;head01_over=0;head02_over=0;}
 536   3                           else{ if(i==0x06){rcv_inf00=6;head00_over=0;head01_over=0;head02_over=0;}}}
 537   2                                                      
 538   2              else{
 539   3                     if(rcv_inf00==0x07){
 540   4                                     rx[re0_c]=i;re0_c++;rcv_flag=0;noinf_4s=0;
 541   4                                     if(re0_c>=5){rcv_inf01=7;re0_c=0;
 542   5                                   head00_over=0;head01_over=0;head02_over=0;}}
 543   3                     else if(rcv_inf00==0x01){date[re0_c]=i;re0_c++;
 544   4                          if(re0_c==6){head00_over=0;head01_over=0;head02_over=0;
 545   5                               rcv_inf01=1;re0_c=0;}}
 546   3                     else if(rcv_inf00==0x03){lenth[re0_c]=i;re0_c++;
 547   4                           if(re0_c>=4){rcv_inf01=2;re0_c=0;
 548   5                                   head00_over=0;head01_over=0;head02_over=0;}}
 549   3                     else if(rcv_inf00==0x04){date[0]=i;rcv_inf01=3;head00_over=0;head01_over=0;head02_over=0;}}
 550   2              RI=0;
C51 COMPILER V7.06   DISTM                                                                 06/20/2005 15:36:06 PAGE 10  

 551   2              }
 552   1      }
 553          void send_y_h(void)
 554          {uint8 i;
 555   1               read_date();read_time();
 556   1               if(rcv_inf00==0x02){
 557   2                      rcv_inf00=0;
 558   2               while(!trans_over){}
 559   2               SBUF=0xfc;trans_over=0;
 560   2               while(!trans_over){}
 561   2               SBUF=0x02;trans_over=0;
 562   2               
 563   2               for(i=0;i<6;i++){
 564   3               while(!trans_over){}
 565   3               SBUF=date[i];
 566   3               trans_over=0;}}
 567   1               if(rcv_inf10==0x02){
 568   2                      rcv_inf10=0;
 569   2                      while((UARTLSR&0x60)==0){}
 570   2                      UARTTHR=0xfc;
 571   2                      while((UARTLSR&0x60)==0){}
 572   2                      UARTTHR=0xfc;
 573   2                      for(i=0;i<6;i++){
 574   3      
 575   3                      while((UARTLSR&0x60)==0){}
 576   3                      UARTTHR=date[i];}}

⌨️ 快捷键说明

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