char filename[] = "MYFILE55TXT";
unsigned char txt[] = "This is the added data...";
unsigned short character;
unsigned long file_size,i;
void main()
{
//
// Configure the serial port
//
Usart_Init(2400);
//
// Initialise the SPI bus
//
Spi_Init_Advanced(MASTER_OSC_DIV16,DATA_SAMPLE_MIDDLE,CLK_IDLE_LOW, LOW_2_HIGH);
//
// Initialise the SD card bus
//
while(Mmc_Init(&PORTC,2));
//
// Initialise the FAT file system
//
while(Mmc_Fat_Init(&PORTC,2));
//---------------------------------------------------The simulation works well till this line -----------------------------------------------------------
Mmc_Fat_QuickFormat(“AAA”));
// Create the file (if it doesn’t exist)
//
Mmc_Fat_Assign(&filename,0x80);
//
// Clear the file, start with new data
//
Mmc_Fat_Rewrite();
//
// Write data to the file
//
Mmc_Fat_Write("This is MYFILE.TXT.",19);
//
// Add more data to the end...
//
Mmc_Fat_Append();
Mmc_Fat_Write(txt,sizeof(txt));
//
// Now read the data and send to UART
//
Mmc_Fat_Reset(&file_size);
for(i=0; i<file_size; i++)
{
Mmc_Fat_Read(&character);
Usart_Write(character);
}
for(;;); // wait here forever
}