mikroC
mikroC - C Compiler for Microchip PIC microcontrollers
making it simple...
Library Example
The following program tests MMC FAT routines. It creates 5 different files in the root of MMC card, and fills them with some data. You can check the file dates which should be different.
char FAT_ERROR[20] = "FAT16 not found";
char file_contents[50] = "XX MMC/SD FAT16 library by Anton Rieckert"; char filename[14] = "MIKRO00xTXT"; // File names
unsigned short tmp, character, loop; long i, size;
void main() { PORTB = 0; TRISB = 0;
Usart_Init(19200); // Set up USART for reading the files if (!Mmc_Fat_Init(&PORTC, 2)) { // Try to find the FAT
tmp = 0;
while (FAT_ERROR[tmp]) Usart_Write(FAT_ERROR[tmp++]);
}
for (loop = 1; loop <= 5; loop++) { filename[7] = loop + 64; Mmc_Fat_Assign(&filename); Mmc_Fat_Rewrite(); file_contents[0] = loop / 10 + 48; file_contents[1] = loop % 10 + 48; Mmc_Fat_Write(file_contents, 41); Mmc_Fat_Append(); Mmc_Fat_Write(file_contents, 41); Delay_ms(200);
//We want 5 files on our MMC card
//Set number 1, 2, 3, 4 or 5
//If file not found, create new file
//Clear the file, start with new data
//Write data to the assigned file
//Add more data to file
//Write data to file
}
//Now if we want to add more data to those same files for (loop = 1; loop <= 5; loop++) {
filename[7] = loop + 64;
Mmc_Fat_Assign(&filename); | // Assign a file |
Mmc_Fat_Append(); |
|
Mmc_Set_File_Date(2005,6,21,10,loop,0);
Mmc_Fat_Write(" for mikroElektronika 2005\r\n", 30);
Mmc_Fat_Append(); |
|
Mmc_Fat_Write(file_contents, 41); |
|
Mmc_Fat_Reset(&size); | // To read file, returns file size |
for (i = 1; i <= size; i++) { | // Write whole file to USART |
Mmc_Fat_Read(&character); |
|
Usart_Write(character); |
|
} |
|
Delay_ms(200); |
|
} |
|
}//~! |
|
page |
|
231 | MikroElektronika: Development tools - Books - Compilers |
|