program MMC_FAT_Test
const FAT_ERROR as string[20] = "FAT16 not found"
dim filename as string[14]
dim tmp, character, j as byte
dim size, i as longint
dim aux as string[5]
dim msg as string[100]
main:
' Set up USART for the read of the files
Usart_Init(19200)
tmp = Mmc_Fat_Init(PORTC, 2) ' Try to locate the FAT
if tmp <> 0 then
for tmp = 0 to Strlen(FAT_ERROR) - 1
Usart_Write(FAT_ERROR[tmp])
next tmp
end if
j = 1
'** Write test, 5 files **
for j = 1 to 5 ' We want 5 files on the MMC card
filename = "MYFILE0xTXT" ' File names, e.g. "MYFILE01.TXT", "MYFILE02.TXT"
filename[7] = j + 48 ' Set number 1, 2, 3, 4, or 5
Mmc_Fat_Assign(filename, 1) ' Create the file, if not found
Mmc_Fat_Rewrite ' Clear the file and prepare for writing
' Form the text to be written
aux = " "
aux[0] = j + 48
msg = "This is a test file, no." + aux
Mmc_Fat_Write(msg) ' Write data to the assigned file
next j
'** Append test **
' Now let's add more data to the same files
for j = 1 to 5
filename = "MYFILE0xTXT"
filename[7] = j + 48
Mmc_Fat_Assign(filename, 1) ' Find the file and "assign" it
Mmc_Fat_Append ' Prepare for appending
' Form the text to be written
aux = " "
aux[0] = j + 48
msg = "Append test, try " + aux
Mmc_Set_File_Date(2005,5,j,12,47,12) ' Test the date function
Mmc_Fat_Write(msg) ' Write data to the assigned file
'** Read test **
Mmc_Fat_Reset(size) ' Take the size of the file
' Send whole file to USART, char by char
for i = 1 to size
Mmc_Fat_Read(character)
Usart_Write(character)
next i
next j
end.