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

📄 sd.lst

📁 FAT32文件系统源码
💻 LST
📖 第 1 页 / 共 2 页
字号:
 239   1              // [73:72] == sectorBuffer.data[6] && 0x03
 240   1              // [71:64] == sectorBuffer.data[7]
 241   1              // [63:62] == sectorBuffer.data[8] && 0xc0
C51 COMPILER V7.02a   SD                                                                   12/22/2010 21:07:57 PAGE 5   

 242   1              vinf->sector_count = sectorBuffer.dat[6] & 0x03;
 243   1              vinf->sector_count <<= 8;
 244   1              vinf->sector_count += sectorBuffer.dat[7];
 245   1              vinf->sector_count <<= 2;
 246   1              vinf->sector_count += (sectorBuffer.dat[8] & 0xc0) >> 6;
 247   1                      
 248   1              // get the val for C_SIZE_MULT. bits [49:47] of sectorBuffer.data
 249   1              // [49:48] == sectorBuffer.data[5] && 0x03
 250   1              // [47]    == sectorBuffer.data[4] && 0x80
 251   1              vinf->sector_multiply = sectorBuffer.dat[9] & 0x03;
 252   1              vinf->sector_multiply <<= 1;
 253   1              vinf->sector_multiply += (sectorBuffer.dat[10] & 0x80) >> 7;
 254   1      
 255   1              // work out the MBs
 256   1              // mega bytes in u08 == C_SIZE / (2^(9-C_SIZE_MULT))
 257   1              vinf->size_MB = vinf->sector_count >> (9-vinf->sector_multiply);
 258   1              // get the name of the card
 259   1              Read_CID_MMC(sectorBuffer.dat);
 260   1              vinf->name[0] = sectorBuffer.dat[3];
 261   1              vinf->name[1] = sectorBuffer.dat[4];
 262   1              vinf->name[2] = sectorBuffer.dat[5];
 263   1              vinf->name[3] = sectorBuffer.dat[6];
 264   1              vinf->name[4] = sectorBuffer.dat[7];
 265   1              vinf->name[5] = 0x00; //end flag
 266   1              //----------------------------------------------------------
 267   1              /*
 268   1              while(1)
 269   1              {
 270   1               P1=~(unsigned char)((vinf->size_MB)>>8);
 271   1               delay(50000);
 272   1               delay(50000);
 273   1               delay(50000);
 274   1               delay(50000);
 275   1               delay(50000);
 276   1               P1=~(unsigned char)((vinf->size_MB));
 277   1               delay(50000);
 278   1               delay(50000);
 279   1               delay(50000);
 280   1               delay(50000);
 281   1               delay(50000);
 282   1              }*/
 283   1          //LCDclrscr();
 284   1          //Print Product name on lcd
 285   1          i=0;
 286   1          //send_s("Product Name:");
 287   1          //while((vinf->name[i]!=0x00)&&(i<16)) send(vinf->name[i++]);
 288   1              //send_s(vinf->name);
 289   1          //Print Card Size(eg:128MB)
 290   1          //gotoxy(1,0);
 291   1          //send_s("Tot:"); 
 292   1          //send_s(ftoa(vinf->size_MB,c_temp,0)); 
 293   1              //send_s("MB ");
 294   1          //gotoxy(2,0);
 295   1          //writestring("sector_mult:"); writeNumber(vinf->sector_multiply);
 296   1          //gotoxy(3,0);
 297   1          //writestring("sect_cnt:"); writeNumber(vinf->sector_count);
 298   1              
 299   1      }
*** WARNING C280 IN LINE 232 OF SD.C: 'c_temp': unreferenced local variable
 300          
 301          //****************************************************************************
 302          //Routine for writing a Block(512Byte) to MMC/SD-Card
C51 COMPILER V7.02a   SD                                                                   12/22/2010 21:07:57 PAGE 6   

 303          //Return 0 if sector writing is completed.
 304          unsigned char MMC_write_sector(unsigned long addr,unsigned char *Buffer)
 305          //****************************************************************************
 306          {  
 307   1         unsigned char tmp,retry;
 308   1         unsigned int i;
 309   1         //Command 24 is a writing blocks command for MMC/SD-Card.
 310   1         unsigned char CMD[] = {0x58,0x00,0x00,0x00,0x00,0xFF}; 
 311   1         //send_s("Write Sector Start!!");
 312   1         EA=0; //clear all interrupt.
 313   1         addr = addr << 9; //addr = addr * 512
 314   1              
 315   1         CMD[1] = ((addr & 0xFF000000) >>24 );
 316   1         CMD[2] = ((addr & 0x00FF0000) >>16 );
 317   1         CMD[3] = ((addr & 0x0000FF00) >>8 );
 318   1      
 319   1         //Send Command CMD24 to MMC/SD-Card (Write 1 Block/512 Bytes)
 320   1         //send_s("Send Command CMD24 to MMC/SD-Card (Write 1 Block/512 Bytes)");
 321   1         retry=0;
 322   1         do
 323   1         {  //Retry 100 times to send command.
 324   2            tmp=Write_Command_MMC(CMD);
 325   2            retry++;
 326   2            if(retry==100) 
 327   2            { 
 328   3              return(tmp); //send commamd Error!
 329   3            }
 330   2         }
 331   1         while(tmp!=0); 
 332   1         
 333   1         //Before writing,send 100 clock to MMC/SD-Card
 334   1         //send_s("Before writing,send 100 clock to MMC/SD-Card");
 335   1         for (i=0;i<100;i++)
 336   1         {
 337   2            Read_Byte_MMC();
 338   2         }
 339   1              
 340   1         //Send Start Byte to MMC/SD-Card
 341   1         //send_s("Send Start Byte to MMC/SD-Card");
 342   1         Write_Byte_MMC(0xFE);        
 343   1              
 344   1         //Now send real data Bolck (512Bytes) to MMC/SD-Card
 345   1         //send_s("Now send real data Bolck (512Bytes) to MMC/SD-Card");
 346   1         for (i=0;i<512;i++)
 347   1         {
 348   2            Write_Byte_MMC(*Buffer++); //send 512 bytes to Card
 349   2         }
 350   1      
 351   1         //CRC-Byte 
 352   1         Write_Byte_MMC(0xFF); //Dummy CRC
 353   1         Write_Byte_MMC(0xFF); //CRC Code
 354   1         
 355   1          
 356   1         tmp=Read_Byte_MMC();   // read response
 357   1         if((tmp & 0x1F)!=0x05) // data block accepted ?
 358   1         {
 359   2           SPI_CS=1;
 360   2           return(WRITE_BLOCK_ERROR); //Error!
 361   2         }
 362   1         //Wait till MMC/SD-Card is not busy
 363   1         //send_s("Wait till MMC/SD-Card is not busy");
 364   1         while (Read_Byte_MMC()!=0xff){};
C51 COMPILER V7.02a   SD                                                                   12/22/2010 21:07:57 PAGE 7   

 365   1              
 366   1         //set MMC_Chip_Select to high (MMC/SD-Card Invalid)
 367   1         //send_s("set MMC_Chip_Select to high (MMC/SD-Card Invalid)");
 368   1         SPI_CS=1;
 369   1         //send_s("Write Sector suc!!");
 370   1         return(0);
 371   1      } 
 372          
 373          //***************************************************************************
 374          //Return: [0]-success or something error!
 375          unsigned char MMC_Start_Read_Sector(unsigned long sector)
 376          //***************************************************************************
 377          {  
 378   1         unsigned char retry;
 379   1         //Command 16 is reading Blocks from MMC/SD-Card
 380   1         unsigned char CMD[] = {0x51,0x00,0x00,0x00,0x00,0xFF}; 
 381   1         unsigned char temp;
 382   1         
 383   1         EA=0; //clear all interrupt.
 384   1         //Address conversation(logic block address-->byte address)  
 385   1         sector = sector << 9; //sector = sector * 512
 386   1      
 387   1         CMD[1] = ((sector & 0xFF000000) >>24 );
 388   1         CMD[2] = ((sector & 0x00FF0000) >>16 );
 389   1         CMD[3] = ((sector & 0x0000FF00) >>8 );
 390   1         //Send Command CMD to MMC/SD-Card
 391   1         retry=0;
 392   1         do
 393   1         {  //Retry 100 times to send command.
 394   2            temp=Write_Command_MMC(CMD);
 395   2            retry++;
 396   2            if(retry==100) 
 397   2            {
 398   3              return(READ_BLOCK_ERROR); //block write Error!
 399   3            }
 400   2         }
 401   1         while(temp!=0); 
 402   1                              
 403   1         //Read Start Byte form MMC/SD-Card (FEh/Start Byte)
 404   1         //Now data is ready,you can read it out.
 405   1         while (Read_Byte_MMC() != 0xfe);
 406   1         return 0; //Open a sector successfully!
 407   1      }
 408          
 409          //***************************************************************************
 410          void MMC_get_data(unsigned int Bytes,unsigned char *buffer) 
 411          //***************************************************************************
 412          {
 413   1         unsigned int j;
 414   1         EA=0; //clear all interrupt.
 415   1         for (j=0;((j<Bytes) && (readPos<512));j++)
 416   1         {    
 417   2            *buffer++ = Read_Byte_MMC();
 418   2            readPos++; //read a byte,increase read position
 419   2         }
 420   1         if (readPos==512)  
 421   1         {  //CRC-Bytes
 422   2            Read_Byte_MMC();//CRC - Byte 
 423   2            Read_Byte_MMC();//CRC - Byte
 424   2            readPos=0;      //reset sector read offset 
 425   2            sectorPos++;    //Need to read next sector
 426   2            LBA_Opened=0;   //Set to 1 when a sector is opened.
C51 COMPILER V7.02a   SD                                                                   12/22/2010 21:07:57 PAGE 8   

 427   2            //set MMC_Chip_Select to high (MMC/SD-Card invalid)
 428   2            SPI_CS=1;;  //MMC disable
 429   2         }
 430   1      }
 431          
 432          //***************************************************************************
 433          void MMC_get_data_LBA(unsigned long lba, unsigned int Bytes,unsigned char *buffer)
 434          //***************************************************************************
 435          { //get data from lba address of MMC/SD-Card
 436   1        //If a new sector has to be read then move head
 437   1        if (readPos==0) MMC_Start_Read_Sector(lba); 
 438   1        MMC_get_data(Bytes,buffer);
 439   1      }
 440          
 441          //***************************************************************************
 442          void MMC_LBA_Close()
 443          //***************************************************************************
 444          {  
 445   1         unsigned char temp[1];
 446   1         while((readPos!=0x00)|(LBA_Opened==1))
 447   1         { //read MMC till readPos==0x00
 448   2           MMC_get_data(1, temp); //dummy read,temp is a valid data.
 449   2         }  
 450   1      }
 451          
 452          //***************************************************************************
 453          void MMC_GotoSectorOffset(unsigned long LBA,unsigned int offset)
 454          //***************************************************************************
 455          {  
 456   1         //Find the offset in the sector
 457   1         unsigned char temp[1];
 458   1         MMC_LBA_Close(); //close MMC when read a new sector(readPos=0)
 459   1         while (readPos<offset) MMC_get_data_LBA(LBA,1,temp); //go to offset  
 460   1      }
 461          
 462          
 463          
 464          
 465          
 466          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1724    ----
   CONSTANT SIZE    =     30    ----
   XDATA SIZE       =    105     114
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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