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

📄 test1_main.lst

📁 C8051F340读写SD卡,带文件系统
💻 LST
📖 第 1 页 / 共 2 页
字号:
 164   1      
 165   1         //Create file
 166   1         //FA_OPEN_ALWAYS | FA_WRITE | FA_READ    这个模式可写   不可读
 167   1         //FA_OPEN_EXISTING | FA_WRITE | FA_READ  这个模式可读   不可写
 168   1          if(f_open(&file, "test2.txt", FA_OPEN_ALWAYS | FA_WRITE | FA_READ)) 
 169   1                      transmitString("\r\nFile creat fail!\r\n");
 170   1              else
 171   1              {       
 172   2                      transmitString("\r\nFile creat success!\r\n");
 173   2      
 174   2                      //f_puts(buff, &file);
 175   2                      
 176   2                      
 177   2                              transmitString("\r\nFile write success!\r\n");
C51 COMPILER V7.06   TEST1_MAIN                                                            03/06/2010 17:37:25 PAGE 4   

 178   2                              transmitString("\r\nPress any key to read the file!\r\n");
 179   2                              receiveByte();
 180   2                              for(i=0; i<512; i++)
 181   2                              {
 182   3                                      buff[i] = 0;//i-16位,buff-8位
 183   3                              }       
 184   2                              f_gets(buff, sizeof(buff), &file);
 185   2                              
 186   2                              transmitString("\r\nFile read success!\r\n");
 187   2                              displayData(buff, sizeof(buff));
 188   2                              
 189   2                              
 190   2                      
 191   2                      //Close all files
 192   2                      f_close(&file);
 193   2              }
 194   1              
 195   1          //Unregister a work area before discard it
 196   1          f_mount(0, 0);
 197   1      }
 198          /*测试文件读写操作,文件大小为512字节*/
 199          void test_FileWR()
 200          {
 201   1              FATFS fs;       /*Work area (file system object) for logical drive*/
 202   1          FIL file;      /*file objects*/
 203   1              UINT bw, br;    /*File R/W count*/
 204   1      
 205   1      
 206   1              int i = 0;
 207   1              for(i=0; i<512; i++)
 208   1              {
 209   2                      buff[i] = i+5;//i-16位,buff-8位
 210   2              }       
 211   1              //写文件测试
 212   1              /*Register a work area for logical drive 0*/
 213   1          f_mount(0, &fs);
 214   1      
 215   1          /*Create file*/
 216   1          if(f_open(&file, "test4.dat", FA_CREATE_ALWAYS | FA_WRITE)) 
 217   1                      transmitString("\r\nFile creat fail!\r\n");
 218   1              else
 219   1              {       
 220   2                      transmitString("\r\nFile creat success!\r\n");
 221   2      
 222   2                      if(f_write(&file, buff, 512, &bw))
 223   2                              transmitString("\r\nFile write fail!\r\n");
 224   2                      else
 225   2                      {       
 226   3                              transmitString("\r\nFile write success!\r\n");
 227   3                      }
 228   2                      /*Close all files*/
 229   2                      f_close(&file);
 230   2              }
 231   1              
 232   1          /*Unregister a work area before discard it*/
 233   1          f_mount(0, 0);
 234   1      //读文件测试
 235   1              f_mount(0, &fs);
 236   1      
 237   1          /*Create file*/
 238   1          if(f_open(&file, "test4.dat", FA_OPEN_EXISTING | FA_READ))  
 239   1                      transmitString("\r\nFile creat fail!\r\n");
C51 COMPILER V7.06   TEST1_MAIN                                                            03/06/2010 17:37:25 PAGE 5   

 240   1              else
 241   1              {       
 242   2                      transmitString("\r\nFile creat success!\r\n");
 243   2                              transmitString("\r\nPress any key to read the file!\r\n");
 244   2                              receiveByte();
 245   2                              for(i=0; i<512; i++)
 246   2                              {
 247   3                                      buff[i] = 0;//i-16位,buff-8位
 248   3                              }       
 249   2                              if(f_read(&file, buff, 512, &br))
 250   2                                      transmitString("\r\nFile read fail!\r\n");
 251   2                              else
 252   2                              {       
 253   3                                      transmitString("\r\nFile read success!\r\n");
 254   3                                      transmitString("\r\nPress any key to display the data!\r\n");
 255   3                                      receiveByte();
 256   3                                      displayData(buff, 512);
 257   3                              }
 258   2                      
 259   2                      /*Close all files*/
 260   2                      f_close(&file);
 261   2              }
 262   1              
 263   1          /*Unregister a work area before discard it*/
 264   1          f_mount(0, 0);
 265   1      }
 266          /*void test_FileWR()
 267          {
 268                  FATFS fs;       //Work area (file system object) for logical drive
 269              FIL file;      //file objects
 270                  UINT bw, br;    //File R/W count
 271                  BYTE ress;
 272          
 273                  int i = 0;
 274                  for(i=0; i<512; i++)
 275                  {
 276                          buff[i] = i+1;//i-16位,buff-8位
 277                  }       
 278                  //Register a work area for logical drive 0
 279              f_mount(0, &fs);
 280          
 281              //Create file
 282              if(f_open(&file, "test1.bmp", FA_OPEN_EXISTING | FA_WRITE | FA_READ))       
 283                          transmitString("\r\nFile creat fail!\r\n");
 284                  else
 285                  {       
 286                          transmitString("\r\nFile creat success!\r\n");
 287          
 288                          //if(f_write(&file, buff, 512, &bw))
 289                          //      transmitString("\r\nFile write fail!\r\n");
 290                          //else
 291                          //{     
 292                          //      transmitString("\r\nFile write success!\r\n");
 293                          //      transmitString("\r\nPress any key to read the file!\r\n");
 294                          //      receiveByte();
 295                          //      for(i=0; i<512; i++)
 296                          //      {
 297                          //              buff[i] = 0;//i-16位,buff-8位
 298                          //      }
 299                          for(;;)//读大文件
 300                          {
 301                                  if(ress=f_read(&file, buff, 512, &br))
C51 COMPILER V7.06   TEST1_MAIN                                                            03/06/2010 17:37:25 PAGE 6   

 302                                          transmitString("\r\nFile read fail!\r\n");
 303                                  else
 304                                  {       
 305                                          transmitString("\r\nFile read success!\r\n");                                   
 306                                  }
 307                                  if (ress || br == 0) break;   // error or end file 
 308                                  transmitString("\r\nPress any key to display the data!\r\n");
 309                                  receiveByte();
 310                                  displayData(buff, 512);
 311                   }
 312                          //}
 313                          //f_puts ("hello word!", &file);
 314                          //Close all files
 315                          f_close(&file);
 316                  }
 317                  
 318              //Unregister a work area before discard it
 319              f_mount(0, 0);
 320          }*/


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1294    ----
   CONSTANT SIZE    =    764    ----
   XDATA SIZE       =   1024    2234
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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