FAT library for SD/MMC

FAT library for SD/MMC

Overview

This library adds supports for the FAT16/32 filesystem from Microsoft to the Microchip PIC24 range. The library can be used with either SD/MMC or CF cards or and device that supports read and write sector. The library includes an example how tomake use of the library.

Implementation

The library has the following functions and procedures

function FAT_Init(AWriteSector : ^TFAT_WriteSector; AReadSector : ^TFAT_ReadSector) : word;
function FAT_WriteFile(ATextFile : ^TTextFile; var Adata_ : array[512] of char; ALength : word) : word;
function FAT_ReadFile(ATextFile : ^TTextFile) : word;
function FAT_ResetFile(ATextFile : ^TTextFile) : word;
function FAT_AssignFile(ATextFile : ^TTextFile; var AFileName : string; ACreate : boolean;) : word;
procedure FAT_SyncFile(ATextFile : ^TTextFile);
function FAT_CreateFile(ATextFile : ^TTextFile; var AFileName : string) : word;
procedure FAT_CloseFile(ATextFile : ^TTextFile);
procedure FAT_AppendFile(ATextFile : ^TTextFile);
procedure FAT_ReWriteFile(ATextFile : ^TTextFile);

Example

program FatExample;
uses libSDMMC, libFAT;
var  
  txt    : string[100];
  f1, f2 : TTextFile;
  
begin
  PORTB := 0;
  ADPCFG := 0xFFFF;
  TrisB := 0;

  Uart1_Init(9600);
  UART1_Write_Text('Start FAT demo' + #13 + #10);

  while SDMMC_Init(LatG, 9) <> 0xFF do Delay_ms(100);

  if FAT_Init(@SDMMC_WriteSector, @SDMMC_ReadSector) <> FAT_RESULT_SUCCESS then
  begin
    UART1_Write_Text('Error while detecting FAT drive ' + #13 + #10);
    while true do;
  end;

  // Assign 2 files. Is they don't exsist, create them
  txt := 'FILE0001.TXT';
  FAT_AssignFile(@f1, txt, true);
  txt := 'FILE0002.TXT';
  FAT_AssignFile(@f1, txt, true);

  // Write data to the files
  txt := 'Hello world, this is file 1' + #13 + #10;
  FAT_WriteFile(@f1, txt, 0);
  txt := 'Hello world, this is file 2' + #13 + #10;
  FAT_WriteFile(@f2, txt, 0);

  txt := 'More data for file 1' + #13 + #10;
  FAT_WriteFile(@f1, txt, 0);
  txt := 'More data for file 2' + #13 + #10;
  FAT_WriteFile(@f2, txt, 0);

  // Close the files
  FAT_CloseFile(@f1);
  FAT_CloseFile(@f2);

  PortB := 0xAAAA;

  UART1_Write_Text('Done' + #13 + #10);
end.

Attachments

File name File version File size
FAT documentation 164.57 KB
FAT library (PIC24) v1.1 438.06 KB

 
Shopping Cart
0 items
 
Riecktron Electronics © 2012