Proton illegal Opcode / Overwriting hatası

Başlatan MR.CAPSLOCK, 13 Nisan 2017, 23:27:44

MR.CAPSLOCK

Arkadaşlar merhaba, her yerde illegal opcode ile PBP çözümleri verilmiş. INC dosyasındaki sigorta ayarlarını comment yapma anlatılmış. ProtonIDE dosyası içerisinde örneklere benzer config ayarları PPI uzantılı dosyanın içerisinde var. P18F2550.PPI olarak. MPASM Suite içerisindeki 18F2550.inc in içindeki koduda ekliyorum.
Kod Seç
[CONFIGEND]

Default 
Configuration Definitions
[DEFCONFIGSTART]
ifndef CONFIG_REQ
ifdef PLL
@REQ ; Do we require the PLL ?
__config Config1LPLLDIV_5_1 CPUDIV_OSC1_PLL2_1 USBDIV_2_1
__config Config1H
FOSC_HSPLL_HS_1
Else
__config Config1HFOSC_HSPLL_HS_1
EndIf
__config Config2LPWRT_OFF_2 BOR_ON_2 BORV_3_2 VREGEN_ON_2
ifdef WATCHDOG_REQ
__config Config2H
WDT_ON_2 WDTPS_128_2
Else
__config Config2HWDT_OFF_2 WDTPS_128_2
EndIf
__config Config3HPBADEN_OFF_3
ifdef DEBUG
@REQ ; Do we require DEBUG ?
__config Config4LLVP_OFF_4 XINST_OFF_4 DEBUG_ON_4
Else
__config Config4LLVP_OFF_4 XINST_OFF_4 DEBUG_OFF_4
EndIf
EndIf
[
DEFCONFIGEND]




Kod Seç
;
;==========================================================================
;==========================================================================
;
;       
Configuration Bits
;
;   
NAME            Address
;   CONFIG1L        300000h
;   CONFIG1H        300001h
;   CONFIG2L        300002h
;   CONFIG2H        300003h
;   CONFIG3H        300005h
;   CONFIG4L        300006h
;   CONFIG5L        300008h
;   CONFIG5H        300009h
;   CONFIG6L        30000Ah
;   CONFIG6H        30000Bh
;   CONFIG7L        30000Ch
;   CONFIG7H        30000Dh
;
;==========================================================================

The following is an assignment of address values for all of the
configuration registers for the purpose of table reads
_CONFIG1L        EQU  H
'300000'
_CONFIG1H        EQU  H'300001'
_CONFIG2L        EQU  H'300002'
_CONFIG2H        EQU  H'300003'
_CONFIG3H        EQU  H'300005'
_CONFIG4L        EQU  H'300006'
_CONFIG5L        EQU  H'300008'
_CONFIG5H        EQU  H'300009'
_CONFIG6L        EQU  H'30000A'
_CONFIG6H        EQU  H'30000B'
_CONFIG7L        EQU  H'30000C'
_CONFIG7H        EQU  H'30000D'



Kodlar bu şekilde. Türlü türlü 2 taraftan kapatıp açmalar yaptım. Sonuç aynı. Ne yapmalıyım tam olarak? Teşekkürler.

Maxim


MR.CAPSLOCK

13 Nisan 2017, 23:48:39 #2 Son düzenlenme: 13 Nisan 2017, 23:50:57 MR.CAPSLOCK
Alıntı yapılan: Maxim - 13 Nisan 2017, 23:37:35
protonun config wizard programını kullanabilirsiniz

http://www.picproje.org/index.php/topic,32231.0.html


Program harika. Sadece cihazı seçip yapıştırdığım da hatalar aynı kalıyor. Bazılarını değişmem gerekiyor sanıyorum ama hangisini OFF ON yapacağımı nasıl bileceğim? Bu konuda bilgim yok maalesef :/



MR.CAPSLOCK

Bu program ile kodu oraya kendi yapıştırınca, PPI. veya INC uzantılı 18f2550 dosyalarında değişiklik yapmam gerekiyor mu hala?

Maxim

hayır ppi dosyalarıyla falan oynamanız gerekmiyor
siz tam olarak ne yapmak istiyorsunuz onu yazın, 18F2550 osc ayarları biraz alengirlidir ona bakalım
birde proton+ versiyonu kaçtır?

MR.CAPSLOCK

Alıntı yapılan: Maxim - 14 Nisan 2017, 09:40:59
hayır ppi dosyalarıyla falan oynamanız gerekmiyor
siz tam olarak ne yapmak istiyorsunuz onu yazın, 18F2550 osc ayarları biraz alengirlidir ona bakalım
birde proton+ versiyonu kaçtır?

Cevap için teşekkürler.
Ne yapmak istiyorumdan kastınız, devre ne yapıyor ise, SD kart var RTC var. Harici OSC kullanıyorum. 20mHz. Sensörlerden gelen verileri zaman verileriyle birleştirip SD karta yazıyor.

ProtonIDE 2.0.1.0
Compiler Proton Basic Compiler 3.5.7.1

Maxim

20mhz ext osc ile bu şekilde çalışması lazım
benim derleyici 3.5.7.4 ve hatasız derliyor

Kod Seç

;-------------------------------------------------------------------------------
;**** 
Added by Fuse Configurator ****
; Use 
the Fuse Configurator plug-in to change these settings

Device 
18F2550
Declare Xtal=20

Config_Start
  PLLDIV 
1    ;No prescale (4 MHz oscillator input drives PLL directly)
  
CPUDIV OSC1_PLL2    ;[Primary Oscillator Src: /1][96 MHz PLL Src: /2]
  
USBDIV 1    ;USB clock source comes directly from the primary oscillator block with no postscale
  FOSC 
HS    ;HS oscillator (HS)
  
FCMEN OFF    ;Fail-Safe Clock Monitor disabled
  IESO 
OFF    ;Oscillator Switchover mode disabled
  PWRT 
On    ;PWRT enabled
  BOR 
OFF    ;Brown-out Reset disabled in hardware and software
  BORV 
3    ;Minimum setting
  VREGEN 
OFF    ;USB voltage regulator disabled
  WDT 
OFF    ;WDT disabled (control is placed on the SWDTEN bit)
  
WDTPS 32768    ;1:32768
  CCP2MX 
OFF    ;CCP2 input/output is multiplexed with RB3
  PBADEN 
OFF    ;PORTB<4:0pins are configured as digital I/O on Reset
  LPT1OSC 
OFF    ;Timer1 configured for higher power operation
  MCLRE 
OFF    ;RE3 input pin enabledMCLR pin disabled
  STVREN 
OFF    ;Stack full/underflow will not cause Reset
  LVP 
OFF    ;Single-Supply ICSP disabled
  XINST 
OFF    ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
  
Debug OFF    ;Background debugger disabledRB6 and RB7 configured as general purpose I/O pins
  Cp0 
OFF    ;Block 0 (000800-001FFFhis not code-protected
  
CP1 OFF    ;Block 1 (002000-003FFFhis not code-protected
  
CP2 OFF    ;Block 2 (004000-005FFFhis not code-protected
  
CP3 OFF    ;Block 3 (006000-007FFFhis not code-protected
  
CPB OFF    ;Boot block (000000-0007FFhis not code-protected
  
CPD OFF    ;Data EEPROM is not code-protected
  
WRT0 OFF    ;Block 0 (000800-001FFFhis not write-protected
  
WRT1 OFF    ;Block 1 (002000-003FFFhis not write-protected
  
WRT2 OFF    ;Block 2 (004000-005FFFhis not write-protected
  
WRT3 OFF    ;Block 3 (006000-007FFFhis not write-protected
  
WRTC OFF    ;Configuration registers (300000-3000FFhare not write-protected
  
WRTB OFF    ;Boot block (000000-0007FFhis not write-protected
  
WRTD OFF    ;Data EEPROM is not write-protected
  
EBTR0 OFF    ;Block 0 (000800-001FFFhis not protected from table reads executed in other blocks
  EBTR1 
OFF    ;Block 1 (002000-003FFFhis not protected from table reads executed in other blocks
  EBTR2 
OFF    ;Block 2 (004000-005FFFhis not protected from table reads executed in other blocks
  EBTR3 
OFF    ;Block 3 (006000-007FFFhis not protected from table reads executed in other blocks
  EBTRB 
OFF    ;Boot block (000000-0007FFhis not protected from table reads executed in other blocks
Config_End

;**** End of Fuse Configurator Settings ****
;-------------------------------------------------------------------------------

MR.CAPSLOCK

14 Nisan 2017, 19:33:53 #7 Son düzenlenme: 17 Nisan 2017, 01:02:09 muhittin_kaplan
Bunları kendi koduma yapıştırıyorum değil mi?. Öyle yapınca hata devam ediyor. Fakat sanırım şununla ilgili olabilir.
SD_FILE_SYSTEM.pbp kullanıyorum. hata metninde ilk bu satırı gösterip illegal opcode diyor. Sonra masaüstünü göstererek onlarca overwriting hatası veriyor. Dosya eklenmiyor mu? Ekleyemedim. Codu koyuyorum bu kütüphanenin. Kütüphaneyi kaldırınca sigorta kodlarını yazmadan da derliyor. Tabi SD kart fonksiyonlarını tanımlamamışsın diyor otomatik olarak.


Kod Seç

@LIB_NAME SD_File_System22

@LIB_NOTES 

@LIB_SHARED
      
      Symbol SD_CS 
PORTB.2                                      'SPI CS to SD CS (SD PortB pin 2)
      Symbol SD_DI = PORTB.5                                      '
SPI DO to SD DI (SD PortB Pin 5)
      
Symbol SD_CLK PORTB.1                                     'SPI CLK to SD CLK (SD PortB Pin 1)
      Symbol SD_DO = PORTB.0                                      '
SPI DI to SD DO (SD PortB Pin 0)
' Code and data shared by more than one subroutine in this library
Dim SD_ByteR As Byte                                                            '
Receive byte from SHIn
Dim SD_Idx 
As Byte                                                              'General index byte
Dim SD_Sector_Num As Dword                                                      '
Sector number for read/write
Dim SD_Address 
As Dword                                                         'Byte address
Dim SD_Seek_Response_Idx As Word                                                '
Index in SD_Seek_Response
Dim SD_Seek_Response_Reqd 
As Byte                                               'Required byte returned from Cmd
Dim SD_Seek_Response_Return As Byte                                             '
Return flag from SD_Seek_ResponseOKTimeout
Dim SD_Return 
As Byte                                                           'Return flag from Subroutine: 0 = OK, 1 = Timeout
Dim SD_Buffer0[$100] As Byte                                                    '
Read/write buffer L
Dim SD_Buffer1
[$100] As Byte                                                    'Read/write buffer - H
Dim SD_Byte0 As Byte                                                            '
Cmd Bytes 0-5
Dim SD_Byte1 
As Byte
Dim SD_Byte2 
As Byte
Dim SD_Byte3 
As Byte
Dim SD_Byte4 
As Byte
Dim SD_Byte5 
As Byte
'Dim SD_Byte_Out As Byte
'
Dim SD_Byte_In As Byte
Dim SD_Buffer_Idx 
As Word                                                       'Current position in buffer
Dim SD_Byte_RW As Byte                                                          '
Byte to Read/Write
Dim SD_RW_Option 
As Byte
'Dim FSR0 As FSR0L.Word                                                         'Combine FSR0L/as a 16-bit register
Dim SD_Extended_Return 
As Byte                                                  'Return flag from Extended Subroutine: 0 = OK, 1 = Fail
Dim SD_Extended_Return_Root_Dir As Byte                                         '
Return flag from Root Dir SubroutineOKFail
Dim SD_Data_IO 
As Byte                                                          'Bytes read/written to SD/MMC card
Dim SD_Buffer_Pos As Word                                                       '
Internal counter of bytes in Sector (i.e512)
Dim SD_Root_Dir_File_Pos As Byte
Dim SD_Sec_Num 
As Dword                                                         'Sector of interest
'
Dim SD_Hidden_Secs As DWord
Dim SD_Secs_Per_Cluster 
As Byte
Dim SD_Reserved_Secs 
As Word
Dim SD_Secs_Per_FAT 
As Word
Dim SD_Num_of_FATs 
As Byte
Dim SD_Num_of_Secs 
As Dword
Dim SD_Bytes_Per_Sec 
As Word
Dim SD_Num_of_Root_Entries 
As Word
Dim SD_Secs_in_Root 
As Word
Dim SD_Boot_Record 
As Word
Dim SD_FAT1 
As Dword
Dim SD_FAT2 
As Dword
Dim SD_Root_Dir 
As Dword
Dim SD_Data_Area 
As Dword
Dim SD_FAT_Entry 
As Word
Dim SD_FAT_Sec 
As Dword
Dim SD_FAT_Buffer_Pos 
As Word
Dim SD_FAT_Sec_Prev 
As Dword
Dim SD_FAT_Buffer_Pos_Prev 
As Word
Dim SD_Root_Dir_Sec 
As Dword
Dim SD_Root_Dir_Pos 
As Word
Dim SD_Data_Sec 
As Dword
Dim SD_Data_Buffer_Pos 
As Word
Dim SD_File_Name 
As String 8
Dim SD_File_Ext 
As String 3
Dim SD_Root_Dir_File
[32] As Byte
Dim SD_Write_Sec_Num 
As Dword
Dim SD_Write_Buffer_Pos 
As Word
Dim SD_Null_F 
As Byte
Dim SD_Cluster_Num 
As Word
Dim SD_Cluster_Num_Prev 
As Word
Dim SD_Last_Cluster 
As Word
Dim SD_Sec_in_Cluster 
As Byte
Dim SD_File_Size 
As Dword
Dim SD_IO_Byte 
As Byte
Dim SD_Temp_Byte 
As Byte
Dim SD_Temp 
As Word
Dim SD_Temp_Dword 
As Dword
Dim SD_Cluster_Seq_Num 
As Word
Dim SD_Cluster_Seq_Idx 
As Word
Dim SD_Cluster_Seq_Num_Prev 
As Word
Dim SD_Cluster_Seq_Idx_Prev 
As Word
Dim SD_Find_Root_Dir_Entry_F 
As Byte                                            'SD_Find_Root_Dir_Entry request: 0=Free, 1=Existing
Dim SD_Bytes_Read As Dword                                                      '
Sequential Read marker
Dim SD_EOF 
As Bit                                                               'EOF marker
Dim SD_File_Num As Word                                                         '
File number for Dir
Dim SD_Dir_Direction 
As Byte                                                    'SD_Dir direction flag: 0 - first, 1 - next (default), 2 - previous
Dim SD_Extended_Return_Int As Byte                                              '
Return flag from Init SubroutineOKFail
Dim SD_File_Size_Left 
As Dword
Dim SD_RW_Ptr 
As SD_Bytes_Read
Dim SD_Free_Cluster_Num 
As SD_Cluster_Seq_Num
Dim SD_Free_Space_KB 
As SD_Bytes_Read
Dim SD_Disk_Size_KB 
As SD_Bytes_Read
Dim SD_Timeout 
As Byte
Dim SD_Day 
As Byte
Dim SD_Month 
As Byte
Dim SD_Year 
As Byte
Dim SD_MSeconds 
As Byte
Dim SD_Seconds 
As Byte
Dim SD_Minutes 
As Byte
Dim SD_Hours 
As Byte
Dim SD_Is_Dirty 
As Byte
Symbol SD_First 
0
Symbol SD_Next 
1
Symbol SD_Previous 
2
Symbol SD_SPI_BF 
SSPSTAT.0                                                    'Master Synchronous Serial Port Buffer Full Status Flag
Dim SD_SSPSTAT As Byte
Symbol SD_SPI_IF = PIR1.3                                                       '
Master Synchronous Serial Port Interrupt Flag
Symbol SD_SPI_FOSC_64 
= %10                                                     'SPI Master mode, clock = FOSC/64
Symbol SD_SPI_FOSC_16 = %01                                                     '
SPI Master modeclock FOSC/16
Symbol SD_SPI_FOSC_04 
= %00                                                     'SPI Master mode, clock = FOSC/04

@LOCAL
Add Local (non-persistentvariables here
@CODE
'------------------------------------------------------------------------------- 
SD_Write_Sub:                                                                   '
Write Byte
    
If SD_Buffer_Idx $FF Then
        SD_Buffer1
[SD_Buffer_Idx - $100] = SD_Byte_RW
    
Else
        
SD_Buffer0[SD_Buffer_Idx] = SD_Byte_RW
    
EndIf
    
SD_Is_Dirty 1
    
If SD_Buffer_Idx = $1FF Then
        Repeat
            GoSub SD_Write_Sector
        Until SD_Return 
0
        SD_Is_Dirty 
0
        SD_Buffer_Idx 
0
        Inc SD_Sector_Num
    
Else
        
SD_Buffer_Idx SD_Buffer_Idx 1
    
EndIf
    Return
'------------------------------------------------------------------------------- 
SD_Sector_Sub:
    SD_Buffer_Idx = 0
    If SD_RW_Option = 0 Then                                                    '
SD_RW_OptionWriteRead 
        
For SD_Idx 0 To $FF
            SD_Buffer0
[SD_Idx] = 0
            SD_Buffer1
[SD_Idx] = 0
        Next SD_Idx
    
Else
        
GoSub SD_Read_Sector
    
EndIf
    Return         
'------------------------------------------------------------------------------- 
'
SD_Send_Cmd:
'    SHOut SD_DI, SD_CLK, msbfirst, [SD_Byte0,SD_Byte1,SD_Byte2,SD_Byte3,SD_Byte4]
'
SD_Send_Byte:
'    SHOut SD_DI, SD_CLK, msbfirst, [SD_Byte5]
'    
Return
'------------------------------------------------------------------------------- 
'
SD_Receive_Byte:
'    SHIn SD_DO, SD_CLK, msbpre, [SD_ByteR]
'    
Return
'------------------------------------------------------------------------------- 
SD_Seek_Response:                                                               '
Wait for response from SD/MMC or timeout
'   SD_Seek_Response_Idx = $FFFF
    Repeat
        GoSub SD_Receive_Byte
        Dec SD_Seek_Response_Idx
    Until SD_ByteR = SD_Seek_Response_Reqd Or SD_Seek_Response_Idx = 0
    If SD_Seek_Response_Idx = 0 Then
        SD_Seek_Response_Return = 1                                             '
SD_Return 1Timeout
    
Else
        
SD_Seek_Response_Return 0                                             'SD_Return = 0: Response obtained
    EndIf
    Return                                                           
'
------------------------------------------------------------------------------- 
SD_Write_Sector:                                                                'Write to SD/MMC
    SD_Timeout = 0
    SD_Return = 1                                                           
SD_Write_Sector_Start:
    SD_Address = SD_Sector_Num << 9 
'
SD_Cmd24:
    
Low SD_CS
    SD_Byte0 
= $58
    SD_Byte1 
SD_Address.Byte3
    SD_Byte2 
SD_Address.Byte2
    SD_Byte3 
SD_Address.Byte1
    SD_Byte4 
SD_Address.Byte0
    SD_Byte5 
$FF
	
SD_Seek_Response_Reqd = $00
	
SD_Seek_Response_Idx $FFFF
	
GoSub SD_Send_Cmd
    GoSub SD_Seek_Response
    
If SD_Seek_Response_Return 1 Then GoTo SD_Write_Sector_Error
'SD_Write_Start_Token:
    SD_Byte5 = $FE
    GoSub SD_Send_Byte
	
                                                        '
Data start token
'SD_Write_Data_Block:
    For SD_Idx = 0 To $FF
        SD_Byte5 = SD_Buffer0[SD_Idx]
        GoSub SD_Send_Byte                                                      '
Send SD_Buffer0
    Next SD_Idx    
    
For SD_Idx 0 To $FF
        SD_Byte5 
SD_Buffer1[SD_Idx]
        
GoSub SD_Send_Byte                                                      'Send SD_Buffer1
    Next SD_Idx    
'
SD_Write_Dummy_CRC:        
    
SD_Byte5 $FF
    GoSub SD_Send_Byte
    GoSub SD_Send_Byte                                                          
'Send dummy CRC to conclude data block
'
SD_Data_Response_Token:
	
SD_Seek_Response_Reqd $FF
    SD_Seek_Response_Idx 
$FFFF
    GoSub SD_Receive_Byte
    SD_Temp_Byte 
SD_ByteR
    GoSub SD_Seek_Response
    SD_Temp_Byte 
SD_Temp_Byte & $0F
    
If SD_Temp_Byte <> $05 Then GoTo SD_Write_Sector_Error
    
If SD_Seek_Response_Return 1 Then GoTo SD_Write_Sector_Error
    SD_Return 
0                                                               'SD_Write completed successfully
    High SD_CS
    GoTo SD_Write_Sector_End                                                    
SD_Write_Sector_Error:
    High SD_CS
    SD_Timeout = SD_Timeout + 1
    If SD_Timeout < $03 Then
        GoTo SD_Write_Sector_Start
    EndIf
SD_Write_Sector_End:      
    Return
'
-------------------------------------------------------------------------------
SD_Read_Sector:                                                                 'Read from SD/MMC
    SD_Timeout = 0
    SD_Return = 1                                                           
SD_Read_Sector_Start:
	
SD_Address = SD_Sector_Num << 9 
'
SD_Cmd17:
    
Low SD_CS
    SD_Byte0 
= $51
    SD_Byte1 
SD_Address.Byte3
    SD_Byte2 
SD_Address.Byte2
    SD_Byte3 
SD_Address.Byte1
    SD_Byte4 
SD_Address.Byte0
    SD_Byte5 
$FF
	
GoSub SD_Send_Cmd
	
SD_Seek_Response_Reqd = $00
    SD_Seek_Response_Idx 
$FFFF
    GoSub SD_Seek_Response
    
If SD_Seek_Response_Return 1 Then GoTo SD_Read_Sector_Error
'SD_Read_Start_Token:
	
SD_Seek_Response_Reqd = $FE
    SD_Seek_Response_Idx = $FFFF
    GoSub SD_Seek_Response
    If SD_Seek_Response_Return = 1 Then GoTo SD_Read_Sector_Error
'
SD_Read_Data_Block:
    For 
SD_Idx 0 To $FF
        GoSub SD_Receive_Byte                                                   
'Read SD_Buffer0
        SD_Buffer0[SD_Idx] = SD_ByteR
    Next SD_Idx    
    For SD_Idx = 0 To $FF
        GoSub SD_Receive_Byte                                                   '
Read SD_Buffer1
        SD_Buffer1
[SD_Idx] = SD_ByteR
    Next SD_Idx    
'SD_Read_Dummy_CRC:        
    GoSub SD_Receive_Byte                                                       '
Read dummy CRC to conclude data block
    GoSub SD_Receive_Byte                                     
    High SD_CS
    SD_Byte5 
$FF
    GoSub SD_Send_Byte                                                          
'Clock SD/MMC to complete job
    SD_Return = 0                                                               '
SD_Read completed successfully
    
GoTo SD_Read_Sector_End
SD_Read_Sector_Error
:
    
High SD_CS
    SD_Timeout 
SD_Timeout 1
    
If SD_Timeout < $03 Then
        
GoTo SD_Read_Sector_Start
    
EndIf
SD_Read_Sector_End:      
    Return                                                                
'-------------------------------------------------------------------------------
SD_Read_FAT_Entry:
    If SD_Buffer_Pos > $0FF Then
        SD_FAT_Entry.Byte0 = SD_Buffer1[SD_Buffer_Pos - $100]                   '
Read FAT entry as 2-byte word
        SD_FAT_Entry
.Byte1 SD_Buffer1[SD_Buffer_Pos - $100]
    Else
        
SD_FAT_Entry.Byte0 SD_Buffer0[SD_Buffer_Pos]                          'Read FAT entry as 2-byte word
        SD_FAT_Entry.Byte1 = SD_Buffer0[SD_Buffer_Pos + 1]
    EndIf
    Return
'
-------------------------------------------------------------------------------
SD_Find_Free_Cluster:
    
SD_Temp_Dword SD_FAT1 SD_Secs_Per_FAT 1
    
For SD_Sec_Num = (SD_FAT_Sec SD_FAT1To SD_Temp_Dword                    'Scan SD_FAT1 for free cluster address
        SD_Sector_Num = SD_Sec_Num
        SD_RW_Option = 1
        GoSub SD_Sector_Sub
'       
SD_Sector SD_Sec_Num1                                                 'Set sector & read sector to SD_Buffer
        For SD_Buffer_Pos = $0000 To $1FF Step 2
            If SD_Sec_Num > (SD_FAT_Sec + SD_FAT1) Or SD_Buffer_Pos >= (SD_FAT_Buffer_Pos + (2 * SD_Cluster_Seq_Num)) Then            
                GoSub SD_Read_FAT_Entry
                If SD_FAT_Entry = $0000 Then GoTo SD_Store_FAT_Position
            EndIf
        Next SD_Buffer_Pos
    Next SD_Sec_Num
    SD_Extended_Return = 1
    Return
SD_Store_FAT_Position:  
    SD_FAT_Sec = SD_Sec_Num - SD_FAT1                                           '
Store FAT Sec &
    
SD_FAT_Buffer_Pos SD_Buffer_Pos                                           'Buffer Position for Free Cluster
    SD_Cluster_Num = (SD_FAT_Sec * $100) 
    SD_Cluster_Num = (SD_FAT_Buffer_Pos / 2) + SD_Cluster_Num
    SD_Cluster_Seq_Num = 0
    For SD_Buffer_Pos = SD_FAT_Buffer_Pos To $1FF Step 2
        GoSub SD_Read_FAT_Entry
        If SD_FAT_Entry = $0000 Then
            Inc SD_Cluster_Seq_Num                                              '
Number of empty clusters in Sector of FAT1
        
Else
            GoTo 
SD_Store_Cluster_Seq
        
EndIf
    
Next SD_Buffer_Pos
SD_Store_Cluster_Seq
:
    
SD_Cluster_Seq_Idx 1                                                      'Initilise Cluster Sequence
    SD_Extended_Return = 0
    Return
'
-------------------------------------------------------------------------------
SD_Modify_File_Name:
    
SD_Null_F 0
    
For SD_Root_Dir_File_Pos = $00 To $07                                       'Replace Blank File Name Chr with $20
        If SD_Null_F = 1 Or SD_File_Name[SD_Root_Dir_File_Pos] = 0 Then
            SD_File_Name[SD_Root_Dir_File_Pos] = $20
            SD_Null_F = 1
        EndIf                            
    Next SD_Root_Dir_File_Pos
    SD_Null_F = 0
    For SD_Root_Dir_File_Pos = $08 To $0A                                       '
Replace Blank File Name Chr with $20
        
If SD_Null_F Or SD_File_Ext[SD_Root_Dir_File_Pos - $08] = 0 Then
            SD_File_Ext
[SD_Root_Dir_File_Pos - $08] = $20
            SD_Null_F 
1
        
EndIf                                                               
    
Next SD_Root_Dir_File_Pos
    
Return
'-------------------------------------------------------------------------------
SD_Find_Root_Dir_Entry:
    GoSub SD_Modify_File_Name
    SD_Num_of_Root_Entries = 0
    SD_Temp_Dword = SD_Root_Dir + SD_Secs_in_Root - 1
    For SD_Sec_Num = SD_Root_Dir To SD_Temp_Dword                               '
Scan Root Dir for free entry
        SD_Sector_Num 
SD_Sec_Num
        SD_RW_Option 
1
        GoSub SD_Sector_Sub
'       SD_Sector SD_Sec_Num, 1                                                 'Set sector read sector to SD_Buffer
        
For SD_Buffer_Pos = $000 To $1FF Step 32
            
For SD_Root_Dir_File_Pos 0 To 31
                SD_Temp 
SD_Buffer_Pos SD_Root_Dir_File_Pos
                
If SD_Temp > $0FF Then
                    SD_Root_Dir_File
[SD_Root_Dir_File_Pos] = SD_Buffer1[SD_Temp - $100]                            
                Else
                    
SD_Root_Dir_File[SD_Root_Dir_File_Pos] = SD_Buffer0[SD_Temp]
                EndIf                            
            
Next SD_Root_Dir_File_Pos
            Select SD_Find_Root_Dir_Entry_F
            
Case 0                                                              'Search for free position
                If SD_Root_Dir_File[0] = $00 Or SD_Root_Dir_File[0] = $E5 Then
                    GoTo SD_Store_Root_Direct_Position
                EndIf
            Case 1                                                              '
Search for file
                SD_Null_F 
0
                
For SD_Root_Dir_File_Pos = $00 To $07                           'Check File Name
                    If SD_Root_Dir_File[SD_Root_Dir_File_Pos] <> SD_File_Name[SD_Root_Dir_File_Pos] Then 
                        SD_Null_F = 1
                        Break
                    EndIf
                Next SD_Root_Dir_File_Pos
                For SD_Root_Dir_File_Pos = $08 To $0A                           '
Check File Ext
                    
If SD_Root_Dir_File[SD_Root_Dir_File_Pos] <> SD_File_Ext[SD_Root_Dir_File_Pos - $08Then 
                        SD_Null_F 
1
                        
Break
                    EndIf
                
Next SD_Root_Dir_File_Pos
                
If SD_Null_F 0 Then GoTo SD_Store_Root_Direct_Position
            
Case 2                                                              'SD_Dir command
                If SD_Root_Dir_File[$0B] | %11110000 <> $FF Then                '
Not Long Filename entry
                    
If SD_Root_Dir_File[$00] <> $00 Then                        'Not empty entry
                        If SD_Root_Dir_File[$00] <> $E5 Then                    '
Not deleted entry
                            
If SD_Root_Dir_File[$0B] & %00011110 0 Then       'Not System, Hidden, Directory or Volume (File attributes (00ADVSHR) - 0: unused bit, A: archive bit, D: Dir bit, V: volume bit, S: system bit, R: read-only bit)
                                Inc SD_Num_of_Root_Entries
                                If SD_Num_of_Root_Entries = SD_File_Num Then    '
Found required entry in directory
                                    
For SD_Root_Dir_File_Pos = $00 To $07       'Copy File Name
                                        SD_File_Name[SD_Root_Dir_File_Pos] = SD_Root_Dir_File[SD_Root_Dir_File_Pos]
                                    Next SD_Root_Dir_File_Pos
                                    For SD_Root_Dir_File_Pos = $08 To $0A       '
Copy File Ext
                                        SD_File_Ext
[SD_Root_Dir_File_Pos - $08] = SD_Root_Dir_File[SD_Root_Dir_File_Pos
                                    
Next SD_Root_Dir_File_Pos
                                    
GoTo SD_Store_Root_Direct_Position          'Returns with SD_Extended_Return_Root_Dir = 0 & Filename & Extension set
                                EndIf
                            EndIf
                        EndIf
                    EndIf
                EndIf
            EndSelect
        Next SD_Buffer_Pos
    Next SD_Sec_Num
    SD_Extended_Return_Root_Dir = 1
    Return
SD_Store_Root_Direct_Position:
    SD_Root_Dir_Sec = SD_Sec_Num - SD_Root_Dir                                  '
Store Root Dir Position &
    
SD_Root_Dir_Pos SD_Buffer_Pos                                             'Buffer Position
    SD_Extended_Return_Root_Dir = 0
    Return
'
-------------------------------------------------------------------------------
SD_Insert_Byte_Into_Buffer:
    If 
SD_Write_Buffer_Pos > $0FF Then
        SD_Buffer1
[SD_Write_Buffer_Pos - $100] = SD_Data_IO
    
Else
        
SD_Buffer0[SD_Write_Buffer_Pos] = SD_Data_IO
    
EndIf
    Return         
'-------------------------------------------------------------------------------
SD_Assemble_FAT_Sector:
    SD_Write_Buffer_Pos = SD_FAT_Buffer_Pos_Prev
    SD_Cluster_Num = (SD_FAT_Sec_Prev * $100)                                   '
Derive first Cluster Number
    SD_Cluster_Num 
= (SD_FAT_Buffer_Pos_Prev 2) + SD_Cluster_Num
    Inc SD_Cluster_Num
    
While SD_Cluster_Seq_Num_Prev 1
        SD_Data_IO 
SD_Cluster_Num.Byte0                                  
        GoSub SD_Insert_Byte_Into_Buffer
        Inc SD_Write_Buffer_Pos
        SD_Data_IO 
SD_Cluster_Num.Byte1                                  
        GoSub SD_Insert_Byte_Into_Buffer
        Inc SD_Write_Buffer_Pos      
        Inc SD_Cluster_Num
        Dec SD_Cluster_Seq_Num_Prev
    Wend 
    
Return
'-------------------------------------------------------------------------------
SD_Assemble_FAT_Sector_End_Cont:
    SD_Cluster_Num = (SD_FAT_Sec * $100) 
    SD_Cluster_Num = (SD_FAT_Buffer_Pos / 2) + SD_Cluster_Num
    SD_Data_IO = SD_Cluster_Num.Byte0                                  
    GoSub SD_Insert_Byte_Into_Buffer
    Inc SD_Write_Buffer_Pos
    SD_Data_IO = SD_Cluster_Num.Byte1                                  
    GoSub SD_Insert_Byte_Into_Buffer
    Return
'
-------------------------------------------------------------------------------
SD_Assemble_FAT_Sector_End_Close:
    
SD_Data_IO $FF                                  
    GoSub SD_Insert_Byte_Into_Buffer
    Inc SD_Write_Buffer_Pos
    GoSub SD_Insert_Byte_Into_Buffer
    
Return
'-------------------------------------------------------------------------------
SD_Write_Byte_To_File_Sub:
    Inc SD_RW_Ptr
    If SD_RW_Ptr > SD_File_Size Then
        Inc SD_File_Size
        SD_EOF = 1
    EndIf
    Inc SD_Data_Buffer_Pos
    If SD_Data_Buffer_Pos > SD_Bytes_Per_Sec Then
        Inc SD_Data_Sec
        Inc SD_Sec_in_Cluster
        If SD_Sec_in_Cluster > SD_Secs_Per_Cluster Then
            If SD_EOF = 0 Then                                                      '
Not extending file
                SD_FAT_Sec 
SD_Cluster_Num / $100                                  'Find FAT position for existing cluster
                SD_FAT_Buffer_Pos = SD_Cluster_Num // $100
                SD_FAT_Buffer_Pos = SD_FAT_Buffer_Pos * 2
                SD_Sector_Num = SD_FAT1 + SD_FAT_Sec
                SD_RW_Option = 1
                GoSub SD_Sector_Sub
                SD_Buffer_Pos = SD_FAT_Buffer_Pos
                GoSub SD_Read_FAT_Entry
                SD_Cluster_Num = SD_FAT_Entry
                SD_Data_Sec = (SD_Cluster_Num - 2) * SD_Secs_Per_Cluster
                SD_Data_Sec = SD_Data_Sec + SD_Data_Area
                SD_Sector_Num = SD_Data_Sec
                SD_RW_Option = 1
                GoSub SD_Sector_Sub
                SD_Sec_in_Cluster = 1
                
                SD_FAT_Sec = SD_Cluster_Num / $100                                  '
Find new FAT position for existing cluster
                SD_FAT_Buffer_Pos 
SD_Cluster_Num // $100
                
SD_FAT_Buffer_Pos SD_FAT_Buffer_Pos 2
                         
            
Else                                                                    'Extending file
                Inc SD_Cluster_Seq_Idx
                If SD_Cluster_Seq_Idx > SD_Cluster_Seq_Num Then
                    SD_FAT_Buffer_Pos_Prev = SD_FAT_Buffer_Pos                      
                    SD_FAT_Sec_Prev = SD_FAT_Sec
                    SD_Cluster_Seq_Idx_Prev = SD_Cluster_Seq_Idx
                    SD_Cluster_Seq_Num_Prev = SD_Cluster_Seq_Num
    '               
Inc SD_FAT_Sec
                    GoSub SD_Find_Free_Cluster
                    
If SD_Extended_Return 1 Then Return
                    
SD_Write_Sec_Num SD_FAT1 SD_FAT_Sec_Prev                    'Write complete sector to FAT1    
                    SD_Sector_Num = SD_Write_Sec_Num
                    SD_RW_Option = 1
                    GoSub SD_Sector_Sub
    '               
SD_Sector SD_Write_Sec_Num1                                   'Set sector & read sector to SD_Buffer
                    GoSub SD_Assemble_FAT_Sector                                    '
Modify Buffer to assemble FAT
                    GoSub SD_Assemble_FAT_Sector_End_Cont
                    GoSub SD_Write_Sector                                           
'Write FAT1
                    SD_Sector_Num = SD_FAT2 + SD_FAT_Sec_Prev                       '
Write complete sector to FAT2    
                    GoSub SD_Write_Sector                                           
'Write FAT2 as copy of FAT1 without re-assembly
                    SD_Data_Sec = (SD_Cluster_Num - 2) * SD_Secs_Per_Cluster
                    SD_Data_Sec = SD_Data_Sec + SD_Data_Area
                    SD_Sector_Num = SD_Data_Sec
                    SD_RW_Option = 0
                    GoSub SD_Sector_Sub
    '               
SD_Sector SD_Data_Sec0
                
Else
                    
Inc SD_Cluster_Num
                
EndIf
                
SD_Sec_in_Cluster 1
            
EndIf
        Else
        
GoSub SD_Read_Sector        
        
EndIf      
        
SD_Data_Buffer_Pos 1
    
EndIf
    
SD_Byte_RW SD_IO_Byte
    GoSub SD_Write_Sub
    SD_Extended_Return 
0
    
Return        
'-------------------------------------------------------------------------------
SD_Check_For_File_Sub:
    SD_Find_Root_Dir_Entry_F = 1
    GoSub SD_Find_Root_Dir_Entry
    Return
'
-------------------------------------------------------------------------------
SD_Read_Sub:                                                                    'Read Byte
    If SD_Buffer_Idx > $1FF Then                                                '
Inc Sector if read past end of previous sector
'        If SD_Is_Dirty = 1 Then                                                'If bytes have been written in current sectorwrite sector back to SD card and reset SD_Is_Dirty
'            Repeat
'                
GoSub SD_Write_Sector
'            Until SD_Return = 0
'            
SD_Is_Dirty 0
'        EndIf
        SD_Buffer_Idx = 0
        Inc SD_Sector_Num
        SD_RW_Option = 1
        GoSub SD_Sector_Sub                                                     
    EndIf
    If SD_Buffer_Idx > $0FF Then
        SD_Byte_RW = SD_Buffer1[SD_Buffer_Idx - $100]
    Else
        SD_Byte_RW = SD_Buffer0[SD_Buffer_Idx]
    EndIf
    Inc SD_Buffer_Idx
    Return
'
-------------------------------------------------------------------------------

@
END

@MACRO_START SD_Check_For_File

[member=12364]target[/member16 Bit

@HELP 

SD_Check_For_File Macro  
 GoSub SD_Check_For_File_Sub 
 
#if (SD_Check_For_File_RETURN != 1) 
  #error "SD_Check_For_File -  Mandatory return parameter missing" 
 #else 
  #if (Return_Type != Byte) && (Return_Type != Word) && (Return_Type != Dword) 
   #error "SD_Check_For_File - Return variable should be a Byte, Word or DWord variable" 
  #endif 
  #if (Return_Type == Byte) 
   
BYTE_BYTE SD_Extended_Return_Root_DirReturn_Var 
  
#endif 
  #if (Return_Type == Word) 
   
BYTE_WORD SD_Extended_Return_Root_DirReturn_Var 
  
#endif 
  #if (Return_Type == Dword) 
   
BYTE_DWORD SD_Extended_Return_Root_DirReturn_Var 
  
#endif 
 #endif 
Endm 

@LOCAL
'Add Local (non-persistent) variables here

@CODE


@END

@MACRO_START SD_Close_File

[member=12364]target[/member] 16 Bit

@HELP 

SD_Close_File Macro                                                          
    #if(Prm_Count != 0)         
     #error "No parameters required for SD_Close_File" 
     Exitm 
    #endif 
    GoSub SD_Close_File_Sub 
    Endm 

@LOCAL
'
Add Local (non-persistentvariables here

@CODE


SD_Close_File_Sub
:
'   SD_Byte_RW = $00
'   
While SD_Data_Buffer_Pos SD_Bytes_Per_Sec 
'       SD_Data_IO = $00
'       
SD_Write SD_Data_IO
'       GoSub SD_Write_Sub
'       
Inc SD_Data_Buffer_Pos
'   Wend
    If SD_Is_Dirty = 1 Then
        Repeat
            GoSub SD_Write_Sector                                               '
Write current sector to file
        Until SD_Return 
0
    
EndIf
    
SD_Write_Sec_Num SD_Root_Dir SD_Root_Dir_Sec              
    SD_Sector_Num 
SD_Write_Sec_Num
    SD_RW_Option 
1
    GoSub SD_Sector_Sub
'   SD_Sector SD_Write_Sec_Num, 1                                               'Set sector read sector to SD_Buffer
    SD_Write_Buffer_Pos 
SD_Root_Dir_Pos + $1C
    SD_Data_IO 
SD_File_Size.Byte0                                             'File Size  
    GoSub SD_Insert_Byte_Into_Buffer
    Inc SD_Write_Buffer_Pos
    SD_Data_IO = SD_File_Size.Byte1                                             '
File Size  
    GoSub SD_Insert_Byte_Into_Buffer
    Inc SD_Write_Buffer_Pos
    SD_Data_IO 
SD_File_Size.Byte2                                             'File Size  
    GoSub SD_Insert_Byte_Into_Buffer
    Inc SD_Write_Buffer_Pos
    SD_Data_IO = SD_File_Size.Byte3                                             '
File Size  
    GoSub SD_Insert_Byte_Into_Buffer
    SD_Write_Buffer_Pos 
SD_Root_Dir_Pos + $16                                 'Position Write_Buffer_Pos to start of modified time & date
    GoSub SD_Set_File_Time_Modified                                             '
Set file modified time date
    GoSub SD_Write_Sector
    
If SD_EOF 1 Then
        SD_FAT_Buffer_Pos_Prev 
SD_FAT_Buffer_Pos                      
        SD_FAT_Sec_Prev 
SD_FAT_Sec
        SD_Write_Sec_Num 
SD_FAT1 SD_FAT_Sec_Prev                            'Write complete sector to FAT1    
        SD_Sector_Num = SD_Write_Sec_Num
        SD_RW_Option = 1
        GoSub SD_Sector_Sub
    '   
SD_Sector SD_Write_Sec_Num1                                           'Set sector & read sector to SD_Buffer
        SD_Cluster_Seq_Num_Prev = SD_Cluster_Seq_Idx
        GoSub SD_Assemble_FAT_Sector                                            '
Modify Buffer to assemble FAT
        GoSub SD_Assemble_FAT_Sector_End_Close                                  
        GoSub SD_Write_Sector                                                   
'Write FAT1
        SD_Sector_Num = SD_FAT2 + SD_FAT_Sec_Prev                               '
Write complete sector to FAT2    
        GoSub SD_Write_Sector                                                   
'Write FAT2 as copy of FAT1 without re-assembly
    EndIf
    Return        


SD_Set_File_Time_Create:
    SD_Data_IO = SD_MSeconds + ((SD_Seconds // 2) * 100)                        '
Create Time/Date MSeconds
    GoSub SD_Insert_Byte_Into_Buffer      
    Inc SD_Write_Buffer_Pos
SD_Set_File_Time_Modified
:
    
SD_Data_IO = (SD_Seconds 2) | (SD_Minutes << 5)                           'Create Time/Date - Seconds/Minutes
    GoSub SD_Insert_Byte_Into_Buffer      
    Inc SD_Write_Buffer_Pos
    SD_Data_IO = (SD_Minutes >> 3) | (SD_Hours << 3)                            '
Create Time/Date Minutes/Hours
    GoSub SD_Insert_Byte_Into_Buffer      
    Inc SD_Write_Buffer_Pos
    SD_Data_IO 
SD_Day | (SD_Month << 5)                                       'Create Time/Date - Day/Month
    GoSub SD_Insert_Byte_Into_Buffer      
    Inc SD_Write_Buffer_Pos
    SD_Data_IO = (SD_Month >> 3) | ((SD_Year + 20) << 1)                        '
Create Time/Date Month/Year
    GoSub SD_Insert_Byte_Into_Buffer
    
Return     


@
END

@MACRO_START SD_Init

[member=12364]target[/member16 Bit

@HELP 

SD_Init Macro  
    GoSub SD_Init_Sub 
 
#if (SD_Init_RETURN != 1) 
 #else 
  #if (Return_Type != Byte) 
   #error "SD_Init - Return variable should be a Byte variable" 
  #endif 
  #if (Return_Type == Byte) 
   
BYTE_BYTE SD_ReturnReturn_Var 
  
#endif 
 #endif 
Endm 

@LOCAL
'Add Local (non-persistent) variables here

@CODE

'
------------------------------------------------------------------------------- 
SD_Send_Cmd'Software SPI Version
    SHOut SD_DI, SD_CLK, MsbFirst, [SD_Byte0,SD_Byte1,SD_Byte2,SD_Byte3,SD_Byte4]
SD_Send_Byte:
    SHOut SD_DI, SD_CLK, MsbFirst, [SD_Byte5]
    Return
'
------------------------------------------------------------------------------- 
SD_Receive_Byte'Software SPI Version
    SHIn SD_DO, SD_CLK, MsbPre, [SD_ByteR]
    Return
'
------------------------------------------------------------------------------- 

SD_Init_Sub:                                                                    'Initialise SD/MMC card
    Output SD_CS : Output SD_DI : Output SD_CLK : Input SD_DO                   '
Setup direction for SPI bus
	
High SD_CS                                                                  'Pull CS high
    SD_Byte0 = $FF
    SD_Byte1 = $FF
    SD_Byte2 = $FF
    SD_Byte3 = $FF
    SD_Byte4 = $FF
    SD_Byte5 = $FF
	
GoSub SD_Send_Cmd
	
GoSub SD_Send_Cmd
'
SD_Cmd0:                                                                       'SD/MMC Cmd 0 & CRC
    DelayMS 100
    Low SD_CS                                                                   '
Pull CS low
    SD_Byte0 
= $40
    SD_Byte1 
= $00
    SD_Byte2 
= $00
    SD_Byte3 
= $00
    SD_Byte4 
= $00
    SD_Byte5 
= $95
	
GoSub SD_Send_Cmd
	
SD_Seek_Response_Reqd = $01
    SD_Seek_Response_Idx 
$FF
    GoSub SD_Seek_Response
    
If SD_Seek_Response_Return 1 Then
        High SD_CS
        SD_Return 
1                                                           
        
Return
    EndIf
'SD_Cmd1:                                                                       'SD/MMC Cmd 1 CRC Init from idle
	
SD_Idx $FF
    Repeat
        SD_Byte0 
= $41
        SD_Byte1 
= $00
        SD_Byte2 
= $00
        SD_Byte3 
= $00
        SD_Byte4 
= $00
        SD_Byte5 
$FF
    
	
GoSub SD_Send_Cmd
	
    
SD_Seek_Response_Reqd = $00
        SD_Seek_Response_Idx 
$FF
        GoSub SD_Seek_Response
        Dec SD_Idx
	
Until SD_Seek_Response_Return Or SD_Idx 0
    
If SD_Idx 0 Then
        High SD_CS
        SD_Return 
1                                                           'SD_Init Failed @ Cmd 1

     

mehmet

@MR.CAPSLOCK ; mesajınıza kod eklerken, "KOD" düğmesini
kullanıp yeniden düzenleyiniz.
nothing

MR.CAPSLOCK

Alıntı yapılan: mehmet - 15 Nisan 2017, 14:45:16
@MR.CAPSLOCK ; mesajınıza kod eklerken, "KOD" düğmesini
kullanıp yeniden düzenleyiniz.


KOD düğmesini zaten kullanmıştım. Tekrar kullandım. Önizleme'de çalışır halde gözüküyor fakat onay bekleme kısmında uzuncana gözüküyor. Dikkat ederseniz kullanmış görünüyorum

muhittin_kaplan

Hocam Yanlış Kullanıyorsunuz bu code u,
eklemek istediğiniz kodları
[ code ] [ / code ] larının arasına alacaksınız.


[ code ]
kodlar...
kodlar...
kodlar...
[ /code ]

Maxim

sizin sd file system kodunda uyumsuz satırlar var
muhtemelen o kod eskidir ve yeni versiyon protona uymuyordur

güncelemeler yapıldıkça eskiden hata vermeyen bir takım komut düzeni artık değişik şekilde yazılması gerekiyor.
yani komut gene var ama farklı şekilde yazılması gerekiyor artık
sizin o kodun (kütüphanenin) içinde boyle satırlar vardır.