Furtion
02.02.2008, 20:30
Hi,
ich habe ein verständnis Problem des Codes für die Ansteuerung der MMC-
Karte von roboterheld. Das Programm läuft (bezogen auf den ersten
Sector) super. (Alles erkannt, ausgelesen....) Will ich nun den 2ten Sektor
auslesen, bekomm ich nichts mehr raus.
Hier der Code:
$regfile = "m32def.dat"
$framesize = 32
$swstack = 32
$hwstack = 64
$crystal = 8000000
$baud = 19200
Declare Sub Mc_init()
Declare Sub Mc_write()
Declare Sub Mc_read()
Dim Dout As Byte
Dim Din As Byte
Dim A As Word
Dim Cmd(6) As Byte
Dim Buffer(515) As Byte
Dim Tmp As Long
Dim Sector As Long
Mcs Alias Portb.0
Mosi Alias Portb.1
Miso Alias Pinb.2
Sck Alias Portb.3
Config Pinb.0 = Output
Config Pinb.1 = Output
Config Pinb.2 = Input
Config Pinb.3 = Output
Waitms 255
Sector = 0
Buffer(1) = &HFE
Buffer(514) = &HFF
Buffer(515) = &HFF
For A = 2 To 513
Buffer(a) = 76
Next
Call Mc_init()
Call Mc_write()
Waitms 500
For A = 1 To 515
Buffer(a) = 0
Next
Call Mc_init()
Call Mc_read()
For A = 2 To 513
Print "wert: " ; Buffer(a)
Waitms 255
Next
End
Sub Mc_init()
Set Mcs
Dout = &HFF
For A = 0 To 10
Shiftout Mosi , Sck , Dout , 1 , 8 , 16
Next
Anfang:
Reset Mcs
Cmd(1) = &H40
Cmd(2) = 0
Cmd(3) = 0
Cmd(4) = 0
Cmd(5) = 0
Cmd(6) = &H95
For A = 1 To 6
Shiftout Mosi , Sck , Cmd(a) , 1 , 8 , 16
Next
For A = 1 To 8
Reset Sck
Waitus 10
Set Sck
Waitus 10
Next
Shiftin Miso , Sck , Din , 1 , 8 , 16
If Din <> 1 Then
Goto Anfang
End If
Print Din
Anfang1:
Reset Mcs
Cmd(1) = &H41
Cmd(2) = 0
Cmd(3) = 0
Cmd(4) = 0
Cmd(5) = 0
Cmd(6) = &HFF
For A = 1 To 6
Shiftout Mosi , Sck , Cmd(a) , 1 , 8 , 16
Next
For A = 1 To 8
Reset Sck
Waitus 10
Set Sck
Waitus 10
Next
Shiftin Miso , Sck , Din , 1 , 8 , 16
If Din <> 0 Then
Goto Anfang1
End If
Print Din
Set Mcs
End Sub
Sub Mc_read()
Set Mcs
Cmd(1) = &H51
Cmd(2) = 0
Cmd(3) = 0
Cmd(4) = 0
Cmd(5) = 0
Cmd(6) = &HFF
Shift Sector , Left , 9
Tmp = Sector And &HFF000000
Shift Tmp , Right , 24
Cmd(2) = Tmp
Tmp = Sector And &H00FF0000
Shift Tmp , Right , 16
Cmd(3) = Tmp
Tmp = Sector And &H0000FF00
Shift Tmp , Right , 8
Cmd(4) = Tmp
Anfang3:
Reset Mcs
For A = 1 To 6
Shiftout Mosi , Sck , Cmd(a) , 1 , 8 , 16
Next
For A = 1 To 8
Reset Sck
Waitus 10
Set Sck
Waitus 10
Next
Shiftin Miso , Sck , Din , 1 , 8 , 16
If Din <> 0 Then
Goto Anfang3
End If
Print Din
For A = 1 To 16
Reset Sck
Waitus 10
Set Sck
Waitus 10
Next
Shiftin Miso , Sck , Din , 1 , 8 , 16
If Din <> &HFE Then
Goto Ende
End If
For A = 2 To 515
Shiftin Miso , Sck , Din , 1 , 8 , 16
Buffer(a) = Din
Next
Ende:
Waitms 5
Set Mcs
End Sub
Sub Mc_write()
Set Mcs
Cmd(1) = &H58
Cmd(2) = 0
Cmd(3) = 0
Cmd(4) = 0
Cmd(5) = 0
Cmd(6) = &HFF
Shift Sector , Left , 9
Tmp = Sector And &HFF000000
Shift Tmp , Right , 24
Cmd(2) = Tmp
Tmp = Sector And &H00FF0000
Shift Tmp , Right , 16
Cmd(3) = Tmp
Tmp = Sector And &H0000FF00
Shift Tmp , Right , 8
Cmd(4) = Tmp
Anfang2:
Reset Mcs
For A = 1 To 6
Shiftout Mosi , Sck , Cmd(a) , 1 , 8 , 16
Next
For A = 1 To 8
Reset Sck
Waitus 10
Set Sck
Waitus 10
Next
Shiftin Miso , Sck , Din , 1 , 8 , 16
If Din <> 0 Then
Goto Anfang2
End If
Print Din
For A = 1 To 8
Reset Sck
Waitus 10
Set Sck
Waitus 10
Next
For A = 1 To 515
Dout = Buffer(a)
Shiftout Mosi , Sck , Dout , 1 , 8 , 16
Waitus 10
Next
Waitus 10
Shiftin Miso , Sck , Din , 1 , 8 , 16
Print Din
For A = 1 To 8
Reset Sck
Waitus 10
Set Sck
Waitus 10
Next
Set Mcs
End Sub
Weiß jemand wie man da den Sector ändern kann?
ich habe ein verständnis Problem des Codes für die Ansteuerung der MMC-
Karte von roboterheld. Das Programm läuft (bezogen auf den ersten
Sector) super. (Alles erkannt, ausgelesen....) Will ich nun den 2ten Sektor
auslesen, bekomm ich nichts mehr raus.
Hier der Code:
$regfile = "m32def.dat"
$framesize = 32
$swstack = 32
$hwstack = 64
$crystal = 8000000
$baud = 19200
Declare Sub Mc_init()
Declare Sub Mc_write()
Declare Sub Mc_read()
Dim Dout As Byte
Dim Din As Byte
Dim A As Word
Dim Cmd(6) As Byte
Dim Buffer(515) As Byte
Dim Tmp As Long
Dim Sector As Long
Mcs Alias Portb.0
Mosi Alias Portb.1
Miso Alias Pinb.2
Sck Alias Portb.3
Config Pinb.0 = Output
Config Pinb.1 = Output
Config Pinb.2 = Input
Config Pinb.3 = Output
Waitms 255
Sector = 0
Buffer(1) = &HFE
Buffer(514) = &HFF
Buffer(515) = &HFF
For A = 2 To 513
Buffer(a) = 76
Next
Call Mc_init()
Call Mc_write()
Waitms 500
For A = 1 To 515
Buffer(a) = 0
Next
Call Mc_init()
Call Mc_read()
For A = 2 To 513
Print "wert: " ; Buffer(a)
Waitms 255
Next
End
Sub Mc_init()
Set Mcs
Dout = &HFF
For A = 0 To 10
Shiftout Mosi , Sck , Dout , 1 , 8 , 16
Next
Anfang:
Reset Mcs
Cmd(1) = &H40
Cmd(2) = 0
Cmd(3) = 0
Cmd(4) = 0
Cmd(5) = 0
Cmd(6) = &H95
For A = 1 To 6
Shiftout Mosi , Sck , Cmd(a) , 1 , 8 , 16
Next
For A = 1 To 8
Reset Sck
Waitus 10
Set Sck
Waitus 10
Next
Shiftin Miso , Sck , Din , 1 , 8 , 16
If Din <> 1 Then
Goto Anfang
End If
Print Din
Anfang1:
Reset Mcs
Cmd(1) = &H41
Cmd(2) = 0
Cmd(3) = 0
Cmd(4) = 0
Cmd(5) = 0
Cmd(6) = &HFF
For A = 1 To 6
Shiftout Mosi , Sck , Cmd(a) , 1 , 8 , 16
Next
For A = 1 To 8
Reset Sck
Waitus 10
Set Sck
Waitus 10
Next
Shiftin Miso , Sck , Din , 1 , 8 , 16
If Din <> 0 Then
Goto Anfang1
End If
Print Din
Set Mcs
End Sub
Sub Mc_read()
Set Mcs
Cmd(1) = &H51
Cmd(2) = 0
Cmd(3) = 0
Cmd(4) = 0
Cmd(5) = 0
Cmd(6) = &HFF
Shift Sector , Left , 9
Tmp = Sector And &HFF000000
Shift Tmp , Right , 24
Cmd(2) = Tmp
Tmp = Sector And &H00FF0000
Shift Tmp , Right , 16
Cmd(3) = Tmp
Tmp = Sector And &H0000FF00
Shift Tmp , Right , 8
Cmd(4) = Tmp
Anfang3:
Reset Mcs
For A = 1 To 6
Shiftout Mosi , Sck , Cmd(a) , 1 , 8 , 16
Next
For A = 1 To 8
Reset Sck
Waitus 10
Set Sck
Waitus 10
Next
Shiftin Miso , Sck , Din , 1 , 8 , 16
If Din <> 0 Then
Goto Anfang3
End If
Print Din
For A = 1 To 16
Reset Sck
Waitus 10
Set Sck
Waitus 10
Next
Shiftin Miso , Sck , Din , 1 , 8 , 16
If Din <> &HFE Then
Goto Ende
End If
For A = 2 To 515
Shiftin Miso , Sck , Din , 1 , 8 , 16
Buffer(a) = Din
Next
Ende:
Waitms 5
Set Mcs
End Sub
Sub Mc_write()
Set Mcs
Cmd(1) = &H58
Cmd(2) = 0
Cmd(3) = 0
Cmd(4) = 0
Cmd(5) = 0
Cmd(6) = &HFF
Shift Sector , Left , 9
Tmp = Sector And &HFF000000
Shift Tmp , Right , 24
Cmd(2) = Tmp
Tmp = Sector And &H00FF0000
Shift Tmp , Right , 16
Cmd(3) = Tmp
Tmp = Sector And &H0000FF00
Shift Tmp , Right , 8
Cmd(4) = Tmp
Anfang2:
Reset Mcs
For A = 1 To 6
Shiftout Mosi , Sck , Cmd(a) , 1 , 8 , 16
Next
For A = 1 To 8
Reset Sck
Waitus 10
Set Sck
Waitus 10
Next
Shiftin Miso , Sck , Din , 1 , 8 , 16
If Din <> 0 Then
Goto Anfang2
End If
Print Din
For A = 1 To 8
Reset Sck
Waitus 10
Set Sck
Waitus 10
Next
For A = 1 To 515
Dout = Buffer(a)
Shiftout Mosi , Sck , Dout , 1 , 8 , 16
Waitus 10
Next
Waitus 10
Shiftin Miso , Sck , Din , 1 , 8 , 16
Print Din
For A = 1 To 8
Reset Sck
Waitus 10
Set Sck
Waitus 10
Next
Set Mcs
End Sub
Weiß jemand wie man da den Sector ändern kann?