Mmc card wav player na atmega32


Właśnie znalazłem taki oto programik służący do odtwarzania plików wav z karty mmc na atmedze32.Moja prośba jest następująca: czy ktoś mógł by podany niżej program mi bardzo jasno wyjaśnić. Chodzi mi o to żebym wiedział co jest po co napisane i jak można to zmienić według własnych potrzeb(np: w którym miejscu zmienia się nazwę odtwarzanego pliku itp).


$regfile = "m16def.dat"
$crystal = 11059200                                         '
 
 
 
  Config Pinc.4 = Input
 Pause Alias Pinc.4
 '-------------------------------
 Config Pinc.5 = Input
 Kelid Alias Pinc.5
'--------------------------------
  Config Pinc.6 = Input
 Kelid2 Alias Pinc.6
 '-------------------------------
 Config Pinb.4 = Output
 
 
Config Pind.3 = Output
Set Portd.3
'---------------------------------
 Config Debounce = 20
 '-------------------------------------
Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Up , Compare B Pwm = Clear Down , Prescale = 1
Pwm1a = 255
Pwm1b = 255
'Constants
'warter are FAM & Behnam
 
 
Const Msbl = 0
Const Msbh = 1
Const Dly = 2
Const Bits8 = 8
Const Bits16 = 16
Const Bits32 = 32
 
'Dim
Dim Dat As Byte
Dim Resp As Byte
Dim I As Word
Dim Addr As Long
Dim Adres As Long
Dim Tanzim As Byte
Dim Ali As Byte
Dim Test As Long
Dim Copy As Long
Dim Shomare As Long
Dim Hassan As Byte
'Aliases
Cs Alias Portb.0
Mosi Alias Portb.1
Clk Alias Portb.3
Miso Alias Pinb.2
 
'Declarations
Declare Sub Minit
Declare Sub Mread(byval Addr As Long )
'Configs
Config Portb.2 = Output
Config Portb.0 = Output
Config Portb.3 = Output
Config Pinb.1 = Input
 
 
Waitms 300
Config Spi = Soft , Din = Pinb.2 , Dout = Portb.1 , Ss = Portb.0 , Clock = Portb.3
 
 Enable Interrupts
 Enable Spi
 
 Spiinit
 
'******** MAIN PROGRAM *************
 
 Reset Portd.3
Main:
'Initialize the MMCC
Minit
Adres = 1048576
Ali = 0
 Reset Portd.3
 
Inja:
Toggle Portb.4
Mread Adres
 
Debounce Pause , 1 , Stop_play , Sub
Debounce Kelid2 , 1 , Jolo2 , Sub
Debounce Kelid , 1 , Jolo , Sub
 
Adres = Adres + 512
 
'baraye in ke ta dastgah roshan shod peygham 1 ra ped konad
'-----------------------------------------------------------------
If Ali = 0 Then
Adres = Adres + 5120000
Test = 512 * 7800
 'Test = 512 * 8000
Adres = Adres - Test
Ali = 1
 
Test = Adres
End If
'-------------------------------------------------------------------
Goto Inja
 
Xloop:
Set Cs
Shiftout Mosi , Clk , Dat , Msbl
Endloop:
Goto Endloop
End                                                         'end program
'***************************** END OF PROGRAM **********************************
'======= SUB ROUTINES AND FUNCTIONS =======
'warter are FAM & Behnam
'*** INITIALIZATION OF MMC ***
Sub Minit
Set Cs
 
Dat = &HFF
For I = 1 To 10
  Shiftout Mosi , Clk , Dat , Msbl
Next I
 
Resp = 255
Reset Cs
 
Cmd0:
Dat = &H40
Shiftout Mosi , Clk , Dat , Msbl
 
Addr = &H00000000
Shiftout Mosi , Clk , Addr , Msbl
 
Dat = &H95
Shiftout Mosi , Clk , Dat , Msbl
 
While Resp <> &H01
Shiftin Miso , Clk , Resp , Msbl
Wend
 
Set Cs
Waitms 50
Reset Cs
Dat = &HFF
 
Cmd1:
While Resp <> &H00
'warter are FAM & Behnam
Set Cs
Shiftout Mosi , Clk , Dat , Msbl
Shiftin Miso , Clk , Resp , Msbl
Reset Cs
Dat = &H41
Shiftout Mosi , Clk , Dat , Msbl
Addr = 0
Shiftout Mosi , Clk , Addr , Msbl
Dat = &HFF
Shiftout Mosi , Clk , Dat , Msbl
Shiftout Mosi , Clk , Dat , Msbl
Shiftin Miso , Clk , Resp , Msbl
Wend
 
Dat = &HFF
Set Cs
End Sub
 
 
 
 
'warter are FAM & Behnam
'**** READ routine assumes ADDR uses Status subroutine *****
Sub Mread(byval Addr As Long)
Set Cs
Dat = &HFF
Shiftout Mosi , Clk , Dat , Msbl
Shiftin Miso , Clk , Resp , Msbl
Reset Cs
 
Dat = &H51
Shiftout Mosi , Clk , Dat , Msbl
Shiftout Mosi , Clk , Addr , Msbl
 
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 I = 1 To 512
    Shiftin Miso , Clk , Resp , Msbl
 
      Pwm1a = Resp
      Pwm1b = Resp
      Waitus 29
      'Waitus 3                                              'ÓŃÚĘ
      Next I
 
Shiftin Miso , Clk , Resp , Msbl
Shiftin Miso , Clk , Resp , Msbl
Set Cs
'warter are FAM & Behnam
End Sub
 
 
 
 
 
 
 
 
Jolo:
Adres = Adres + 153600
 
For Shomare = 1 To 500
If Kelid = 0 Then Return
Waitms 1
Next
 
Adres = Adres + 972800
 
 
Return
 
 
 
 
 
Jolo2:
Adres = Adres - 153600
 
For Shomare = 1 To 500
If Kelid2 = 0 Then Return
Waitms 1
Next
 
 
 Adres = Adres - 972800
 
If Adres < Test Then Adres = Test
Return
 
 
 
Stop_play:
Set Portd.3
Pwm1a = 255
Pwm1b = 255
Copy = Adres
Do
Debounce Pause , 1 , Play
Loop
Play:
Reset Portd.3
Adres = Copy
Return

Taki program napewno przyda się nie tylko mi ale i innym użytkownikom forum.
Oto link do strony ze schematem http://www.avrprojects.info/avr-projects/mmc-card-based-wav-player/




Portret użytkownika mirley

Re: Odtwarzacz

Wygląda na to że plik odczytywany jest po adresie z karty.... nie ma tutaj systemu plików, żeby mówić o nazwie..... Z kartami MC ani SD nie miałem jeszcze do czynienia więc nie jestem znawcą. To tylko pierwsze spostrzeżenie

-

UWAGA! Możliwy jest zakup zaprogramowanych uC i zestawów elementów itp. do niektórych projektów. O dostępność proszę pytać via email. Konkretne oferty pojawiają się w cenniku.

Portret użytkownika zan

Drógi program

Znalazłem jeszcze taki program, może coś takiego da się rozgryźć ; )

'******************************************************************************* 
'* WAV Player Tel  (M8L) By Behnam @ 27.Day.87 [2008]                          * 
'*                                                                             * 
'* Author:        FAM & Behnam Zakizadeh                                       * 
'* Location:      IRAN , Qazvin City                                           * 
'* Web:           <a href="http://electronic-projects.blogfa.com">http://electronic-projects.blogfa.com</a>                        * 
'* Mail:          <script type="text/javascript">eval(unescape('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%7a%61%6b%69%7a%61%64%65%68%5f%62%65%68%6e%61%6d%40%79%61%68%6f%6f%2e%63%6f%6d%22%3e%7a%61%6b%69%7a%61%64%65%68%5f%62%65%68%6e%61%6d%40%79%61%68%6f%6f%2e%63%6f%6d%3c%2f%61%3e%27%29%3b'))</script>                                   * 
'******************************************************************************* 
$regfile = "M8def.dat" 
$crystal = 12000000 
Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Down , Prescale = 1 
'Constants 
'warter are FAM & Behnam 
Const Msbl = 0 
Const Msbh = 1 
Const Dly = 2 
Const Bits8 = 8 
Const Bits16 = 16 
Const Bits32 = 32 
'Dim 
Dim Dat As Byte 
Dim Resp As Byte 
Dim I As Word 
Dim Addr As Long 
Dim Adres As Long 
Dim Tanzim As Byte 
'Aliases 
Cs Alias Portd.1 
Mosi Alias Portd.2 
Clk Alias Portd.3 
Miso Alias Pind.0 
'Declarations 
Declare Sub Minit 
Declare Sub Mread(byval Addr As Long ) 
'Configs 
Config Portd.0 = Output 
Config Portd.4 = Output 
Config Portd.3 = Output 
Config Pind.2 = Input 
Waitms 300 
Config Spi = Soft , Din = Pind.0 , Dout = Portd.2 , Ss = Portd.1 , Clock = Portd.3 
Spiinit 
'******** MAIN PROGRAM ************* 
Main: 
'Initialize the MMCC 
Minit 
Adres = 1048576 
Inja: 
Mread Adres 
Adres = Adres + 512 
Goto Inja 
Xloop: 
Set Cs 
Shiftout Mosi , Clk , Dat , Msbl 
Endloop: 
Goto Endloop 
End                                                         'end program 
'***************************** END OF PROGRAM ********************************** 
'======= SUB ROUTINES AND FUNCTIONS ======= 
'warter are FAM & Behnam 
'*** INITIALIZATION OF MMC *** 
Sub Minit 
Set Cs 
Dat = &HFF 
For I = 1 To 10 
  Shiftout Mosi , Clk , Dat , Msbl 
Next I 
Resp = 255 
Reset Cs 
Cmd0: 
Dat = &H40 
Shiftout Mosi , Clk , Dat , Msbl 
Addr = &H00000000 
Shiftout Mosi , Clk , Addr , Msbl 
Dat = &H95 
Shiftout Mosi , Clk , Dat , Msbl 
While Resp <> &H01 
Shiftin Miso , Clk , Resp , Msbl 
Wend 
Set Cs 
Waitms 50 
Reset Cs 
Dat = &HFF 
Cmd1: 
While Resp <> &H00 
'warter are FAM & Behnam 
Set Cs 
Shiftout Mosi , Clk , Dat , Msbl 
Shiftin Miso , Clk , Resp , Msbl 
Reset Cs 
Dat = &H41 
Shiftout Mosi , Clk , Dat , Msbl 
Addr = 0 
Shiftout Mosi , Clk , Addr , Msbl 
Dat = &HFF 
Shiftout Mosi , Clk , Dat , Msbl 
Shiftout Mosi , Clk , Dat , Msbl 
Shiftin Miso , Clk , Resp , Msbl 
Wend 
Dat = &HFF 
Set Cs 
End Sub 
'warter are FAM & Behnam 
'**** READ routine assumes ADDR uses Status subroutine ***** 
Sub Mread(byval Addr As Long) 
Set Cs 
Dat = &HFF 
Shiftout Mosi , Clk , Dat , Msbl 
Shiftin Miso , Clk , Resp , Msbl 
Reset Cs 
Dat = &H51 
Shiftout Mosi , Clk , Dat , Msbl 
Shiftout Mosi , Clk , Addr , Msbl 
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 I = 1 To 512 
    Shiftin Miso , Clk , Resp , Msbl 
      Pwm1a = Resp 
      Waitus 30                                             'ÓŃÚĘ 
      Next I 
Shiftin Miso , Clk , Resp , Msbl 
Shiftin Miso , Clk , Resp , Msbl 
Set Cs 
'warter are FAM & Behnam 

Program pochodzi z tej strony http://en.pudn.com/downloads154/sourcecode/others/detail684806_en.html

Portret użytkownika zan

A tak przy okazji...

Kupiłem nową atmege32 montuję do programatora i wszystko się ładnie i sprawnie programuje.Problem w tym że po zaprogramowaniu at wogule nic nie reaguje!Myślałem że napisałem zły program i w ramach testu napisałem i wgrałem coś takiego:

$regfile = "m32def.dat"
$crystal = 8000000
 
Do
Toggle Portb.0
Wait 2
Loop
End

Gdzie portb.0 to dioda led, która miała migać i dalej nic!
Może pomieszałem coś w fuse bitach:

Aaa i jeszcze muszę dodać że przez kond. i opornik włączony jest rezonator wewnętrzny.

Portret użytkownika mirley

Re: M32

Program nie ma konfiguracji portów. Ile razy bym nie pisał to i tak zawsze ktoś nie wie. Wszystkie porty nawet nieużywane powinny mieć konfiguracje typu i wartość początkową. Popatrz do dowolnego mojego programu, wszystkie to mają

-

UWAGA! Możliwy jest zakup zaprogramowanych uC i zestawów elementów itp. do niektórych projektów. O dostępność proszę pytać via email. Konkretne oferty pojawiają się w cenniku.

Portret użytkownika zan

Rzeczywiście

Rzeczywiście, mirley miałeś racje z tymi ustawieniami pinów.Już wszystko chodzi.Tylko co zdobić z tą nieszczęsną mmc?

Portret użytkownika zan

nowy program

Znalazłem jeszcze jeden program który wydaje się łatwiejszy. Proszę kogoś o podpowiedź jak skonfigurować na własne potrzeby?

{
********************************************************************************
*  Name    : WavPlayer.BAS                                                     *
*  Author  : S Wright                                                          *
*  Notice  : Copyright (c) 2006 S Wright                                       *
*          : All Rights Reserved                                               *
*  Date    : 25/10/2006                                                        *
*  Version : 1.0                                                               *
*  Notes   :                                                                   *
*          :                                                                   *
********************************************************************************
}
Device = 18F452
Clock = 32
Config OSC = HSPLL
 
#option SD_SPI = MSSP
#option SD_SUPPORT_SUB_DIRECTORIES = True
#option LCD_DATA = PORTB.4
#option LCD_RS = PORTB.2
#option LCD_EN = PORTB.3
#option LCD_INIT_DELAY = 300
Include "SDFileSystem.bas"
Include "LCD.bas"
 
Const BufferSize = 500                  // buffer to avoid glitches
Const TimerReload = 65036               // alter for different sample rates
 
Dim Timer As TMR1L.AsWord               // alias to Timer1
Dim TimerOn As T1CON.Booleans(0)        // start and stop
Dim TimerEnabled As PIE1.Booleans(0)    // enable interrupts
Dim TimerInterrupt As PIR1.Booleans(0)  // interrupt flag
 
Dim File As String(13)
Dim WritePointer, ReadPointer As Word   // read/write pointers in
Dim Buffer(BufferSize) As Byte          // circular buffer
Dim DataSize As LongWord                // size of WAV data in file
Dim Progress As LongWord                // increment progress bar when zero
Dim ProgressIncrement As LongWord       // progress bar step
 
{
********************************************************************************
* Name    : OnTimer (Interupt)                                                 *
* Purpose : Sends bytes to R-2R DAC on PORT D to play file                     *
********************************************************************************
}   
Interrupt OnTimer()                     // ISR
   Timer = TimerReload
   Save(0)                              // context save
   If ReadPointer = WritePointer Then   // buffer empty
      PORTE.0 = 1                       // set buffer empty indicator
   Else
      Inc(ReadPointer)                  // increment read pointer
      If ReadPointer = BufferSize Then  // if end of buffer then...
         ReadPointer = 0                // move back to beginning of buffer 
      EndIf
      PORTD = Buffer(ReadPointer)       // move byte to PORTD (R-2R ladder DAC)
   EndIf
   TimerInterrupt = False               // clear interrupt flag
   Restore
End Interrupt
{
********************************************************************************
* Name    : ReadFmt                                                            *
* Purpose : Reads header of WAV file and checks compatibility                  *
********************************************************************************
}   
Function ReadFmt() As Boolean           // read fmt block of WAV file
Dim Index As Byte
   ReadFmt = True
   Index = 0
   Repeat                               // skip over RIFF header
      SD.ReadLongWord
      Inc(Index)
   Until Index = 3
   If SD.ReadChar <> "f" Then           // check in fmt block
      ReadFmt = False
   EndIf
   If SD.ReadChar <> "m" Then
      ReadFmt = False
   EndIf
   If SD.ReadChar <> "t" Then
      ReadFmt = False
   EndIf
   If SD.ReadChar <> " " Then
      ReadFmt = False
   EndIf
   SD.ReadLongWord                      // skip over fmt size
   If SD.ReadWord <> 1 Then             // check PCM (un-compressed) file
      ReadFmt = False
   EndIf
   If SD.ReadWord <> 1 Then             // check 1 channel (mono) file
      ReadFmt = False
   EndIf
   If SD.ReadLongWord <> 16000 Then     // check sample rate (16kHz)
      ReadFmt = False
   EndIf
   Index = 0
   Repeat                               // skip to data size
      SD.ReadByte
      Inc(Index)
   Until Index = 12
   DataSize = SD.ReadLongWord
   SD.ReadLongWord                      // skip to data section
   ProgressIncrement = DataSize / 16
End Function
{
********************************************************************************
* Name    : ProgressBar                                                        *
* Purpose : Updates progress bar during playback                               *
********************************************************************************
}   
Sub ProgressBar()
   Dec(Progress)
   If Progress = 0 Then
      Progress = ProgressIncrement
      LCD.Write("=")
   EndIf
End Sub
{
********************************************************************************
* Name    : SoftStart                                                          *
* Purpose : Ramps DAC output to new value to avoid clicks                      *
********************************************************************************
}   
Sub SoftStart(pNewValue As Byte)
Dim Value As Byte
   Value = PORTD
   Repeat
      If Value < pNewValue Then
         Inc(Value)
      ElseIf Value > pNewValue Then
         Dec(Value)
      EndIf
      PORTD = Value
      DelayUS(20)
   Until Value = pNewValue
End Sub
{
********************************************************************************
* Name    : PlayFile                                                           *
* Purpose : Plays file                                                         *
********************************************************************************
}   
Sub PlayFile(pFile As String)
Dim TempWritePointer As Word
   LCD.Cls
   LCD.Writeat(1, 1, "{ ", pFile, " }")
   LCD.WriteAt(2, 1, "  OPENING FILE  ")
   SD.OpenFile(pFile)                      
   Timer = TimerReload                  // set timer one
   ReadPointer = 0                      // initialise pointers
   WritePointer = 0                     
   If Not(ReadFmt()) Then               // incompatible file format
      LCD.WriteAt(2, 1, "WRONG FILE TYPE!")
   Else
      LCD.WriteAt(2, 1, "----------------")      
      Progress = ProgressIncrement
      LCD.MoveCursor(2,1)
      Repeat                            // fill buffer initially
         Inc(WritePointer)
         Buffer(WritePointer) = SD.ReadByte
         Dec(DataSize)
         ProgressBar()
      Until (WritePointer = BufferSize - 1) Or SD.EOF   
      SoftStart(Buffer(1))              // ramp up to first byte to play
      TimerOn = True                    // start timer - play starts
      Repeat
         TempWritePointer = WritePointer        // use a temp pointer in order
         Inc(TempWritePointer)                  // to prevent interrupt 
         If TempWritePointer = BufferSize Then  // detecting a buffer underun
            TempWritePointer = 0                // when buffer is full
         EndIf
         While TempWritePointer = ReadPointer
            PORTE.1 = 1
         Wend 
         PORTE.1 = 0
         WritePointer = TempWritePointer
         Buffer(WritePointer) = SD.ReadByte     // write next byte to buffer
         Dec(DataSize)
         ProgressBar()
      Until SD.EOF Or (DataSize = 0)  
   EndIf 
   SD.CloseFile
   Repeat                               // wait until buffer is empty
   Until ReadPointer = WritePointer
   TimerOn = False                      // stop timer
   PORTE = 0
End Sub
 
 
// Main program...
TRISD = 0
TRISE = 0
PORTE = 0
SoftStart(127)
TimerOn = False                         // stop timer initially
Enable(OnTimer)                         // assign the interrupt handler
TimerEnabled = True                     // enable timer interrupts
 
LCD.Cls
LCD.WriteAt(1, 1, "PLEASE INSERT SD")
Repeat
Until SD.Init(spiOscDiv4)
 
Repeat
   File = SD.Dir(dirNext, sdFile)       // search for next file on SD card
   If File <> Null Then                 // file found
      PlayFile(File)
   EndIf
Until File = Null
 
LCD.Cls
LCD.WriteAt(1, 5, "FINISHED")

Link do strony z programem: http://www.sfcompiler.co.uk/wiki/pmwiki.php?n=SwordfishUser.SDMMCWavPlayer