Mas Dian beri contoh listing and rangkaiannya biar kita coba-coba...
saya suka males bikin skema.. caranya mudah kok..
coba ikutin step berikut, kalau belum berhasil nanti saya share lebih jauh ya..
1. hubungkan SD card ke SPI Port (kalau mau cepat) atau ke port/pin manapun (bit bang) selain Port A dan Port B
2. hubungkan port A dan port C (16 bit) ke rangkaian R2R DAC (16 bit DAC dengen 2 jenis resistor) coba google aja R2R DAC..
3. baca sector dari MMC/SD Card (per 512 byte) masukkan kedalam array
4. proces array per 16 bit data, invert bit ke 16 (MSB)
5. keluarkan 16 data tsb ke port A dan Port B
note: beri delay secukupnya sesuai dgn sample rate nya.. biar gak terlalu ngebut suaranya
sejauh yg saya uji cukup bersaing kualitasnya.
berikut ada penggalan program dalam BASCOM yg saya pakai, menggunakan nanoFAT (made in dewe)
'*******************************************************************************
' micro FAT32 access for read only wav player
' Dian Kurniawan v0.1b
' 2005
'*******************************************************************************
$regfile = "m16def.dat"
'$crystal = 7372800
$crystal = 14745600
$baud = 57600
'*******************************************************************************
' Overlay Memory
'*******************************************************************************
Dim Buff(512) As Byte
Dim Fileinfo(128) As Long At Buff Overlay
'*******************************************************************************
' MBR and Partition
'*******************************************************************************
Dim Mbr(512) As Byte At Buff Overlay
Dim Map_part_type_1 As Byte At Mbr(1) + 450 Overlay
Dim Map_lba_start_1 As Long At Mbr(1) + 454 Overlay
Dim Map_part_type_2 As Byte At Mbr(1) + 466 Overlay
Dim Map_lba_start_2 As Long At Mbr(1) + 470 Overlay
Dim Map_signatur_mbr As Word At Mbr(1) + &H1FE Overlay
'*******************************************************************************
' Boot Record
'*******************************************************************************
Dim Bootrec(512) As Byte At Buff Overlay
Dim Map_bytspersec As Word At Bootrec(1) + &H0B Overlay
Dim Map_secperclus As Byte At Bootrec(1) + &H0D Overlay
Dim Map_rsvdseccnt As Word At Bootrec(1) + &H0E Overlay
Dim Map_numfats As Byte At Bootrec(1) + &H10 Overlay
Dim Map_fatsz32 As Long At Bootrec(1) + &H24 Overlay
Dim Map_rootclus As Long At Bootrec(1) + &H2C Overlay
Dim Map_signature_boot As Word At Bootrec(1) + &H1FE Overlay
'*******************************************************************************
' microFAT variable
'*******************************************************************************
Dim Lba_start As Long
Dim Fat_begin_lba As Long
Dim Cluster_begin_lba As Long
Dim Bpb_secperclus As Byte
Dim Bpb_rootclus As Long
Dim Bpb_rsvdseccnt As Word
Dim Bpb_numfats As Byte
Dim Bpb_fatsz32 As Long
'*******************************************************************************
' File Handling
'*******************************************************************************
Dim Fsize As Long
Dim Start_cluster As Long
Dim End_cluster As Long
Dim Addr As Long
Dim Saddr As Long
Dim Sector_pointer As Long
'*******************************************************************************
' DAC Part
'*******************************************************************************
Dim Pcml As Byte
Dim Pcmh As Byte
Dim State As Byte
Dim Dstate As Bit
Dim Idx As Word
'*******************************************************************************
' MMC SPI Part
'*******************************************************************************
Dim Dat As Byte
Dim Resp As Byte
Const Msbl = 0
Dim I As Word
Dim J As Word
Dim Chain_loop As Word
Dim Cmd As String * 8
Dim Rx As Byte
'*******************************************************************************
' Sub Routine Declaration
'*******************************************************************************
Declare Sub Readsector(byval Secnum As Long)
Declare Sub Playsector(byval Secnum As Long)
Declare Sub Playcluster(byval Secnum As Long)
Declare Sub Initmmc()
Declare Sub Initmicrofat()
Declare Sub Getbootrecord()
Declare Sub Playmmc
Declare Sub Printsector
'*******************************************************************************
' Peripheral Config
'*******************************************************************************
'Config Spi = Soft , Din = Pinb.3 , Dout = Portb.1 , Ss = Portb.0 , Clock = Portb.2
'Spiinit
'Cs Alias Portc.0
'Mosi Alias Portc.1
'Clk Alias Portc.2
'Miso Alias Pinc.3
Cs Alias Portb.0
Mosi Alias Portb.1
Clk Alias Portb.2
Miso Alias Pinb.3
Set Cs
Set Clk
Set Mosi
Config Porta = Output
Config Portb = Output
Config Portc = Output
Config Portd = Output
Config Pinb.0 = Output
Config Pinb.1 = Output
Config Pinb.2 = Output
Config Pinb.3 = Input
Config Pinb.4 = Input
Config Pinb.5 = Input
Config Watchdog = 2048
Waitms 100
'*******************************************************************************
' Main Program
'*******************************************************************************
'Enable Urxc
'Enable Interrupts
'On Urxc Change_track
'
' Open "comd.6:57600,8,n,1" For Output As #1;
' Waitms 200
Cmd = ""
Porta = &HFF
Portb = &HFF
Portc = &HFF
Portd = &HFF
State = &HFF
Dstate = 1
Main:
Print "MMC 1.0"
Set Cs
Waitms 500
'Start Watchdog
Call Initmmc
'Stop Watchdog
Print "MMC init success"
Call Initmicrofat
Print "MMC MicroFat success"
Call Playmmc
Goto Main
End
'*******************************************************************************
' init microfat
' get partition information
'*******************************************************************************
Sub Initmicrofat()
Local Calc As Long
Call Readsector(0)
If Map_signatur_mbr = &HAA55 Then
If Map_part_type_1 = &H0B Or Map_part_type_1 = &H0C Then
Lba_start = Map_lba_start_1
Call Getbootrecord
Else
If Map_part_type_2 = &H0B Or Map_part_type_1 = &H0C Then
Lba_start = Map_lba_start_2
Call Getbootrecord
Else
Print "Error, #2" '"microfat Doesn't Recorg Partition Type "
End If
End If
Else
Print "Error, #1" '"microFat doesn't recorg Master Boot Record"
End If
Fat_begin_lba = Lba_start + Bpb_rsvdseccnt
Cluster_begin_lba = Lba_start + Bpb_rsvdseccnt
Calc = Bpb_fatsz32 * Bpb_numfats
Cluster_begin_lba = Cluster_begin_lba + Calc
End Sub
'*******************************************************************************
' Getbootrecord
'*******************************************************************************
Sub Getbootrecord()
Sector_pointer = Lba_start * 512
Call Readsector(sector_pointer)
If Map_signature_boot = &HAA55 Then
Bpb_secperclus = Map_secperclus
'Bpb_secperclus = Bpb_secperclus - 1
Bpb_rootclus = Map_rootclus
Bpb_rsvdseccnt = Map_rsvdseccnt
Bpb_numfats = Map_numfats
Bpb_fatsz32 = Map_fatsz32
Else
Print "Error, #3" '"microFat doesn't recorg Partition Boot Record"
End If
End Sub
'*******************************************************************************
' init MMC device
'*******************************************************************************
Sub Initmmc
Set Cs
Dat = &HFF
For I = 1 To 80
Reset Clk
Waitus 1
Set Clk
Waitus 1
Next I
Reset Cs
Resp = 255
Dat = &H40
Addr = 0
Shiftout Mosi , Clk , Dat , Msbl
Shiftout Mosi , Clk , Addr , Msbl
Dat = &H95
Shiftout Mosi , Clk , Dat , Msbl
Shiftout Mosi , Clk , Dat , Msbl
While Resp <> &H01
Shiftin Miso , Clk , Resp , Msbl
Wend
Set Cs
Dat = &HFF
Shiftout Mosi , Clk , Dat , Msbl
While Resp <> &H00
Reset Cs
Waitms 100
Dat = &H41
Addr = 0
Shiftout Mosi , Clk , Dat , Msbl
Shiftout Mosi , Clk , Addr , Msbx
Dat = &HFF
Shiftout Mosi , Clk , Dat , Msbl
Shiftout Mosi , Clk , Dat , Msbl
Shiftin Miso , Clk , Resp , Msbl
Set Cs
Waitms 100
Wend
Shiftout Mosi , Clk , Dat , Msbl
End Sub
'*******************************************************************************
' Readsector
'*******************************************************************************
Sub Readsector(byval Secnum As Long)
Local Sec_idx As Word
Reset Cs
Dat = &H51
Addr = Secnum
Shiftout Mosi , Clk , Dat , Msbl
Shiftout Mosi , Clk , Addr , Msbx
Dat = &HFF
Shiftout Mosi , Clk , Dat , Msbl
Shiftin Miso , Clk , Resp , Msbl
While Resp <> 0
Shiftin Miso , Clk , Resp , Msbl
Wend
While Resp <> &HFE
Shiftin Miso , Clk , Resp , Msbl
Wend
For Sec_idx = 1 To 512
Shiftin Miso , Clk , Resp , Msbl
Buff(sec_idx) = Resp
Next Sec_idx
Shiftin Miso , Clk , Resp , Msbl
Shiftin Miso , Clk , Resp , Msbl
Set Cs
Shiftout Mosi , Clk , Dat , Msbl
End Sub
'*******************************************************************************
' Play
'*******************************************************************************
Sub Playmmc
Local Sec_idx As Byte
Local Sec_count As Long
Cluster_begin_lba = Cluster_begin_lba * 512
Call Readsector(cluster_begin_lba )
Fsize = Fileinfo(
Start_cluster = Bpb_secperclus * 512
Start_cluster = Start_cluster + Cluster_begin_lba
End_cluster = Fsize
End_cluster = End_cluster + Start_cluster
Sec_count = Start_cluster
'Print Hex(cluster_begin_lba)
'Print Hex(sec_count)
'Print "end sector :" ; Hex(end_cluster)
'Print Hex(fsize )
Reset Cs
Dat = &H52
Shiftout Mosi , Clk , Dat , Msbl
Shiftout Mosi , Clk , Start_cluster , Msbx
Dat = &HFF
Shiftout Mosi , Clk , Dat , Msbl
Start Watchdog
Shiftin Miso , Clk , Resp , Msbl
While Resp <> 0
Shiftin Miso , Clk , Resp , Msbl
Wend
Stop Watchdog
Start Watchdog
While Resp <> &HFE
Shiftin Miso , Clk , Resp , Msbl
Wend
Stop Watchdog
Do
Start Watchdog
While Resp <> &HFE
Shiftin Miso , Clk , Resp , Msbl
Wend
Stop Watchdog
For Sec_idx = 0 To 255
Shiftin Miso , Clk , Resp , Msbl
Pcml = Resp
Shiftin Miso , Clk , Resp , Msbl
Pcmh = Resp
Toggle Pcmh.7
Porta = Pcmh
Portc = Pcml
Waitus 2
Next Sec_idx
Shiftin Miso , Clk , Resp , Msbl
Shiftin Miso , Clk , Resp , Msbl
Shiftin Miso , Clk , Resp , Msbl
Sec_count = Sec_count + 512
'Print "current :" ; Hex(sec_count)
Loop Until Sec_count > End_cluster
'Loop Until Sec_count > 2139808
'Until Sec_idx > End_cluster
Set Cs
Shiftout Mosi , Clk , Dat , Msbl
Shiftout Mosi , Clk , Dat , Msbl
End Sub