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

📄 at45db161d.lst

📁 通过车载终端采集GPS数据
💻 LST
📖 第 1 页 / 共 2 页
字号:
 237   1          spi_csoff();//SPI_CS = 1;
 238   1          SPI_CLK = 1;
 239   1      //需要延迟3-6ms
C51 COMPILER V7.09   AT45DB161D                                                            09/16/2008 09:20:10 PAGE 5   

 240   1          delayMs(6);
 241   1      }
 242          
 243          /**3+12+9*/
 244          void page_erase(Uint16 pageAddr)
 245          {
 246   1          Byte addr[3];
 247   1          Byte i;
 248   1          for (i=0; i<3; i++)
 249   1              addr[i] = 0;
 250   1          pageAddr <<= 1;
 251   1          spi_csoff();//SPI_CS = 1;
 252   1          
 253   1          addr[0] = ((Byte*)&pageAddr)[0];
 254   1          addr[1] = ((Byte*)&pageAddr)[1];
 255   1          spi_cson();//SPI_CS=0;
 256   1          spi_write(ERASE_PAGE);
 257   1          for (i=0; i<3; i++)
 258   1              spi_write(addr[i]);
 259   1          spi_csoff();//SPI_CS = 1;
 260   1          SPI_CLK = 1;
 261   1          //需要延迟15-35ms
 262   1      }
 263          
 264          /***3+9+12***/
 265          void block_erase(Uint16 BlockAddr)
 266          {
 267   1          Byte addr[3];
 268   1          Byte i;
 269   1          delayMs(10000);
 270   1          for (i=0; i<3; i++)
 271   1              addr[i] = 0;
 272   1          BlockAddr <<= 4;
 273   1          spi_csoff();//SPI_CS = 1;
 274   1          
 275   1          addr[0] = ((Byte*)&BlockAddr)[0];
 276   1          addr[1] = ((Byte*)&BlockAddr)[1];
 277   1          spi_cson();//SPI_CS=0;
 278   1          spi_write(ERASE_BLOCK);
 279   1          for (i=0; i<3; i++)
 280   1              spi_write(addr[i]);
 281   1          spi_csoff();//SPI_CS = 1;
 282   1          SPI_CLK = 1;
 283   1          //需要延迟45-100ms
 284   1          delayMs(3000);
 285   1      }
 286          
 287          
 288          void chip_erase()
 289          {
 290   1      }
 291          /***************************************
 292          sectorAddr:1-15   1-15个sector
 293                     16     0a
 294                     17     0b
 295          *****************************************/
 296          void sector_erase(Byte sectorAddr)
 297          {
 298   1          Byte addr[3];
 299   1          Byte i;
 300   1          for (i=0; i<3; i++)
 301   1              addr[i] = 0;    
C51 COMPILER V7.09   AT45DB161D                                                            09/16/2008 09:20:10 PAGE 6   

 302   1          
 303   1          delayMs(10000);
 304   1          if (17 == sectorAddr)
 305   1          {
 306   2              addr[1] = 0x10;
 307   2          }
 308   1          else if (sectorAddr < 16)
 309   1          {
 310   2              sectorAddr <<= 1;
 311   2              addr[0] = sectorAddr;
 312   2          }
 313   1      
 314   1          spi_csoff();//SPI_CS=0;
 315   1          spi_write(ERASE_SECTOR);
 316   1          for (i=0; i<3; i++)
 317   1              spi_write(addr[i]);
 318   1          spi_csoff();//SPI_CS = 1;
 319   1          SPI_CLK = 1;
 320   1          //需要延迟1.5-6s
 321   1          delayMs(10000);
 322   1      }
 323          
 324          /********3+12+9***********/
 325          void program_page_throughbuf(Byte bufNum, Uint16 bufAddr, Uint16 pageAddr, Uint16 nLen, Byte* pBuf)
 326          {
 327   1          Byte addr[3];
 328   1          Byte command;
 329   1          Uint16 i;
 330   1          spi_csoff();//SPI_CS = 1;
 331   1          
 332   1          for (i=0; i<3; i++)
 333   1              addr[i] = 0; 
 334   1          pageAddr <<= 1;
 335   1          addr[0] = ((Byte*)&pageAddr)[0];
 336   1          addr[1] = ((Byte*)&pageAddr)[1]+((Byte*)&bufAddr)[0];
 337   1          addr[2] = ((Byte*)&bufAddr)[1];
 338   1          if (1 == bufNum)
 339   1              command = PROGRAM_PAGE_BYBUF1;
 340   1          else
 341   1              command = PROGRAM_PAGE_BYBUF2;
 342   1      
 343   1          spi_cson();//SPI_CS = 0;
 344   1          spi_write(command);
 345   1          for (i=0; i<3; i++)
 346   1              spi_write(addr[i]);
 347   1          for (i=0; i<nLen; i++)
 348   1              spi_write(pBuf[i]);
 349   1          spi_csoff();//SPI_CS = 1;
 350   1          SPI_CLK = 1;
 351   1          //需要延迟17-40ms
 352   1          delayMs(40);
 353   1      }
 354          
 355          /*********编程1页用四段缓冲*************/
 356          /*每段缓冲的大小为128Byte
 357          /*buffer起始地址为0
 358          /****************************************/
 359          void program_onepage_throughbuf(Byte bufNum, Uint16 pageAddr, Byte* pBuf1, Byte* pBuf2, Byte* pBuf3, Byte*
             - pBuf4)
 360          {
 361   1          Byte addr[3];
 362   1          Byte command;
C51 COMPILER V7.09   AT45DB161D                                                            09/16/2008 09:20:10 PAGE 7   

 363   1          Uint16 i;
 364   1          spi_csoff();//SPI_CS = 1;
 365   1          
 366   1          for (i=0; i<3; i++)
 367   1              addr[i] = 0; 
 368   1          pageAddr <<= 1;
 369   1          addr[0] = ((Byte*)&pageAddr)[0];
 370   1          addr[1] = ((Byte*)&pageAddr)[1];
 371   1          addr[2] = 0;
 372   1          if (1 == bufNum)
 373   1              command = PROGRAM_PAGE_BYBUF1;
 374   1          else
 375   1              command = PROGRAM_PAGE_BYBUF2;
 376   1      
 377   1          spi_cson();//SPI_CS = 0;
 378   1          spi_write(command);
 379   1          for (i=0; i<3; i++)
 380   1              spi_write(addr[i]);
 381   1          for (i=0; i<128; i++)
 382   1              spi_write(pBuf1[i]);
 383   1          for (i=0; i<128; i++)
 384   1              spi_write(pBuf2[i]);
 385   1          for (i=0; i<128; i++)
 386   1              spi_write(pBuf3[i]);
 387   1          for (i=0; i<128; i++)
 388   1              spi_write(pBuf4[i]);
 389   1          spi_csoff();//SPI_CS = 1;
 390   1          SPI_CLK = 1;
 391   1          //需要延迟17-40ms
 392   1          delayMs(40);
 393   1      }
 394          
 395          Byte read_status_register()
 396          {
 397   1          Byte nValue;
 398   1          nValue = 0;
 399   1          spi_cson();//SPI_CS = 0;
 400   1          spi_write(READ_STATUS_REG);
 401   1          nValue = spi_read();
 402   1          spi_csoff();//SPI_CS = 1;
 403   1          SPI_CLK = 1;
 404   1          return nValue;
 405   1      }
 406          
 407          void  Program_configure_reg()
 408          {
 409   1          spi_csoff();//SPI_CS = 1;
 410   1          spi_cson();//SPI_CS = 0;
 411   1          spi_write(0x3d);
 412   1          spi_write(0x2a);
 413   1          spi_write(0x80);  
 414   1          spi_write(0xa6); 
 415   1          spi_csoff();//SPI_CS = 1;
 416   1          SPI_CLK = 1;
 417   1          //需要延迟3-6ms
 418   1          delayMs(6);
 419   1      }
 420          
 421          /*******************
 422          *读取ID号
 423          *返回值:OK表示值吻合
 424                  KO表示不对
C51 COMPILER V7.09   AT45DB161D                                                            09/16/2008 09:20:10 PAGE 8   

 425          *******************/
 426          Byte read_deviceid()
 427          {
 428   1          Byte id[4];
 429   1          Byte i;
 430   1          id[0] = 0;
 431   1          id[1] = 0;
 432   1          id[2] = 0;
 433   1          id[3] = 0;
 434   1          spi_cson();//SPI_CS = 0;
 435   1          spi_write(READ_DEVICEID);
 436   1          for (i=0; i<4; i++)
 437   1          {
 438   2              id[i] = spi_read();
 439   2          }
 440   1      
 441   1          spi_csoff();//SPI_CS = 1;
 442   1          SPI_CLK = 1;
 443   1          if ((id[0] == MANU_ID) && (id[1] == DEVICE_ID1) &&
 444   1              (id[2] == DEVICE_ID2) && (id[3] == DEVICE_ID3))
 445   1              return OK;
 446   1          else
 447   1              return KO;
 448   1      }
 449          
 450          
 451          void check_toready()
 452          {
 453   1          Byte nValue;
 454   1          nValue = 0;
 455   1          spi_cson();//SPI_CS = 0;
 456   1          spi_write(READ_STATUS_REG);
 457   1          nValue = spi_read();
 458   1          while (0 == (nValue & 0x80))
 459   1          {
 460   2              nValue = spi_read();
 461   2          }
 462   1          spi_csoff();//SPI_CS = 1;
 463   1          SPI_CLK = 1;
 464   1      }
 465          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   2580    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----     128
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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