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

📄 spidrv.lst

📁 华邦串行flash W25X40 读写源代码
💻 LST
📖 第 1 页 / 共 3 页
字号:
 402          void IO_FastRead_nBytes(uint32 Dst_Addr, uchar nBytes_128)
 403          {
 404   1              uchar i = 0;
 405   1              
 406   1              _cs = 0;                                        /* enable device */
 407   1              IO_Send_Byte(W25P_FastReadData);                /* read command */
 408   1              IO_Send_Byte(((Dst_Addr & 0xFFFFFF) >> 16));    /* send 3 address bytes */
 409   1              IO_Send_Byte(((Dst_Addr & 0xFFFF) >> 8));
 410   1              IO_Send_Byte(Dst_Addr & 0xFF);
 411   1              IO_Send_Byte(0xFF);                     /*dummy byte*/
 412   1              for (i = 0; i < nBytes_128; i++)        /* read until no_bytes is reached */
 413   1              {
 414   2                      upper_128[i] = IO_Get_Byte();   /* receive byte and store at address 80H - FFH */
 415   2              }
 416   1              _cs = 1;                                /* disable device */
 417   1      
 418   1      }
 419          
 420          void IO_Write_Byte(uint32 Dst_Addr, uchar byte)
 421          {
 422   1              _cs = 0;                                        /* enable device */
 423   1              IO_Write_Enable();                              /* set WEL */
 424   1              IO_Wait_Busy();
 425   1              
 426   1              _cs = 0;        
 427   1              IO_Send_Byte(W25P_PageProgram);                 /* send Byte Program command */
C51 COMPILER V7.50   SPIDRV                                                                09/25/2008 17:18:42 PAGE 8   

 428   1              IO_Send_Byte(((Dst_Addr & 0xFFFFFF) >> 16));    /* send 3 address bytes */
 429   1              IO_Send_Byte(((Dst_Addr & 0xFFFF) >> 8));
 430   1              IO_Send_Byte(Dst_Addr & 0xFF);
 431   1              IO_Send_Byte(byte);                     /* send byte to be programmed */
 432   1              _cs = 1;                                /* disable device */
 433   1      }
 434          
 435          void test_page(uchar addr)
 436          {
 437   1              uint i; uchar byte;
 438   1              uint32 Dst_Addr;        
 439   1              _cs = 0;                                        /* enable device */
 440   1              IO_Write_Enable();                              /* set WEL */
 441   1              _cs = 0;
 442   1              Dst_Addr = (uint32)addr*256;
 443   1              Dst_Addr = 0x0ff000;//(uint32)addr*256;
 444   1              IO_Send_Byte(W25P_PageProgram);                 /* send Byte Program command */
 445   1              IO_Send_Byte((uchar)((Dst_Addr & 0xFFFFFF) >> 16));     /* send 3 address bytes */
 446   1              IO_Send_Byte((uchar)((Dst_Addr & 0xFFFF) >> 8));
 447   1              IO_Send_Byte((uchar)(Dst_Addr & 0xFF));
 448   1              
 449   1              for (i = 0; i < 256; i++)
 450   1              {
 451   2                      //byte = upper_128[i];
 452   2                      IO_Send_Byte(i);                /* send byte to be programmed */
 453   2              }       
 454   1              _cs = 1;        
 455   1              
 456   1              delay_nms(5);
 457   1                                      while(1)
 458   1                                      {
 459   2                                              tx_buff[0] = IO_Read_StatusReg();
 460   2                                              trace(tx_buff,1);
 461   2                                              if(tx_buff[0] == 0)
 462   2                                                      break;
 463   2                                      }
 464   1              Dst_Addr = 0x0ff000;
 465   1              for (i = 0; i < 256; i++)
 466   1              {
 467   2                      byte = IO_Read_Byte(Dst_Addr+i);
 468   2                      ES = 0;
 469   2                      SBUF = byte;
 470   2                      while (TI == 0);
 471   2                      TI = 0;
 472   2                      ES = 1;
 473   2              }
 474   1                              
 475   1      }
 476          
 477          void read_page(uchar addr)
 478          {
 479   1              uint i;
 480   1              uchar byte;
 481   1              uint32 Dst_Addr;
 482   1              Dst_Addr = addr*256;
 483   1              Dst_Addr = 0x0ff000;
 484   1              for (i = 0; i < 256; i++)
 485   1              {
 486   2                      byte = IO_Read_Byte(Dst_Addr+i);
 487   2                      ES = 0;
 488   2                      SBUF = byte;
 489   2                      while (TI == 0);
C51 COMPILER V7.50   SPIDRV                                                                09/25/2008 17:18:42 PAGE 9   

 490   2                      TI = 0;
 491   2                      ES = 1;
 492   2              }
 493   1      }
 494          
 495          
 496          void IO_Write_nBytes(uint32 Dst_Addr, uchar nBytes_128)
 497          {       
 498   1              uchar i, byte;  
 499   1              _cs = 0;                                        /* enable device */
 500   1              IO_Write_Enable();                              /* set WEL */
 501   1              _cs = 0;
 502   1              IO_Send_Byte(W25P_PageProgram);                 /* send Byte Program command */
 503   1              IO_Send_Byte(((Dst_Addr & 0xFFFFFF) >> 16));    /* send 3 address bytes */
 504   1              IO_Send_Byte(((Dst_Addr & 0xFFFF) >> 8));
 505   1              IO_Send_Byte(Dst_Addr & 0xFF);
 506   1              
 507   1              for (i = 0; i < nBytes_128; i++)
 508   1              {
 509   2                      byte = upper_128[i];
 510   2                      IO_Send_Byte(byte);             /* send byte to be programmed */
 511   2              }       
 512   1              _cs = 1;                                /* disable device */
 513   1              
 514   1              //printf("\nPage program (%d nBytes)! please waiting....\n");
 515   1      }
 516          
 517          void IO_Erase_Chip()
 518          {
 519   1              _cs = 0;                                /* enable device */
 520   1              IO_Write_Enable();                              /* set WEL */
 521   1              _cs = 0;
 522   1              IO_Wait_Busy();
 523   1              _cs = 0;
 524   1              IO_Send_Byte(W25P_ChipErase);           /* send Chip Erase command */
 525   1              _cs = 1;                                /* disable device */
 526   1      }
 527          
 528          void IO_Erase_Sector(uint32 Dst_Addr)
 529          {
 530   1              _cs = 0;                                        /* enable device */
 531   1              IO_Write_Enable();                              /* set WEL */
 532   1              _cs = 0;
 533   1              IO_Send_Byte(W25P_SectorErase);                 /* send Sector Erase command */
 534   1              IO_Send_Byte((uchar)((Dst_Addr & 0xFFFFFF) >> 16));     /* send 3 address bytes */
 535   1              IO_Send_Byte((uchar)((Dst_Addr & 0xFFFF) >> 8));
 536   1              IO_Send_Byte((uchar)Dst_Addr & 0xFF);
 537   1              _cs = 1;                                        /* disable device */
 538   1      }
 539          
 540          void Verify(uchar byte, uchar cor_byte)
 541          {
 542   1              if (byte != cor_byte)
 543   1              {
 544   2                      while(1);
 545   2                              //LED_Error = 0; /* display to view error on LED. */                    
 546   2              }
 547   1      }
 548          
 549          void IO_Write_Disable()
 550          {
 551   1              _cs = 0;                                /* enable device */
C51 COMPILER V7.50   SPIDRV                                                                09/25/2008 17:18:42 PAGE 10  

 552   1              IO_Send_Byte(W25P_WriteDisable);        /* send W25P_Write_Disable command */
 553   1              _cs = 1;                                /* disable device */
 554   1      }
 555          
 556          void myputchar(uchar c)
 557          {       
 558   1              ES = 0;
 559   1              SBUF = c;
 560   1              while (TI == 0);
 561   1              TI = 0;
 562   1              ES = 1;
 563   1      }
 564          
 565          void trace(uchar *str,uchar len)
 566          {
 567   1              uint i;
 568   1              for(i=0;i<len;i++)
 569   1              {
 570   2                      myputchar(*str);
 571   2                      str++;
 572   2              }
 573   1      }
 574          
 575          
 576          
 577          //IO_Read_StatusReg             Reads the status register of the serial flash
 578          //IO_Write_StatusReg            Performs a write to the status register
 579          //IO_Write_Enable                       Write enables the serial flash
 580          //IO_Write_Disable              Write disables the serial flash
 581          //IO_Read_ID1                   Reads the device ID using the instruction 0xAB
 582          //IO_Read_ID2                   Reads the manufacturer ID and device ID with 0x90
 583          //IO_Read_Byte                  Reads one byte from the serial flash and returns byte(max of 20 MHz CLK frequency)
 584          //IO_Read_nBytes                        Reads multiple bytes(max of 20 MHz CLK frequency)
 585          //IO_FastRead_Byte              Reads one byte from the serial flash and returns byte(max of 33 MHz CLK frequency)
 586          //IO_FastRead_nBytes            Reads multiple bytes(max of 33 MHz CLK frequency)
 587          //IO_Write_Byte                 Program one byte to the serial flash
 588          //IO_Write_nBytes                       Program n bytes to the serial flash, n<=256
 589          //IO_Erase_Chip                 Erases entire serial flash
 590          //IO_Erase_Sector                       Erases one sector (64 KB) of the serial flash
 591          //IO_Wait_Busy                  Polls status register until busy bit is low


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1468    ----
   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 + -