This my sample using SD card. Code is not mine, I get it somewhere but I did some minor changes and tested it ok. Later I will refer the creator cause not remember now
Tested in Proteus and phisically on board.
$regfile = "m128def.dat" ' specify the used micro
$crystal = 16000000
$baud = 19200 ' use baud rate
$swstack = 64
$hwstack = 128
$framesize = 128
Dim B As Byte , F As Byte , S As String * 120
Print "SD/MMC CARD TEST..."
$include "Config_MMC.bas" '<--- do not change this line order...
If Gbdriveerror <> 0 Then
Print "SD/MMC ERROR " ; Gbdriveerror
End ' <---- Terminate program
Else
Print "SD/MMC CARD FOUND !!"
Wait 4
End If
$include "Config_AVR-DOS.BAS" '<--- do not change this line order...
B = Initfilesystem(1)
If B <> 0 Then
Print "Error en MMC No: " ; B
End If
'Now Create a file and write some text...
Open "MyList.txt" For Output As #9
Print #9 , "Hello All from the"
Print #9 , "SD/MMC Card."
Print #9 , "Using D.O.S type"
Print #9 , "FAT16. This file"
Print #9 , "has been created by"
Print #9 , "the Atmel uC M128"
Print #9 , "without PC "
Print #9 , "intervention."
Close #9
'Now do a very fast Dir listing of SD/MMC card contents...
S = Dir( "*.mp3")
F = 0
While Len(s) > 0
Print S ; Filedate() ; " " ; Filetime() ; " " ; Filelen()
F = F + 1
S = Dir()
Wend
Print "Total " ; F ; " Files"
Wait 4
'Now Open the previous file created and display it...
Open "MyList.txt" For Input As #9
For F = 1 To 4 ' <----- 1 to 4 because we only write 4 lines of text..
Line Input #9 , S
Print S
Next F
Close #9
Wait 4
'Now Write 254 lines of 80 characters to the card...
Print "Writing 254 text lines"
Print "80 characters long....."
Open "Chars.txt" For Output As #9
For F = 1 To 254
Print #9 , F ; " Test Line, Test Line, Test Blah Blah Blah Do Do Do Test Test 1 2 3 You There?"
Next F
Close #9
Print "Ready !!!"
End
It needs the CONFIG_AVR-DOS.bas and Config_MMC.bas files in the same folder where you save this sample code. I guess they are included in the Bascom lib Floder.
Folow this rules:
1. The card has to be formatted using FAT16 or FAT12. FAT32 does not work.
2. Use only short names (8.3) example: ThisFile.txt <--- "ThisFile" = 8 characteres, "txt" = 3 characters.
3. Currently does not support folders
4. Do not connect the SD card directly to atmel because SD works 3.3V and atmel works 5V, refer to the
schematic to use resistors.
5. Preferrable buy a SD socket or slavage one from a dead SD gadget like an broke photo camera..
6. Have fun