⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rr1050 ver10 pir.bas

📁 AVR PWM Audio player from FAT16 MMC version11
💻 BAS
📖 第 1 页 / 共 2 页
字号:
  End If
  Tempword = Tempword - 1
  For Q = 1 To Tempword Step 8
   Bpointer = Q
   Noalarms = Noalarms + 1
   If Noalarms > 50 Then                                    'limit to 50 alarms
    Noalarms = 50
   End If
   Tas(noalarms) = Mdat(bpointer)
   Bpointer = Bpointer + 1
   Tam(noalarms) = Mdat(bpointer)
   Bpointer = Bpointer + 1
   Tah(noalarms) = Mdat(bpointer)
   Bpointer = Bpointer + 1
   Taw(noalarms) = Mdat(bpointer)
  Next Q
 Loop Until Readsector => Eofsector
 End If
End Sub



'****************************** GET TIME TO SET ********************************

'format for file vrijeme.cfg:
'ASMHYW
'A: 0 - time is already set
'   1 - time needs to be set
'S: seconds byte
'M: minutes byte
'H: hours byte
'Y: years/date byte
'W: weekday/month byte

Sub Gettimetoset
 Filename = "VRIJEME"
 Fileextension = "CFG"
 Getfileinfo
 If Filefound = 1 Then
  Readsector = Filesector
  Mmcread
  If Mdat(1) = 1 Then                                       'if the time needs to be set
 '  Print Mdat(1)
   Mdat(1) = 0
   Ts = Mdat(2)
   Tm = Mdat(3)
   Th = Mdat(4)
   Ty = Mdat(5)
   Tw = Mdat(6)
   Settime
   Mmcwrite
  End If
 End If
End Sub


'******************************** SET TIME *************************************

'sets the time to pcf

Sub Settime
    I2cstart                                                'generate start
    I2cwbyte &HA0                                           'write address
    I2cwbyte 0                                              'select control register
    I2cwbyte 0                                              'set control register to 0
    I2cwbyte 0                                              'set hundrets of second to 0
    I2cwbyte Ts                                             'write seconds
    I2cwbyte Tm                                             'write minuts
    I2cwbyte Th                                             'write hours
    I2cwbyte Ty                                             'write year/date
    I2cwbyte Tw                                             'write week/month
    I2cstop
End Sub

'********************************** GET TIME ***********************************

'gets current time from pcf

Sub Gettime
    I2cstart
    I2cwbyte &HA0                                           'write addres of PCF8583
    I2cwbyte 2                                              'select second register
    I2cstart                                                'generate repeated start
    I2cwbyte &HA1                                           'write address for reading info
    I2crbyte Ts , Ack                                       'read seconds
    I2crbyte Tm , Ack                                       'read minuts
    I2crbyte Th , Ack                                       'read hours
    I2crbyte Ty , Ack                                       'read year and days
    I2crbyte Tw , Nack                                      'read weekday and month
    I2cstop                                                 'generate stop
End Sub

'******************************** GET END OF FILE ******************************

Sub Getendoffile
 Eofsector = Filesize \ 512
 Eofsector = Eofsector + Filesector
 Eofbyte = Filesize Mod 512
End Sub

'********************************** MMCINIT ************************************

'initializes MMC with cmd0 and cmd1 and waits for succesfull initailsation

Sub Mmcinit
 Maddr = 0
 'Print "Init started"

 Cmd0:
 Mdata = &H95
 Mcmd = &H40
 Mmccmd

 Cmd1:
 Mdata = &HFF
 Mcmd = &H41
 Mmccmd


 Select Case Mresp
   Case &H01
    Goto Cmd1
   Case &H00
    nop
   Case Else
    Goto Cmd0
 End Select
End Sub

'********************************** MMCcmd *************************************

'execute MMC command and puts R1 type resp into mresp

Sub Mmccmd
 Templong = &HFFFFFFFF
 Set Cs
 Shiftout Mosi , Clk , Templong , Msbl
 Reset Cs
 If Mcmd = 0 Then
 ' Print "Bad command"
  'Print Hex(mcmd)
 End If
 Shiftout Mosi , Clk , Mcmd , Msbl
 Shiftout Mosi , Clk , Maddr , Msbl
 Shiftout Mosi , Clk , Mdata , Msbl
 Shiftin Miso , Clk , Mresp , Msbl
 If Mresp = &HFF Then
   Waitms 2
   Shiftin Miso , Clk , Mresp , Msbl
 End If
End Sub

'****************************** Check MMC **************************************

'Checks the status of MMC and initializes it again if it isn't OK

Sub Mmccheck

Do
  Mdata = &HFF
  Mcmd = &H49
  Mmccmd
  For Q = 0 To 8
   Shiftin Miso , Clk , Tempword , Msbl
  Next Q
  Select Case Tempword
   Case &HFFFF
     Mmcinit
     Mmccid = 0
   Case 0
    Mmcinit
    Mmccid = 0
   Case Mmccid
    nop
   Case Else
    Mmcinit
    Mmccid = Tempword
    Tempword = Mmccid + 1
    Mmcrestarted = 1
    Waitms 10
  End Select
Loop Until Mmccid = Tempword

End Sub

'****************************** MMC get 1st part ********************************

' puts response from MMC to mdat from 1 to 256

Sub Mmcget1stpart
 Mmcstartread
 For Q = 1 To 256
  Reset Watchdog
  Shiftin Miso , Clk , Mdat(q) , Msbl
 Next Q

End Sub


'****************************** MMC get 1st part ********************************

' puts response from MMC to mdat from 257 to 51
Sub Mmcget2ndpart
 For Q = 257 To 512
  Reset Watchdog
  Shiftin Miso , Clk , Mdat(q) , Msbl
 Next Q
 Shiftin Miso , Clk , Mresp , Msbl
 Shiftin Miso , Clk , Mresp , Msbl
 Set Cs

End Sub


'**************************** MMC start read ***********************************
Sub Mmcstartread
  Maddr = Readsector * 512
  Mdata = &HFF
  Mcmd = &H51
  Mmccmd
  If Mresp <> 0 Then
  '  Print "MRESP:" ; Bin(mresp)
    'Mmcstartread
  End If
  Do
    Shiftin Miso , Clk , Mdat(1) , Msbl
  Loop Until Mdat(1) <> &HFF
End Sub


'************************************* MMC read ********************************

' reads 512 bytes from MMC and puts it into mdat()

Sub Mmcread
 Mmcget1stpart
 Mmcget2ndpart
End Sub

'****************************** MMC write **************************************

'writes 512 bytes from mdat to MMC

Sub Mmcwrite

  Maddr = Readsector * 512
  Mdata = &HFF
  Mcmd = &H58
  Mmccmd                                                    'cmd24
  If Mresp <> 0 Then
'   Print "mresp:" ; Bin(mresp)
   Do
   Loop
  End If

  Mresp = &HFE
  Shiftout Mosi , Clk , Mresp , Msbl

  For Q = 1 To 512
   Shiftout Mosi , Clk , Mdat(q) , Msbl
  Next Q

  Mresp = &HFF
  Shiftout Mosi , Clk , Mresp , Msbl
  Shiftout Mosi , Clk , Mresp , Msbl

  Do
   Shiftin Miso , Clk , Mresp , Msbl
  Loop Until Mresp = &B11100101

  Do
   Shiftin Miso , Clk , Mresp , Msbl
  Loop Until Mresp = &HFF

End Sub


'***************************** Get system info *********************************

Sub Getsysteminfo
 Readsector = 0
 Mmcread

 Filesystemtype = Mdat(451)
 'Tempbyte = Filesystemtype And &B00000101
 'If Tempbyte = 4 Then                                       'FAT16
  Systemfound = 1
  Brsector = Getlong(455)

  Readsector = Brsector
  Mmcread

  Sectorspercluster = Mdat(14)
  Reservedsector = Makeint(mdat(15) , Mdat(16))
  Fatno = Mdat(17)
  Maxroot = Makeint(mdat(18) , Mdat(19))
  Sectorsperfat = Makeint(mdat(23) , Mdat(24))
  Fatsector = Brsector + Reservedsector
  Dirsector = Sectorsperfat * 2
  Dirsector = Dirsector + Fatsector
  Datasector = Maxroot / 16
  Datasector = Datasector + Dirsector
 'Else
  'Systemfound = 0
 'End If

End Sub

'******************************* Get file info *********************************

' retrieves starting cluster and filesize from filename and fileextension

Sub Getfileinfo
 Dim Nameok As Bit
 Dim Extensionok As Bit
 Filefound = 0
 Readsector = Dirsector
 While Readsector < Datasector
 Mmcread
 For Q = 0 To 15
  Bpointer = Q * 32
  Bpointer = Bpointer + 12
   Mdat(bpointer) = Mdat(bpointer) And &H11000011           'ignore S,R,A
    Nameok = 0
    Extensionok = 0
    If Mdat(bpointer) = 0 Then                              ' if not volume label or LFN
     Bpointer = Bpointer + 15
     If Mdat(bpointer) > 0 Then                             'sector>0
      Bpointer = Bpointer - 26
      Tempstring = ""
      For W = 0 To 7
       If Mdat(bpointer) <> &H20 Then
        Tempstring = Tempstring + Chr(mdat(bpointer))
       End If
       Bpointer = Bpointer + 1
      Next W
      If Tempstring = Filename Then
        Nameok = 1
      End If
      Tempstring = ""
      For W = 8 To 10
        If Mdat(bpointer) <> &H20 Then
         Tempstring = Tempstring + Chr(mdat(bpointer));
        End If
        Bpointer = Bpointer + 1
      Next W
      If Tempstring = Fileextension Then
        Extensionok = 1
      End If
      If Nameok = 1 Then
       If Extensionok = 1 Then
         Bpointer = Bpointer + 16
         Tempword = 256 * Mdat(bpointer)
         Bpointer = Bpointer - 1
         Tempword = Tempword + Mdat(bpointer)
         Filesector = Clustertosector(tempword)
         Bpointer = Bpointer + 2
         Filesize = Getlong(bpointer)
         Filefound = 1
         Getendoffile
       End If
      End If
     End If
   End If
 Next Q
  Readsector = Readsector + 1
 Wend
End Sub

'***************************** printbuffer *************************************
 'prints buffer to RS232
Sub Printbuffer
For Q = 1 To 512
 'Print Chr(mdat(q) ) ;
 Tempword = Q Mod 64
 If Tempword = 0 Then
  'Print ""
 End If
Next Q

End Sub

'**************************** Get Long ******************************************
'creates long from 4 buffer bytes
Function Getlong(byval Pocetak As Word ) As Long
 Getlong = Mdat(pocetak)
 Pocetak = Pocetak + 1
 Templong = Mdat(pocetak) * &H100
 Getlong = Getlong + Templong
 Pocetak = Pocetak + 1
 Templong = Mdat(pocetak) * &H10000
 Getlong = Getlong + Templong
 Pocetak = Pocetak + 1
 Templong = Mdat(pocetak) * &H1000000
 Getlong = Getlong + Templong
End Function

'**************************** Cluster to sector ********************************
'coverts relative cluster address to sector address

Function Clustertosector(byval Cluster As Word) As Long
 Cluster = Cluster - 2
 Clustertosector = Cluster * Sectorspercluster
 Clustertosector = Clustertosector + Datasector
End Function

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -