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

📄 spidrv.lst

📁 大容量Flash存储器W25X16,W25X32,W25X64读写擦除程序
💻 LST
📖 第 1 页 / 共 3 页
字号:
 382   1              W25X_CS = 0;                                    /* enable device */
 383   1              SPI_Send_Byte(W25X_FastReadData);               /* read command */
 384   1              SPI_Send_Byte(((Dst_Addr & 0xFFFFFF) >> 16));   /* send 3 address bytes */
 385   1              SPI_Send_Byte(((Dst_Addr & 0xFFFF) >> 8));
 386   1              SPI_Send_Byte(Dst_Addr & 0xFF);
 387   1              SPI_Send_Byte(0xFF);                    /*dummy byte*/
 388   1              for (i = 0; i < nBytes_128; i++)        /* read until no_bytes is reached */
 389   1              {
 390   2                      upper_128[i] = SPI_Get_Byte();  /* receive byte and store at address 80H - FFH */
 391   2              }
 392   1              W25X_CS = 1;                            /* disable device */
 393   1      
 394   1      }
 395          //=================================================================================================
 396          void SPI_Write_Byte(uint32 Dst_Addr, uchar byte)
 397          {
 398   1              W25X_CS = 0;                                    /* enable device */
 399   1              SPI_Write_Enable();                             /* set WEL */
 400   1              SPI_Wait_Busy();
 401   1              
 402   1              W25X_CS = 0;    
 403   1              SPI_Send_Byte(W25X_PageProgram);                /* send Byte Program command */
 404   1              SPI_Send_Byte(((Dst_Addr & 0xFFFFFF) >> 16));   /* send 3 address bytes */
 405   1              SPI_Send_Byte(((Dst_Addr & 0xFFFF) >> 8));
 406   1              SPI_Send_Byte(Dst_Addr & 0xFF);
 407   1              SPI_Send_Byte(byte);                    /* send byte to be programmed */
 408   1              W25X_CS = 1;                            /* disable device */
 409   1      }
 410          //=================================================================================================
 411          void test_page(uchar addr)
 412          {
 413   1              uint i; uchar byte;
 414   1              uint32 Dst_Addr;        
 415   1              W25X_CS = 0;                                    /* enable device */
 416   1              SPI_Write_Enable();                             /* set WEL */
 417   1              W25X_CS = 0;
 418   1              Dst_Addr = (uint32)addr*256;
 419   1              Dst_Addr = 0x0ff000;//(uint32)addr*256;
 420   1              SPI_Send_Byte(W25X_PageProgram);                /* send Byte Program command */
 421   1              SPI_Send_Byte((uchar)((Dst_Addr & 0xFFFFFF) >> 16));    /* send 3 address bytes */
 422   1              SPI_Send_Byte((uchar)((Dst_Addr & 0xFFFF) >> 8));
 423   1              SPI_Send_Byte((uchar)(Dst_Addr & 0xFF));
 424   1              
 425   1              for (i = 0; i < 256; i++)
 426   1              {
 427   2                      //byte = upper_128[i];
C51 COMPILER V7.50   SPIDRV                                                                01/11/2009 22:30:34 PAGE 8   

 428   2                      SPI_Send_Byte(i);               /* send byte to be programmed */
 429   2              }       
 430   1              W25X_CS = 1;    
 431   1              
 432   1              delay_nms(5);
 433   1                                      while(1)
 434   1                                      {
 435   2                                              tx_buff[0] = SPI_Read_StatusReg();
 436   2                                              trace(tx_buff,1);
 437   2                                              if(tx_buff[0] == 0)
 438   2                                                      break;
 439   2                                      }
 440   1              Dst_Addr = 0x0ff000;
 441   1              for (i = 0; i < 256; i++)
 442   1              {
 443   2                      byte = SPI_Read_Byte(Dst_Addr+i);
 444   2                      ES = 0;
 445   2                      SBUF = byte;
 446   2                      while (TI == 0);
 447   2                      TI = 0;
 448   2                      ES = 1;
 449   2              }
 450   1                              
 451   1      }
 452          //=================================================================================================
 453          void read_page(uchar addr)
 454          {
 455   1              uint i;
 456   1              uchar byte;
 457   1              uint32 Dst_Addr;
 458   1              Dst_Addr = addr*256;
 459   1              Dst_Addr = 0x0ff000;
 460   1              for (i = 0; i < 256; i++)
 461   1              {
 462   2                      byte = SPI_Read_Byte(Dst_Addr+i);
 463   2                      ES = 0;
 464   2                      SBUF = byte;
 465   2                      while (TI == 0);
 466   2                      TI = 0;
 467   2                      ES = 1;
 468   2              }
 469   1      }
 470          //=================================================================================================
 471          void SPI_Write_nBytes(uint32 Dst_Addr, uchar nBytes_128)
 472          {       
 473   1              uchar i, byte;  
 474   1              W25X_CS = 0;                                    /* enable device */
 475   1              SPI_Write_Enable();                             /* set WEL */
 476   1              W25X_CS = 0;
 477   1              SPI_Send_Byte(W25X_PageProgram);                /* send Byte Program command */
 478   1              SPI_Send_Byte(((Dst_Addr & 0xFFFFFF) >> 16));   /* send 3 address bytes */
 479   1              SPI_Send_Byte(((Dst_Addr & 0xFFFF) >> 8));
 480   1              SPI_Send_Byte(Dst_Addr & 0xFF);
 481   1              
 482   1              for (i = 0; i < nBytes_128; i++)
 483   1              {
 484   2                      byte = upper_128[i];
 485   2                      SPI_Send_Byte(byte);            /* send byte to be programmed */
 486   2              }       
 487   1              W25X_CS = 1;                            /* disable device */
 488   1              
 489   1              //printf("\nPage program (%d nBytes)! please waiting....\n");
C51 COMPILER V7.50   SPIDRV                                                                01/11/2009 22:30:34 PAGE 9   

 490   1      }
 491          //=================================================================================================
 492          void SPI_Erase_Chip()
 493          {
 494   1              W25X_CS = 0;                            /* enable device */
 495   1              SPI_Write_Enable();                             /* set WEL */
 496   1              W25X_CS = 0;
 497   1              SPI_Wait_Busy();
 498   1              W25X_CS = 0;
 499   1              SPI_Send_Byte(W25X_ChipErase);          /* send Chip Erase command */
 500   1              W25X_CS = 1;                            /* disable device */
 501   1      }
 502          //=================================================================================================
 503          void SPI_Erase_Sector(uint32 Dst_Addr)
 504          {
 505   1              W25X_CS = 0;                                                                            //      enable device
 506   1              SPI_Write_Enable();                                                                     //      set WEL
 507   1              W25X_CS = 0;
 508   1              SPI_Send_Byte(W25X_SectorErase);                        /* send Sector Erase command */
 509   1              SPI_Send_Byte((uchar)((Dst_Addr & 0xFFFFFF) >> 16));    /* send 3 address bytes */
 510   1              SPI_Send_Byte((uchar)((Dst_Addr & 0xFFFF) >> 8));
 511   1              SPI_Send_Byte((uchar)Dst_Addr & 0xFF);
 512   1              W25X_CS = 1;                                    /* disable device */
 513   1      }
 514          
 515          void Verify(uchar byte, uchar cor_byte)
 516          {
 517   1              if (byte != cor_byte)
 518   1              {
 519   2                      while(1);
 520   2                              //LED_Error = 0; /* display to view error on LED. */                    
 521   2              }
 522   1      }
 523          //=================================================================================================
 524          void SPI_WriteW25X_Disable()
 525          {
 526   1              W25X_CS = 0;                                                    //      enable device
 527   1              SPI_Send_Byte(W25X_WriteDisable);               //      send W25X_WriteW25X_DIsable command
 528   1              W25X_CS = 1;                                                    //      disable device
 529   1      }
 530          //=================================================================================================
 531          void myputchar(uchar c)
 532          {       
 533   1              ES = 0;
 534   1              SBUF = c;
 535   1              while (TI == 0);
 536   1              TI = 0;
 537   1              ES = 1;
 538   1      }
 539          //=================================================================================================
 540          void trace(uchar *str,uchar len)
 541          {       uint i;
 542   1              for(i=0;i<len;i++)      {       myputchar(*str);        str++;  }
 543   1      }
 544          //=================================================================================================
 545          //SPI_Read_StatusReg            Reads the status register of the serial flash
 546          //SPI_Write_StatusReg           Performs a write to the status register
 547          //SPI_Write_Enable                      Write enables the serial flash
 548          //SPI_WriteW25X_Disable         Write disables the serial flash
 549          //SPI_Read_ID1                          Reads the device ID using the instruction 0xAB
 550          //SPI_Read_ID2                          Reads the manufacturer ID and device ID with 0x90
 551          //SPI_Read_Byte                         Reads one byte from the serial flash and returns byte(max of 20 MHz CLK frequency)
C51 COMPILER V7.50   SPIDRV                                                                01/11/2009 22:30:34 PAGE 10  

 552          //SPI_Read_nBytes                       Reads multiple bytes(max of 20 MHz CLK frequency)
 553          //SPI_FastRead_Byte                     Reads one byte from the serial flash and returns byte(max of 33 MHz CLK frequency)
 554          //SPI_FastRead_nBytes           Reads multiple bytes(max of 33 MHz CLK frequency)
 555          //SPI_Write_Byte                        Program one byte to the serial flash
 556          //SPI_Write_nBytes                      Program n bytes to the serial flash, n<=256
 557          //SPI_Erase_Chip                        Erases entire serial flash
 558          //SPI_Erase_Sector                      Erases one sector (64 KB) of the serial flash
 559          //SPI_Wait_Busy                         Polls status register until busy bit is low
 560          //=================================================================================================


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1476    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     33      49
   IDATA SIZE       =   ----    ----
   BIT SIZE         =      2    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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