User manual

Table Of Contents
378
mikoC PRO for PIC32
MikroElektronika
Requires MMC/SD card and MMC library must be initialized for le operations. See Mmc_Fat_Init.
Example
//-------------- Tries to create a swap le, whose size will be at least
100 sectors.
//If it succeeds, it sends the No. of start sector over UART
void M_Create_Swap_File(){
size = Mmc_Fat_Get_Swap_File(100);
if (size <> 0) {
UART1_Write(0xAA);
UART1_Write(Lo(size));
UART1_Write(Hi(size));
UART1_Write(Higher(size));
UART1_Write(Highest(size));
UART1_Write(0xAA);
}
}
Notes Long File Names (LFN) are not supported.
Library Example
The following example demonstrates usage of the MMC and MMC_FAT routines.
Copy Code To Clipboard
// MMC module connections
sbit Mmc_Chip_Select at LATG9_bit; // for writing to output pin always use
latch
sbit Mmc_Chip_Select_Direction at TRISG9_bit;
// eof MMC module connections
const LINE_LEN = 43;
char err_txt[20] = “FAT16 not found”;
char le_contents[LINE_LEN] = “XX MMC/SD FAT16 library by Anton Rieckert\n”;
char lename[14] = “MIKRO00x.TXT”; // File names
unsigned short loop, loop2;
unsigned long i, size;
char Buffer[512];
// UART1 write text and new line (carriage return + line feed)
void UART1_Write_Line(char *uart_text) {
UART1_Write_Text(uart_text);
UART1_Write(13);
UART1_Write(10);
}
// Creates new le and writes some data to it
void M_Create_New_File() {
lename[7] = ‘A’;
Mmc_Fat_Set_File_Date(2011,1,12,11,9,0); // Set le date & time info
Mmc_Fat_Assign(&lename, 0xA0); // Find existing le or create a new one
Mmc_Fat_Rewrite(); // To clear le and start with new data
for(loop = 1; loop <= 99; loop++) {
UART1_Write(‘.’);
le_contents[0] = loop / 10 + 48;
le_contents[1] = loop % 10 + 48;