سلام دوستان میدونم مطلب در مورد mmc توی سایت زیاده ولی به سوالم جواب بدید ممنون میشم من برنامه زیر رو برای atmega32 نوشتم که با ان یک ویو پلییر درست کنم ولی ای سی هنگ میکنه و زمانی هم که داخل پروتیوس شبیه سازی میکنم ارور میده !!! نکته جالبش اینجاست که زمانی که دستور Enable Interrupts رو حذف میکنم دیگه ارور نمیده و در عمل هم ای سی هنگ نمیکنه ولی دیگه pwmکارنمیکنه پس صدایی هم ندارم > لطفا کمک کنید> :cry: 
regfile = "m32def.dat"$
$crystal = 12000000
$hwstack = 200
$swstack = 60
$framesize = 40
Config Timer1 = Pwm , Pwm = 8 , Prescale = 1 , Compare A Pwm = Clear Down
Config Timer2 = Timer , Prescale = 8
'config wathdog=2048
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Porta.0 , Db5 = Porta.1 , Db6 = Porta.2 , Db7 = Porta.3 , E = Porta.4 , Rs = Porta.5
Config Pinc.1 = Input , Pinc.2 = Input , Pinc.3 = Input
'............................................ .............
Enable Interrupts
Enable Timer2 : On Timer2 T2_isr
'............................................ .................
Dim Btemp1 As Byte , Berrorcode As Byte
Dim Play_enable As Bit , Mmc_data(512)as Byte , File_name As String * 20 , J As Word
Dim Read_enable As Bit , Read_end As Bit , X As Byte , Play_mode As Byte , Menu As Byte
Dim First_read As Bit , Start_address As Long
'............................................ .................
Const Timer2_value = 21
'............................................ ..................
$include "config_mmc.bas"
$include "config_avr-dos.bas"
'............................................ .....................
Next_key Alias Pinc.1 : Fw_key Alias Pinc.3 : Menu_key Alias Pinc.2
Audio_enable Alias Pinc.0
'............................................ .....................
Enable Interrupts
Stop Timer2 : Timer2 = Timer2_value : Start Timer2
'............................................ .................
Set Portc.1 : Set Portc.2 : Set Portc.3
'............................................ .................
Cls : Cursor Offnoblink
Gosub Demo
Locate 1 , 1 : Lcd "reading memory"
Locate 2 , 1 : Lcd "wait.... "
Waitms 500
'start wachdog
'............................................ .......................
Berrorcode = Drivereset()
If Berrorcode > 0 Then
Do
Locate 1 , 1 : Lcd "nomemory card"
Locate 2 , 1 : Lcd "inserte"
Loop
End If
Berrorcode = Drivereset()
If Berrorcode > 0 Then
Do
Locate 1 , 1 : Lcd "nomemory card"
Locate 2 , 1 : Lcd "inserte"
Loop
End If
Btemp1 = Initfilesystem(1)
'............................................ .........................
If Gbdriveerror <> 0 Then
Do
Locate 1 , 1 : Lcd "fatal error"
Locate 2 , 1 : Lcd "check your card"
Loop
End If
'............................................ ........................
If Btemp1 > 0 Then
Do
Locate 1 , 1 : Lcd "file system"
Locate 2 , 1 : Lcd "error!!!!! "
Loop
End If
Cls
'............................................ .........................
Gosub Load_settings
'............................................ ....................
File_name = Dir( "file_name"
If File_name = "1.wav"then
File_name = Dir( "*.wav"
Gosub Store_settings
'............................................ ...........................
Config Audio_enable = Output
Open File_name For Binary As#10
Gosub Screen
Play_enable = 1 : Config Audio_enable = Input
'............................................ ......................
Do
Gosub Read_keys
Gosub Read_file
Loop
'............................................ ........................
Screen:
Cls
Select Case Menu
Case 0:
Locate 1 , 1 : Lcd "file name:"
Locate 2 , 1 : Lcd File_name ; " "
Case 1:
Locate 1 , 1 : Lcd "playing mode?"
Locate 1 , 1
Select Case Play_mode
Case 0:
Lcd "normal"
Case 1:
Lcd "repeat all"
Case 2:
Lcd "repeat one track"
Case 3:
Lcd "one track only"
End Select
End Select
Return
'............................................ .................................
Read_keys:
Debounce Next_key , 0 , Push_next_key , Sub
Debounce Menu_key , 0 , Push_menu_key , Sub
Return
'............................................ ............
Read_file:
If Eof(#10) = 0 Then
If Read_enable = 0 Then
Read_enable = 1
If First_read = 0 Then
First_read = 1 : Start_address = 512 : Get #10 , Mmc_data(1) , Start_address , 512
Else
Get #10 , Mmc_data(1) , Start_address , 512
If Fw_key = 1 Then
Start_address = Start_address + 512
Else
Start_address = Start_address + 1024
End If
End If
End If
Else
Select Case Play_mode
Play_mode = 0 : Config Audio_enable = Output : Close #10 : Waitms 500
Case 0:
Gosub Next_track
Case 1:
Gosub Push_next_key
Case 2:
Gosub Repeat_track
Case 3:
Gosub End_track
End Select
End If
Return
'............................................ ...................................
Push_next_key:
Select Case Menu
Case 0:
First_read = 0
Config Audio_enable = Output : Play_enable = 0 : Close #10
File_name = Dir() : If File_name = "" Then File_name = Dir( "*.wav"
Gosub Store_settings
Open File_name For Binary As #10
Gosub Screen
Play_enable = 1 : Config Audio_enable = Input
Case 1:
Incr Play_mode : If Play_mode > 3 Then Play_mode = 0
Gosub Screen
End Select
Return
'............................................ ...................................
Next_track:
First_read = 0
Config Audio_enable = Output : Play_enable = 0 : Close #10
File_name = Dir() : If File_name = "" Then Goto Here
Gosub Store_settings
Open File_name For Binary As #10
Gosub Screen
Play_enable = 1 : Config Audio_enable = Input
Here:
Return
'............................................ ....................................
Repeat_track:
First_read = 0
Config Audio_enable = Output : Play_enable = 0 : Close #10
Open File_name For Binary As #10
Gosub Screen
Play_enable = 1 : Config Audio_enable = Input
Return
'........................................
End_track:
Config Audio_enable = Output : Play_enable = 0 : Close #10
Return
'............................................ ....................
Push_menu_key:
Incr Menu
If Menu > 1 Then Menu = 0
Gosub Screen
Gosub Store_settings
Return
'.........................................
T2_isr:
Stop Timer2 : Timer2 = Timer2_value : Start Timer2
'......................................... ..
Incr J
If Play_enable = 1 Then
Pwm1a = Mmc_data(j)
Else
'pwm1a=0
End If
'...................
If J = 600 Then Read_enable = 0
If J = 1536 Then J = 0
Return
'.....................................
Demo:
Cls
Locate 1 , 17 : Lcd "wav player 1.2"
Locate 2 , 17 : Lcd " 1389 "
For X = 1 To 16
Shiftlcd Left , 1 : Waitms 30
Next
Wait 3
For X = 1 To 16
Shiftlcd Left , 1 : Waitms 30
Next
Cls
Return
'............................................ .............
Store_settings:
Writeeeprom Play_mode , 0
Writeeeprom File_name , 100
Return
'........................................
Load_settings:
Readeeprom Play_mode , 0
If Play_mode > 3 Then Play_mode = 0
Readeeprom File_name , 100
End If
'................................
Gosub Store_settings
Return
'....................
End 'end program

regfile = "m32def.dat"$
$crystal = 12000000
$hwstack = 200
$swstack = 60
$framesize = 40
Config Timer1 = Pwm , Pwm = 8 , Prescale = 1 , Compare A Pwm = Clear Down
Config Timer2 = Timer , Prescale = 8
'config wathdog=2048
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Porta.0 , Db5 = Porta.1 , Db6 = Porta.2 , Db7 = Porta.3 , E = Porta.4 , Rs = Porta.5
Config Pinc.1 = Input , Pinc.2 = Input , Pinc.3 = Input
'............................................ .............
Enable Interrupts
Enable Timer2 : On Timer2 T2_isr
'............................................ .................
Dim Btemp1 As Byte , Berrorcode As Byte
Dim Play_enable As Bit , Mmc_data(512)as Byte , File_name As String * 20 , J As Word
Dim Read_enable As Bit , Read_end As Bit , X As Byte , Play_mode As Byte , Menu As Byte
Dim First_read As Bit , Start_address As Long
'............................................ .................
Const Timer2_value = 21
'............................................ ..................
$include "config_mmc.bas"
$include "config_avr-dos.bas"
'............................................ .....................
Next_key Alias Pinc.1 : Fw_key Alias Pinc.3 : Menu_key Alias Pinc.2
Audio_enable Alias Pinc.0
'............................................ .....................
Enable Interrupts
Stop Timer2 : Timer2 = Timer2_value : Start Timer2
'............................................ .................
Set Portc.1 : Set Portc.2 : Set Portc.3
'............................................ .................
Cls : Cursor Offnoblink
Gosub Demo
Locate 1 , 1 : Lcd "reading memory"
Locate 2 , 1 : Lcd "wait.... "
Waitms 500
'start wachdog
'............................................ .......................
Berrorcode = Drivereset()
If Berrorcode > 0 Then
Do
Locate 1 , 1 : Lcd "nomemory card"
Locate 2 , 1 : Lcd "inserte"
Loop
End If
Berrorcode = Drivereset()
If Berrorcode > 0 Then
Do
Locate 1 , 1 : Lcd "nomemory card"
Locate 2 , 1 : Lcd "inserte"
Loop
End If
Btemp1 = Initfilesystem(1)
'............................................ .........................
If Gbdriveerror <> 0 Then
Do
Locate 1 , 1 : Lcd "fatal error"
Locate 2 , 1 : Lcd "check your card"
Loop
End If
'............................................ ........................
If Btemp1 > 0 Then
Do
Locate 1 , 1 : Lcd "file system"
Locate 2 , 1 : Lcd "error!!!!! "
Loop
End If
Cls
'............................................ .........................
Gosub Load_settings
'............................................ ....................
File_name = Dir( "file_name"

If File_name = "1.wav"then
File_name = Dir( "*.wav"

Gosub Store_settings
'............................................ ...........................
Config Audio_enable = Output
Open File_name For Binary As#10
Gosub Screen
Play_enable = 1 : Config Audio_enable = Input
'............................................ ......................
Do
Gosub Read_keys
Gosub Read_file
Loop
'............................................ ........................
Screen:
Cls
Select Case Menu
Case 0:
Locate 1 , 1 : Lcd "file name:"
Locate 2 , 1 : Lcd File_name ; " "
Case 1:
Locate 1 , 1 : Lcd "playing mode?"
Locate 1 , 1
Select Case Play_mode
Case 0:
Lcd "normal"
Case 1:
Lcd "repeat all"
Case 2:
Lcd "repeat one track"
Case 3:
Lcd "one track only"
End Select
End Select
Return
'............................................ .................................
Read_keys:
Debounce Next_key , 0 , Push_next_key , Sub
Debounce Menu_key , 0 , Push_menu_key , Sub
Return
'............................................ ............
Read_file:
If Eof(#10) = 0 Then
If Read_enable = 0 Then
Read_enable = 1
If First_read = 0 Then
First_read = 1 : Start_address = 512 : Get #10 , Mmc_data(1) , Start_address , 512
Else
Get #10 , Mmc_data(1) , Start_address , 512
If Fw_key = 1 Then
Start_address = Start_address + 512
Else
Start_address = Start_address + 1024
End If
End If
End If
Else
Select Case Play_mode
Play_mode = 0 : Config Audio_enable = Output : Close #10 : Waitms 500
Case 0:
Gosub Next_track
Case 1:
Gosub Push_next_key
Case 2:
Gosub Repeat_track
Case 3:
Gosub End_track
End Select
End If
Return
'............................................ ...................................
Push_next_key:
Select Case Menu
Case 0:
First_read = 0
Config Audio_enable = Output : Play_enable = 0 : Close #10
File_name = Dir() : If File_name = "" Then File_name = Dir( "*.wav"

Gosub Store_settings
Open File_name For Binary As #10
Gosub Screen
Play_enable = 1 : Config Audio_enable = Input
Case 1:
Incr Play_mode : If Play_mode > 3 Then Play_mode = 0
Gosub Screen
End Select
Return
'............................................ ...................................
Next_track:
First_read = 0
Config Audio_enable = Output : Play_enable = 0 : Close #10
File_name = Dir() : If File_name = "" Then Goto Here
Gosub Store_settings
Open File_name For Binary As #10
Gosub Screen
Play_enable = 1 : Config Audio_enable = Input
Here:
Return
'............................................ ....................................
Repeat_track:
First_read = 0
Config Audio_enable = Output : Play_enable = 0 : Close #10
Open File_name For Binary As #10
Gosub Screen
Play_enable = 1 : Config Audio_enable = Input
Return
'........................................
End_track:
Config Audio_enable = Output : Play_enable = 0 : Close #10
Return
'............................................ ....................
Push_menu_key:
Incr Menu
If Menu > 1 Then Menu = 0
Gosub Screen
Gosub Store_settings
Return
'.........................................
T2_isr:
Stop Timer2 : Timer2 = Timer2_value : Start Timer2
'......................................... ..
Incr J
If Play_enable = 1 Then
Pwm1a = Mmc_data(j)
Else
'pwm1a=0
End If
'...................
If J = 600 Then Read_enable = 0
If J = 1536 Then J = 0
Return
'.....................................
Demo:
Cls
Locate 1 , 17 : Lcd "wav player 1.2"
Locate 2 , 17 : Lcd " 1389 "
For X = 1 To 16
Shiftlcd Left , 1 : Waitms 30
Next
Wait 3
For X = 1 To 16
Shiftlcd Left , 1 : Waitms 30
Next
Cls
Return
'............................................ .............
Store_settings:
Writeeeprom Play_mode , 0
Writeeeprom File_name , 100
Return
'........................................
Load_settings:
Readeeprom Play_mode , 0
If Play_mode > 3 Then Play_mode = 0
Readeeprom File_name , 100
End If
'................................
Gosub Store_settings
Return
'....................
End 'end program
دیدگاه