Arkadaşlar SD kart kullanımı ile ilgili birazcık bilgiye ihtiyacım var. Fat dosya sistemi hakkında hiç bilgim yok malesef. Fat16-32 dosya sistemlerini öğrenmeye çalışıyorum. Ayrıca SD kartın veri depolama yapısı sektörler hakkında öğrenmek istediğim birçok konu var. Şimdilik ufaktan başlıyarak sd kart içerisinde bir text dosyası oluşturup içine bazı veriler yazmak istiyorum. Sizce nereden başlamalıyım Beni bu konuda yönlendirirseniz sevinirim?
İlk olarak fat dosya sistemini öğrenmeniz gerekiyor.
Hızlıca yazabileceklerimi size iletmeye çalışayım, (çok uzun yıllar önce uğraşmıştım,yanlışlarım olursa affola)
Once boot sectoru okuyacaksınız. Burası diskin 0. sectörüdür. Burada Root,Fat,Data sectörlerin yerini bulacaksınız
root sectör : buradan kök klasördeki dosyaların ve klasörlerin isimleri ve hangi clusterlarda olduğunu okuyacaksınız.
fat sector : buradan ilk cluster'ini okuduğunuz datanın zincirlerinin (2-3-4-..... parçalarının) hangi clusterda olduğunu okuyacaksınız
data sector : buradan da ilgili cluster'ı bulup ihtiyacınız olan datayı okuyacaksınız.
Hazır kütüphanelerden nefret ederim ancak, yeni bir şeye el atınca hazır kütüphaneleri tercih ederim. Böylece üzerinde çalışacağınız donanımların kusuru olmadığını bileceğiniz için, çalıştıramama durumunda kusurun tamamının yazılımınızda olduğundan emin olursunuz.
saygılar...
@Mucit23
Hocam Swordfish Basic derleyicisini kullandınız mı? Protonla neredeyse aynı yapıda ve harika bir SD kütüphanesi var. Bu yıl tasarım projemde kullandım gerçekten çok hoş bir kütüphane ve pek çok fonksiyonu var tavsiye ederim. Forumda full versiyon swordfish basic var aratırsanzı çıkar. Hazır kütüphane kullanmayı bende pek sevmem ama amerikayı yeniden keşfetmeye gerek yok:D
Hocam haklısınız. Swordfish i daha önce incelemistim. Gerçektende sd kart kullanımını çok kolaylastirmislar. Yanlız şimdilik benim isime pek yaramıyor. Daha önce protonla kapsamlı bir proje yapmıştım. Aynı proje üzerinde şimdi datalogger benzeri ek bir özellik eklemek istiyorum. Programı yeniden yazmak ile uğraşmak istemiyorum. Programı swordfish e adapte etmek için harcıyacagim zamanı protonda sd kart kullanımını öğrenmek için harcamak istiyorum. Ama farkettimki daha çok eksiğim var. Fat dosya sistemi hakkında türkçe kaynağa ihtiyacım var.
http://www.barissamanci.net/AltKategori/10/her-yonuyle-fat32/
Barış Samancı Hocamız FAT ' ı tam ayrıntılı bir şekilde anlatmış, bu adresten pdf halindeki dökümanı indirebilirsiniz.
Kolay Gelsin
TXT dosyası şeklinde uygulama sana yetecekse proton için hazır kodlar var daha doğrusu kütüphane, SD_FILE_SYSTEM diye ararsan bulabilirsin , bir kaç yıl evvel kullanmıştım çok iyi çalışıyor TXT uzantılı istediğin isimde dosya açabiliyor, istediğin bilgiyi kayıt edebiliyor.
bu kütüphaneyi kullanırken dikkat edilecek olan karta yazma-silme-format gibi komutların bir işlem sırasında yapılması, not olarak eklenmişti komutların açıklandığı kısımda
Fat sistemini öğrenmek kısa sürede bitirilecek bir konu değil
Protonun resmi sitesinde sd kütüphanesi var inceleyin isterseniz.
Arkadaşlar teşekkür ederim. Barış samancı fat dosya sistemi hakkında güzel bi türkçe kaynak sunmuş. Protonun kendi sistesindende sd kütüphanesini indirdim.
Birde arkadaşlar protonun help dosyasını ve bazı kitapları incelerken bu CF kartlar gözüme çarptı. Sanırım Protonun bunada desteği var. Hatta örnek uygulama ile açıklanmış. Şimdi Bu cf kartların SD kartlara göre artsı veya eksileri nelerdir. Hafıza boyutları ne kadar oluyor.
Alıntı yapılan: KONYALIHocam Swordfish Basic derleyicisini kullandınız mı? Protonla neredeyse aynı yapıda ve harika bir SD kütüphanesi var. Bu yıl tasarım projemde kullandım gerçekten çok hoş bir kütüphane ve pek çok fonksiyonu var tavsiye ederim. Forumda full versiyon swordfish basic var aratırsanzı çıkar. Hazır kütüphane kullanmayı bende pek sevmem ama amerikayı yeniden keşfetmeye gerek yok :D
Alıntı yapılan: pcbbir kaç yıl evvel kullanmıştım çok iyi çalışıyor TXT uzantılı istediğin isimde dosya açabiliyor, istediğin bilgiyi kayıt edebiliyor.
Merhaba arkdaşalar; çalışan bir örneğinizi paylaşır mısınız? SD kartlarla yeni uğraşmaya başladım ve dün ASM ' de kartı initalize bile edemedim. Çalışan kodu sırf donanımımdan emin olmak için istiyorum. Çalışan basit bir örnek verebilirmisiniz?
hernekadar proton değilsede işe yarar...
http://www.ktemo.org/index.php?option=com_docman&task=doc_view&gid=96&Itemid=137
yapınca tecrübelerini paylaş...
Hic kullanmadim ama protonun bu is icin library dosyasi var diye hatirliyorum
Arkadaşlar Belki daha önce görmüşsünüzdür. Protonun Sd kart kütüphanesi hakkında bazı bilgiler buldum.
Burada bazı açıklamalar ve kütüphane dosyalarını vermişler
http://wiki.picbasic.org/index.php?n=LibraryManager.SDFileSystem
Linkte örnek bir programda vermişler.
Dün akşam çok uğraştım ama Sd kütüphanesini nasıl benim pc deki proton kütüphanesine ekleyeceğimi bulamadım. Bu konuda bana yardımcı olursanız sevinirim.
önce sd_file_system_library dosyasındaki programı çalıştırıp, START INSTALLATION tıklayarak kuruyorsun sonra proton da
library manager ı aktif hale getiriyorsun. aktif olunca yeşile dönüyordu ikon birde windows görev çubuğunda library manager aktif olduğunu gösteren bir kutucuk çıkıyordu diyebilirim.
View/Plugin/library manager dan ulaşabilirsin.
programda Include "SD_MMC_Read_File_Lib.pbp" ekli olmalı. ben eski programa baktığımda başka dosyalarda gördüm ama neden farklı isimlerde kullandığımı hatırlayamadım.
dosya açma - yazma - silme - format gibi fonksiyonlar için bir sırayı takip etmek gerekliydi diye hatırlıyorum, örneğin MSDOS programında eskiden kullanırken C:\ altındaki bir A dosyasını D:\ altındayken silemiyorduk C ye geçmek gerekiyordu , bunun gibi bir sırası vardı. sd_file help pdf dosyasında ayrıntılı yazıyor.
SD_FILE_SYSTEM ilk kuranlar için can sıkıcı, çalıştırılamayan bir program olarak görülür çok uğraşmıştım. lisans olmayınca cevapta vermiyor yasal sitedekiler.
3.5.2.5 de library manager ı çalıştıramadığımdan detaylı yardımcı olamıyorum.
Protonun verdiği örnek kodu derlemeye çalışıyorum.
Bendeki Compiler Versiyon 3.4.0.8
Library manageri tarif ettiğiniz yerde bulamıyorum. Protonun Sd kütüphanesi sadece belirli versiyonlardamı çalışıyor?
Ayrıca Protonun Library dosyası içerisindeki SD_File_System.pbp dosyasını protona tanıttım. Derlediğimde resimdeki gibi hatalar alıyorum.
(http://s4.postimg.cc/7jb4bl5w/Ads_z.jpg) (http://postimg.cc/image/7jb4bl5w/)
Derleyici yazılan programda hata vermiyor. SD_File_System.pbp dosyasında bazı yerlerde hata veriyor.
Kodlar ;
Device = 18F4550
Xtal = 20
'-----------------------------------------------------------
All_Digital = TRUE
'-----------------------------------------------------------
Hserial_Baud = 115200 'Setup RS232 port
Hserial_RCSTA = %10010000
Hserial_TXSTA = %00100100
'-----------------------------------------------------------
Dim Response As Byte
Dim SD_IO As Byte
'-----------------------------------------------------------
Symbol SD_CS = PORTD.2 'SPI CS to SD CS (SD pin 1)
Symbol SD_DI = PORTD.5 'SPI DO to SD DI (SD Pin 2)
Symbol SD_CLK = PORTD.3 'SPI CLK to SD CLK (SD Pin 5)
Symbol SD_DO = PORTD.4 'SPI DI to SD DO (SD Pin 7)
'-----------------------------------------------------------
Include "SD_File_System.pbp" 'Include managed library file
'-----------------------------------------------------------
GoTo Over_Sub 'Jump over the subroutines
'-----------------------------------------------------------
Over_Sub:
DelayMS 200
'-----------------------------------------------------------
Main_Prog:
HSerOut ["INSERT SD OR MMC",13]
Repeat
Response = SD_Init_FS
Until Response = 0
HSerOut ["OPENING FILE",13]
SD_File_Name = "TEST001" 'File Name, upper case only!
SD_File_Ext = "TXT" 'File Ext, upper case only!
Response = SD_Open_File
If Response = 1 Then
HSerOut ["FILE NOT FOUND",13]
Stop
EndIf
HSerOut ["FILE OPEN",13]
While SD_EOF < 1
Response = SD_Read_Byte_From_File
HSerOut [Response]
Wend
'-----------------------------------------------------------
Finish:
HSerOut [13]
HSerOut ["FINISHED",13]
Stop
Ayrıca Nedense protonun Help Menüsünde SD kart ile ilgili hiçbir içeriğe ulaşamıyorum. SD kart kütüphanesini yüklediğim zaman Help dosyasınıda yüklemesi gerekmiyormu. SD_File_System programını çalıştırdığım zaman PDS>Library klasörünün içerisinede Sd kart help menüsü görünüyor.
aşağıdaki linkten library developer ve menager ı kur
http://wiki.picbasic.org/index.php?n=LibraryManager.Plugin (http://wiki.picbasic.org/index.php?n=LibraryManager.Plugin)
eklediğim resimde kısmen anlatmaya çalıştım.
(http://b1109.hizliresim.com/11/9/30/14381.jpg) (http://goo.gl/mc9cY)
Merhabalar,elimde dvd den sökülme donanımı üstünde bir sd kart yuvası ve dış dünya ile bağlantısını sağlayan soket + kablosu var.
İşlerin yoğunluğundan ben ilgilenemiyorum,protonda denemeler yapıp çalışmaları burda paylaşacak bir arkadaşa hediye etmek istiyorum,hoşçakalın.
[IMG]http://www.upload.gen.tr/uploads7/icx5c0p7/thumb_sd_cart.jpg[/img] (http://www.upload.gen.tr/resim.php/www/icx5c0p7/sd_cart.jpg.html)
Alıntı yapılan: pcb - 30 Eylül 2011, 21:30:12
aşağıdaki linkten library developer ve menager ı kur
http://wiki.picbasic.org/index.php?n=LibraryManager.Plugin (http://wiki.picbasic.org/index.php?n=LibraryManager.Plugin)
eklediğim resimde kısmen anlatmaya çalıştım.
(http://b1109.hizliresim.com/11/9/30/14381.jpg) (http://goo.gl/mc9cY)
Hocam Size nekadar teşekkür etsem azdır.Sayenizde çözdüm işi.:)
İlk Başta bazı problemlerle karşılaştım. Pre Coımpiler'ı Nasıl aktif edeceğimi bulamadım. Pre compiler aktif olmayınca derleme yapmıyor. Library Manager'ı biraz kurcalayınca anladım. Sonra library dosyasını programa dahil edip derleyince sorun çözüldü. Protonun sitesindeki deneme programını derledim.
(http://s4.postimg.cc/1ahz4b36s/Ads_z.jpg) (http://postimg.cc/image/1ahz4b36s/)
İşte kanıtı:D
Şimdi deney setim yanımda yok olsaydı denerdim. Üzerinde SD kart yuvası vardı.
Alıntı yapılan: frederic - 02 Ekim 2011, 15:52:19
Merhabalar,elimde dvd den sökülme donanımı üstünde bir sd kart yuvası ve dış dünya ile bağlantısını sağlayan soket + kablosu var.
İşlerin yoğunluğundan ben ilgilenemiyorum,protonda denemeler yapıp çalışmaları burda paylaşacak bir arkadaşa hediye etmek istiyorum,hoşçakalın.
[IMG]http://www.upload.gen.tr/uploads7/icx5c0p7/thumb_sd_cart.jpg[/img] (http://www.upload.gen.tr/resim.php/www/icx5c0p7/sd_cart.jpg.html)
Hocam Üzerindene tür bir donanım var.?
arkadaşlar hazır kütüphane kullanmadan , fet 16 veya 32 formatı kullanmadan sadece sd kart cmd komutları ile blok kayıt ve okuma yapabilen var mı ? Herhangi bir programlama dili olsa da olur .
Saygılarımla .
Üzerinde gerekli direnç vb. elemanlar dizili durumda,soketlede spi ve besleme ucları dışarı çıkıyor.
Alıntı yapılan: egokdua - 03 Ekim 2011, 16:28:14
arkadaşlar hazır kütüphane kullanmadan , fet 16 veya 32 formatı kullanmadan sadece sd kart cmd komutları ile blok kayıt ve okuma yapabilen var mı ? Herhangi bir programlama dili olsa da olur .
Saygılarımla .
Ben yapabiliyorum, sonunda becerdim. :D Kendi yazdığım kütüphanelerle hem ASM ' de, hem de CCS C de, SD kartı EEPROM gibi kullanabiliyorum.
sn Hasan Arkadaş .Sen bu işi çözmüşsün . Benim sorunum şu cmd 24 komudu ile sd karta yazabiliyorum fakat başka bloklara kayıt yapamıyorum , sen nasıl yaptın üstat ?
Sn arkadaşım; Picproje e-dergi 2 ' deki yazı ile bu işi ben de yeni çözdüm. O yazıyı hazırlayan
arslan74 hocamıza çok teşekkür ediyorum. C biliyorsan aşağıdaki linke de bir bak, aynı zamanda karşılaştığım bir sorunu da oradan çözdüm.
http://www.microchipc.com/sourcecode/PIC_CCS_C_MMC_card.zip
Alıntı Yapcmd 24 komudu ile sd karta yazabiliyorum fakat başka bloklara kayıt yapamıyorum
Hocam siz hangi bloğa yazma işlemi yaptınız? ve yazdığınızı nasıl anladınız? Hex Editör ile mi yoksa karttan gelen cevaba göre mi? Blok bilgisini nasıl veriyorsunuz? İsterseniz kodunuzu verin bir inceleyeyim.
Program bascom da fakat protona çok yakın . Sadece yazma bölümü :
Sub Mwrite(byval Bout As Byte , Byval Addr As Long )
Cmd24: ' sd blok tek yazma yazma kodu
Set Cs
Dat = &HFF
Shiftout Mosi , Clk , Dat , Msbl
Shiftin Miso , Clk , Resp , Msbl
Reset Cs
Dat = &H58
Shiftout Mosi , Clk , Dat , Msbl
Shiftout Mosi , Clk , Addr , Msbl
Dat = &HFF
Shiftout Mosi , Clk , Dat , Msbl
Shiftout Mosi , Clk , Dat , Msbl
Shiftin Miso , Clk , Resp , Msbl
While Resp <> 0
Shiftin Miso , Clk , Resp , Msbl
Wend
Lcd "C24:" ; Hex(resp)
Dat = &HFE
Shiftout Mosi , Clk , Dat , Msbl
Waitms 30
For I = 1 To 512
Shiftout Mosi , Clk , Bout , Msbl
Next I
sandisk sd kart pdf sini okudum yazma için cmd 24 komudu istiyor . Bunu spı da sd karta gönderdiğimde onay kodu alıyorum ve seri olarak 512 bayt bloğu yazıyorum . Fakat başka blok a yazamıyorum , yani sd karttın tamamına yazamıyorum . yazabildiğim ilk 512 bayt :( .
Hocam koddan pek bir şey anlamadım. Size kendi akış diyagramımı vereyim. Gönderilecek adresin en yüksek byte ' ına Adres4, en düşük byte ' ına Adres1 diyelim:
CS Low Yap
0x58 Gönder (CMD24)
Adres4 Gönder
Adres3 Gönder
Adres2 Gönder
Adres1 Gönder
0xFF Gönder (CRC)
0x00 Gelmesini Bekle
0xFF Gönder (Start Byte ' ına Hazırlanması İçin)
0xFF Gönder (Start Byte ' ına Hazırlanması İçin)
0xFE Gönder (Start Byte ' ı)
512 Byte ' lık Bilgiyi Yaz
0xFF Gönder (CRC)
0xFF Gönder (CRC)
10000 Tane 0xFF Gönder (Yazma İşleminin Tamamlanması İçin; E-Dergideki yazıda 10000 yazma süresi kadar beklenmesi gerektiği yazıyordu, ben de o kadar beklettim.)
CS High Yap
0xFF Gönder (Diğer Komutlara Hazırlamak İçin)
gönderdiğiniz akış blogunu inceledim 32 bit adresi 8 bit lik partiler halinde sd karta gönderiyorum . sonuç aynı . Evet sd karta yazıyor ama aynı blok içine yazıyor. Belkide bunu ısıs te denediğim için bu sonucu alıyorum . Şöyle anlatayım . Bu düzeneği ısıs de yaptım ve orda bulunan mmc konpanenti kullandım . icine boş bir imaj dosyası atıyorum , yukarıda verdiğiniz gibi cmd 24 ü gönderip 8 bit x 4 ü gönderiyorum ve yazma gerçekleşiyor . fakat 32 bit adresi değiştirip başka bir adrese yazmak istediğimde gene aynı yere yazıyor . Bunu şuradan da anlayabiliyorum mmc kart içine attığım dosyayı notpad da açıp bakıyorum . Aslında bunu ısıs de denediğim için bu sonuç oluyor olabilir belkide .
Saygılarımla .
Arkadaşlar Aşağıdaki Programı Deney Setinde Denedim.
Device = 18F452
Xtal = 20
Config_Start
OSC = HS ; HS
PWRT = On ; Enabled
BOR = On ; Enabled
WDT = OFF ; Disabled
CCP2MUX = OFF ; Disable (RB3)
STVR = OFF ; Disabled
LVP = OFF ; Disabled
Debug = OFF ; Disabled
Config_End
'-----------------------------------------------------------
All_Digital = TRUE
'-----------------------------------------------------------
Hserial_Baud = 115200 'Setup RS232 port
Hserial_RCSTA = %10010000
Hserial_TXSTA = %00100100
'-----------------------------------------------------------
Dim Response As Byte
Dim SD_IO As Byte
'-----------------------------------------------------------
Symbol SD_CS = PORTE.0 'SPI CS to SD CS (SD pin 1)
Symbol SD_DI = PORTC.5 'SPI DO to SD DI (SD Pin 2)
Symbol SD_CLK = PORTC.3 'SPI CLK to SD CLK (SD Pin 5)
Symbol SD_DO = PORTC.4 'SPI DI to SD DO (SD Pin 7)
'-----------------------------------------------------------
Include "SD_MMC_Deneme1_Lib.pbp"
'-----------------------------------------------------------
GoTo Over_Sub 'Jump over the subroutines
'-----------------------------------------------------------
Over_Sub:
DelayMS 200
'-----------------------------------------------------------
Main_Prog:
HSerOut ["INSERT SD OR MMC",13]
Repeat
Response = SD_Init_FS
Until Response = 0
'-----------------------------------------------------------
Open_New_File:
SD_File_Name = "TESTFILE" 'File Name, upper case only!
SD_File_Ext = "TXT" 'File Ext, upper case only!
Response = SD_Check_For_File 'Check if file already exists
If Response = 0 Then
HSerOut ["FILE EXISTS - STOPPING",13]
Stop
Else
HSerOut ["OPENING FILE",13]
SD_New_File 'Open new file
EndIf
'-----------------------------------------------------------
Write_To_File:
HSerOut ["WRITING TO FILE",13]
SD_IO_String = "SD Kart Deneme Programıdır"
SD_Write_String_To_File 'Write SD_IO_String to file
SD_Write_Byte_To_File 13
SD_Write_Byte_To_File 10
'-----------------------------------------------------------
Close_File:
SD_Close_File 'Close file
HSerOut ["FILE CLOSED",13]
Stop
Program çok iyi çalışıyor. Şüpheniz olmasın. :)
Ben Birkaç Test yaptım.
İlk başta Dosya adını değiştirdim. "TESTFILE" yerine "Deneme1" yaptım.
Sonra SD kartı bilgisayara takıp baktığımda Deneme1 adında Bir TXT dosyası görüyorum. Dosyayı açtığımda "Dosya bulunamıyor Yeni Bir dosya açmak istermisiniz" diye bir ibareyle karşılaşıyorum. Acaba Dosya adındaki önemli kriterler nelerdir.
Daha öğrenmek istediğim çok şey var. Örneğin Dosya içerisinde Bilgisayardaki gibi rahat nasıl hareket edebilirim. (alt satıra geç, üst sarıta geç, Metin sonuna git vs..)
mucit ütad ben proton ile uğraşmaya yeni başladım . sd lib ( sd kütüphane dosyasını nereden buluyoruz ?
daha önce de söylemiştim, dosya açma , yazma , silme gibi fonksiyonların bir işlem sırası var bunları yapmadan dosya açarsın belki ama bilgisayarda hata verir.
Aşağıda ki verdiğim programda ki dosya açma sırasına göre işlem yap.
Repeat
Response = SD_Init_FS_MSSP SD_SPI_FOSC_04
Until Response = 0
SD_File_Name = "OSMAN"
SD_File_Ext = "TXT"
Print At 1,0, "DOSYA ACILIYOR"
Print At 2,0, "OSMAN.TXT"
Response = SD_New_File
If Response > 0 Then
Print At 2,0, "YENI DOSYA ACILMIYOR,HATA!"
GoTo MMC_PROGRAM
Else
Print At 3,0, "DOSYA ACILDI"
SD_Save_File
EndIf
Dosya kaydet - kapat da hatalı , dosyayı açsa bile kayıt ettiği rakamlar problemli olabilir, help pdf yi iyi incele
üstat ok :) . sen Çok ilerİdesin :) . Ben sizin başta anlattığınız library meneger ile yapılan kütüphane ekleme olayında takıldı . Yani sd kütüphaneyi ekleyip derlemeyi yapmaya çalışıyorum , bugün yarın olur heralde :) . Fakat sd kütüphane rahat bir şekilde kullanılamıyor veya daha beceremedim .Saygılarımla .
library manager i açıyorum derlediğimde aynı yukarıdaki gibi hatalar veriyor , pre_ conpailer i on yapıyorum busefer başka bir hata veriyor .
ustatlar koyay gelsin . Library Maneger ile biraz uğraşınca sorun çözüldü ok :) forumda bilgi paylaşan herkezden Allah razı oldun :) .
Arkadaşlar . :)
Sd kart olayını ps\2 klavye ile birleştirmek istiyorum , ps\2 klavyeyi protona tanıtabilmek ile ilgili pir proje yapan veya bilgisi olan var mı ?
Saygılarımla ,
SD kart çalışmamı kendi kullandığım şekli ile anlatmaya çalışayım.
-Aşağıdaki kod SD kart kütüphanesidir.
-Bu kodu "2550proton_Lib.pbp" olarak bir dosyaya kaydettim.
-Programımın fuse ayarlarından sonra (Include "2550proton_Lib.pbp") programa dahil ettim.
-Proton ide" yi portable yapmıştım. Proton'a kütüphane yüklemesiyle uğraşmadan
bu dosyayı Proton ile yazdığım programın klasörüne kopyaladım. Ve normal derleme ile hiç sorun yaşamadan derledim.
- Muhakkak işlem sıralarını doğru yapmanız gerekli.
- İnit, Dosya Aç, Kapat vs.
- Sd kartı fat 16, yada fat olarak PC'de formatladım.
- Program içinde SD kartını instal için "SD_Init_FS" komutunu kullandım.
- Bir dosyaya kayit işlemi yapıldıktan sonra, işlem sonunda o dosyayı muhakkak kapatmanız lazım. Yoksa SD kartı tekrar formatlamak zorunda kalırısınız.
Not:Pic'in hangi bacaklarının kullanıldığı "2550proton_Lib.pbp" içerisinde symbol bölümünde tanımlanmıştır. Bu tanımlama muhakkak Pic'inizin donasımsal pinleri olmalıdır.
SD kart beslemesi bir regülatör ile 3.3Volt olarak ayarlanmalıdır.
Arama motoru ile görselde "pic18f4520 sd kard" yazıp aratırsanız pin direnç düzeneğinide görebilirsiniz.
Ben 18f4520 kullandım
Device 18F4520
Xtal 20
Include "2550proton_Lib.pbp"
Dim Recal As Byte
Recal=SD_Init_FS ' Eğer SD kart hazır ise 1 döndürür.
delayms 2000
Ana:
if Recal=1 then (??????????)' SD komutları
Goto Ana
End.
SD kart kütüphanesi.
Bu Satırdan Sonrasını olduğu gibi kopyalayın
GoTo OverLibCode
'@LIB_SHARED
'
'Symbol SD_CS = PORTC.2
'Symbol SD_DI = PORTC.4
'Symbol SD_DO = PORTc.5
'Symbol SD_CLK = PORTC.3
Symbol SD_CS = PORTC.2
Symbol SD_DO = PORTC.4
Symbol SD_DI = PORTC.5
Symbol SD_CLK = PORTC.3
'
Dim SD_ByteR As Byte
Dim SD_Idx As Byte
Dim SD_Sector_Num As Dword
Dim SD_Address As Dword
Dim SD_Seek_Response_Idx As Word
Dim SD_Seek_Response_Reqd As Byte
Dim SD_Seek_Response_Return As Byte
Dim SD_Return As Byte
Dim SD_Buffer0[$100] As Byte
Dim SD_Buffer1[$100] As Byte
Dim SD_Byte0 As Byte
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_Buffer_Idx As Word
Dim SD_Byte_RW As Byte
Dim SD_RW_Option As Byte
'
Dim SD_Extended_Return As Byte
Dim SD_Extended_Return_Root_Dir As Byte
Dim SD_Data_IO As Byte
Dim SD_Buffer_Pos As Word
Dim SD_Root_Dir_File_Pos As Byte
Dim SD_Sec_Num 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
Dim SD_Bytes_Read As Dword
Dim SD_EOF As Bit
Dim SD_File_Num As Word
Dim SD_Dir_Direction As Byte
Dim SD_Extended_Return_Int As Byte
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
Dim SD_SSPSTAT As Byte
Symbol SD_SPI_IF = PIR1.3
Symbol SD_SPI_FOSC_64 = %10
Symbol SD_SPI_FOSC_16 = %01
Symbol SD_SPI_FOSC_04 = %00
'@LOCAL
'
'@CODE
SD_Write_Sub:
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
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_Seek_Response:
'
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
Else
SD_Seek_Response_Return = 0
EndIf
Return
'
SD_Write_Sector:
SD_Timeout = 0
SD_Return = 1
SD_Write_Sector_Start:
SD_Address = SD_Sector_Num << 9
'
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_Byte5 = $FE
GoSub SD_Send_Byte
'
For SD_Idx = 0 To $FF
SD_Byte5 = SD_Buffer0[SD_Idx]
GoSub SD_Send_Byte
Next SD_Idx
For SD_Idx = 0 To $FF
SD_Byte5 = SD_Buffer1[SD_Idx]
GoSub SD_Send_Byte
Next SD_Idx
'
SD_Byte5 = $FF
GoSub SD_Send_Byte
GoSub SD_Send_Byte
'
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
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:
SD_Timeout = 0
SD_Return = 1
SD_Read_Sector_Start:
SD_Address = SD_Sector_Num << 9
'
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_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
'
For SD_Idx = 0 To $FF
GoSub SD_Receive_Byte
SD_Buffer0[SD_Idx] = SD_ByteR
Next SD_Idx
For SD_Idx = 0 To $FF
GoSub SD_Receive_Byte
SD_Buffer1[SD_Idx] = SD_ByteR
Next SD_Idx
'
GoSub SD_Receive_Byte
GoSub SD_Receive_Byte
High SD_CS
SD_Byte5 = $FF
GoSub SD_Send_Byte
SD_Return = 0
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]
SD_FAT_Entry.Byte1 = SD_Buffer1[SD_Buffer_Pos + 1 - $100]
Else
SD_FAT_Entry.Byte0 = SD_Buffer0[SD_Buffer_Pos]
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_FAT1) To SD_Temp_Dword
SD_Sector_Num = SD_Sec_Num
SD_RW_Option = 1
GoSub SD_Sector_Sub
'
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
SD_FAT_Buffer_Pos = SD_Buffer_Pos
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
Else
GoTo SD_Store_Cluster_Seq
EndIf
Next SD_Buffer_Pos
SD_Store_Cluster_Seq:
SD_Cluster_Seq_Idx = 1
SD_Extended_Return = 0
Return
'
SD_Modify_File_Name:
SD_Null_F = 0
For SD_Root_Dir_File_Pos = $00 To $07
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
If SD_Null_F = 1 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
SD_Sector_Num = SD_Sec_Num
SD_RW_Option = 1
GoSub SD_Sector_Sub
'
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
If SD_Root_Dir_File[0] = $00 Or SD_Root_Dir_File[0] = $E5 Then
GoTo SD_Store_Root_Direct_Position
EndIf
Case 1
SD_Null_F = 0
For SD_Root_Dir_File_Pos = $00 To $07
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
If SD_Root_Dir_File[SD_Root_Dir_File_Pos] <> SD_File_Ext[SD_Root_Dir_File_Pos - $08] Then
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
If SD_Root_Dir_File[$0B] | %11110000 <> $FF Then
If SD_Root_Dir_File[$00] <> $00 Then
If SD_Root_Dir_File[$00] <> $E5 Then
If SD_Root_Dir_File[$0B] & %00011110 = 0 Then
Inc SD_Num_of_Root_Entries
If SD_Num_of_Root_Entries = SD_File_Num Then
For SD_Root_Dir_File_Pos = $00 To $07
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
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
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
SD_Root_Dir_Pos = SD_Buffer_Pos
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)
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
SD_FAT_Sec = SD_Cluster_Num / $100
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
SD_FAT_Buffer_Pos = SD_Cluster_Num // $100
SD_FAT_Buffer_Pos = SD_FAT_Buffer_Pos * 2
Else
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
'
GoSub SD_Find_Free_Cluster
If SD_Extended_Return = 1 Then Return
SD_Write_Sec_Num = SD_FAT1 + SD_FAT_Sec_Prev
SD_Sector_Num = SD_Write_Sec_Num
SD_RW_Option = 1
GoSub SD_Sector_Sub
'
GoSub SD_Assemble_FAT_Sector
GoSub SD_Assemble_FAT_Sector_End_Cont
GoSub SD_Write_Sector
SD_Sector_Num = SD_FAT2 + SD_FAT_Sec_Prev
GoSub SD_Write_Sector
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
'
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:
If SD_Buffer_Idx > $1FF Then
'
'
'
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
'@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_Dir, Return_Var
#endif
#if (Return_Type == Word)
BYTE_WORD SD_Extended_Return_Root_Dir, Return_Var
#endif
#if (Return_Type == Dword)
BYTE_DWORD SD_Extended_Return_Root_Dir, Return_Var
#endif
#endif
Endm
'
'@LOCAL
'
'
'@CODE
'
'
'@END
'@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
'
'
'@CODE
'
'
SD_Close_File_Sub:
'
'
'
If SD_Is_Dirty = 1 Then
Repeat
GoSub SD_Write_Sector
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_Write_Buffer_Pos = SD_Root_Dir_Pos + $1C
SD_Data_IO = SD_File_Size.Byte0
GoSub SD_Insert_Byte_Into_Buffer
Inc SD_Write_Buffer_Pos
SD_Data_IO = SD_File_Size.Byte1
GoSub SD_Insert_Byte_Into_Buffer
Inc SD_Write_Buffer_Pos
SD_Data_IO = SD_File_Size.Byte2
GoSub SD_Insert_Byte_Into_Buffer
Inc SD_Write_Buffer_Pos
SD_Data_IO = SD_File_Size.Byte3
GoSub SD_Insert_Byte_Into_Buffer
SD_Write_Buffer_Pos = SD_Root_Dir_Pos + $16
GoSub SD_Set_File_Time_Modified
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
SD_Sector_Num = SD_Write_Sec_Num
SD_RW_Option = 1
GoSub SD_Sector_Sub
'
SD_Cluster_Seq_Num_Prev = SD_Cluster_Seq_Idx
GoSub SD_Assemble_FAT_Sector
GoSub SD_Assemble_FAT_Sector_End_Close
GoSub SD_Write_Sector
SD_Sector_Num = SD_FAT2 + SD_FAT_Sec_Prev
GoSub SD_Write_Sector
EndIf
Return
'
'
SD_Set_File_Time_Create:
SD_Data_IO = SD_MSeconds + ((SD_Seconds // 2) * 100)
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)
GoSub SD_Insert_Byte_Into_Buffer
Inc SD_Write_Buffer_Pos
SD_Data_IO = (SD_Minutes >> 3) | (SD_Hours << 3)
GoSub SD_Insert_Byte_Into_Buffer
Inc SD_Write_Buffer_Pos
SD_Data_IO = SD_Day | (SD_Month << 5)
GoSub SD_Insert_Byte_Into_Buffer
Inc SD_Write_Buffer_Pos
SD_Data_IO = (SD_Month >> 3) | ((SD_Year + 20) << 1)
GoSub SD_Insert_Byte_Into_Buffer
Return
'
'
'@END
'@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_Return, Return_Var
#endif
#endif
Endm
'
'@LOCAL
'
'
'@CODE
'
'
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_Init_Sub:
Output SD_CS : Output SD_DI : Output SD_CLK : Input SD_DO
High SD_CS
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
'
DelayMS 100
Low SD_CS
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_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 = 0 Or SD_Idx = 0
If SD_Idx = 0 Then
High SD_CS
SD_Return = 1
Return
EndIf
High SD_CS
SD_Byte5 = $FF
GoSub SD_Send_Byte
SD_Buffer_Idx = 0
SD_Return = 0
Return
'
'
'@END
'@HELP
'
SD_Init_FS Macro
GoSub SD_Init_FS_Sub
#if (SD_Init_FS_RETURN != 1)
#else
#if (Return_Type != Byte)
#error "SD_Init_FS - Return variable should be a Byte variable"
#endif
#if (Return_Type == Byte)
BYTE_BYTE SD_Extended_Return, Return_Var
#endif
#endif
Endm
'
'@LOCAL
'
'
'@CODE
'
'
SD_Init_FS_Sub:
SD_Extended_Return_Int = SD_Init
If SD_Extended_Return_Int = 1 Then
SD_Extended_Return = 1
Return
EndIf
SD_Sector_Num = $00
SD_RW_Option = 1
GoSub SD_Sector_Sub
'
If SD_Buffer0[0] = $EB And SD_Buffer0[2] = $90 Then
'
SD_Boot_Record = $0000
ElseIf SD_Buffer0[0] = $E9 Then
'
SD_Boot_Record = $0000
Else
'
SD_Boot_Record = SD_Buffer1[$0C6] + 0
EndIf
SD_Sector_Num = SD_Boot_Record
SD_RW_Option = 1
GoSub SD_Sector_Sub
'
SD_Bytes_Per_Sec.Byte0 = SD_Buffer0[$0B]
SD_Bytes_Per_Sec.Byte1 = SD_Buffer0[$0C]
SD_Secs_Per_Cluster = SD_Buffer0[$0D]
SD_Reserved_Secs.Byte0 = SD_Buffer0[$0E]
SD_Reserved_Secs.Byte1 = SD_Buffer0[$0F]
SD_Num_of_FATs = SD_Buffer0[$10]
SD_Num_of_Root_Entries.Byte0 = SD_Buffer0[$11]
SD_Num_of_Root_Entries.Byte1 = SD_Buffer0[$12]
SD_Secs_Per_FAT.Byte0 = SD_Buffer0[$16]
SD_Secs_Per_FAT.Byte1 = SD_Buffer0[$17]
SD_Num_of_Secs.Byte0 = SD_Buffer0[$20]
SD_Num_of_Secs.Byte1 = SD_Buffer0[$21]
SD_Num_of_Secs.Byte2 = SD_Buffer0[$22]
SD_Num_of_Secs.Byte3 = SD_Buffer0[$23]
' Devam...
'Devamı
SD_FAT1 = SD_Boot_Record + SD_Reserved_Secs
SD_FAT2 = SD_Boot_Record + SD_Reserved_Secs + SD_Secs_Per_FAT
SD_Root_Dir = SD_Num_of_FATs * SD_Secs_Per_FAT
SD_Root_Dir = SD_Boot_Record + SD_Reserved_Secs + SD_Root_Dir
SD_Secs_in_Root = SD_Num_of_Root_Entries * 32
SD_Secs_in_Root = SD_Secs_in_Root / SD_Bytes_Per_Sec
SD_Data_Area = SD_Root_Dir + SD_Secs_in_Root
'
SD_Sector_Num = SD_Boot_Record + SD_Num_of_Secs - 1
SD_Sector_Num = SD_Sector_Num - SD_Data_Area + 1
SD_Sector_Num = SD_Sector_Num / SD_Secs_Per_Cluster
SD_Last_Cluster = SD_Sector_Num + 1
'
SD_File_Name = " "
SD_File_Ext = " "
SD_Day = 1
SD_Month = 1
SD_Year = 0
SD_MSeconds = 0
SD_Seconds = 0
SD_Minutes = 0
SD_Hours = 0
SD_File_Num = 0
SD_Extended_Return = 0
Return
'
'
'@END
'@HELP
'
SD_New_File Macro
#if(Prm_Count != 0)
#error "No parameters required for SD_New_File"
Exitm
#endif
GoSub SD_New_File_Sub
#if (SD_New_File_RETURN != 1)
#else
#if (Return_Type != Byte)
#error "SD_New_File - Return variable should be a Byte variable"
#endif
#if (Return_Type == Byte)
BYTE_BYTE SD_Extended_Return, Return_Var
#endif
#endif
Endm
'
'@LOCAL
Dim LOCALVARS[202] As Byte
'
Dim SD_Return_F As LOCALVARS#0
'
'@CODE
'
'
SD_New_File_Sub:
SD_Return_F = 0
SD_FAT_Sec = 0
SD_FAT_Buffer_Pos = 0
SD_Cluster_Seq_Num = 0
GoSub SD_Find_Free_Cluster
If SD_Extended_Return = 1 Then Return
SD_Find_Root_Dir_Entry_F = 0
GoSub SD_Find_Root_Dir_Entry
If SD_Extended_Return_Root_Dir = 1 Then
SD_Extended_Return = 1
Return
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
'
For SD_Root_Dir_File_Pos = $00 To $1F
SD_Write_Buffer_Pos = SD_Root_Dir_Pos + SD_Root_Dir_File_Pos
SD_Data_IO = 0
GoSub SD_Insert_Byte_Into_Buffer
Next SD_Root_Dir_File_Pos
GoSub SD_Modify_File_Name
For SD_Root_Dir_File_Pos = $00 To $07
SD_Write_Buffer_Pos = SD_Root_Dir_Pos + SD_Root_Dir_File_Pos
SD_Data_IO = SD_File_Name[SD_Root_Dir_File_Pos]
GoSub SD_Insert_Byte_Into_Buffer
Next SD_Root_Dir_File_Pos
For SD_Root_Dir_File_Pos = $08 To $0A
SD_Write_Buffer_Pos = SD_Root_Dir_Pos + SD_Root_Dir_File_Pos
SD_Data_IO = SD_File_Ext[SD_Root_Dir_File_Pos - $08]
GoSub SD_Insert_Byte_Into_Buffer
Next SD_Root_Dir_File_Pos
SD_Write_Buffer_Pos = SD_Root_Dir_Pos + $0B
SD_Data_IO = %00100000
GoSub SD_Insert_Byte_Into_Buffer
SD_Write_Buffer_Pos = SD_Root_Dir_Pos + $0D
GoSub SD_Set_File_Time_Create
SD_Write_Buffer_Pos = SD_Root_Dir_Pos + $1A
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
GoSub SD_Write_Sector
SD_Data_Sec = (SD_Cluster_Num - 2) * SD_Secs_Per_Cluster
SD_Data_Sec = SD_Data_Sec + SD_Data_Area
SD_Sec_in_Cluster = 1
SD_Sector_Num = SD_Data_Sec
SD_RW_Option = 0
GoSub SD_Sector_Sub
'
SD_Data_Buffer_Pos = 0
SD_File_Size = 0
SD_RW_Ptr = 0
SD_EOF = 1
SD_Return_F = 1
Return
'
'
'@END
'@HELP
'
SD_Write_Byte_To_File Macro P1
#if (Prm_Count > 1)
#error "SD_Write_Byte_to_File - Too many parameters"
#else
#if (Prm_Count < 1)
#error "SD_Write_Byte_to_File - Too few parameters"
#else
#if (Prm_1 != Byte) && (Prm_1 != Num8) && (Prm_1 != Num16) && (Prm_1 != Num32) && (Prm_1 != Word) && (Prm_1 != Dword)
#error "SD_Write_Byte_to_File - Byte(Param 1) should be a Byte, Word or DWord variable or number"
#endif
#if (Prm_1 == Byte)
BYTE_BYTE P1, SD_IO_Byte
#endif
#if (Prm_1 == Num8)
NUM_BYTE P1, SD_IO_Byte
#endif
#if (Prm_1 == Num16)
NUM_BYTE P1, SD_IO_Byte
#endif
#if (Prm_1 == Num32)
NUM_BYTE P1, SD_IO_Byte
#endif
#if (Prm_1 == Word)
BYTE_BYTE P1, SD_IO_Byte
#endif
#if (Prm_1 == Dword)
BYTE_BYTE P1, SD_IO_Byte
#endif
#if (Prm_1 == Float)
FLOAT_BYTE P1, SD_IO_Byte
#endif
GoSub SD_Write_Byte_To_File_Sub
#if (SD_Write_Byte_To_File_RETURN != 1)
#else
#if (Return_Type != Byte)
#error "SD_Write_Byte_To_File - Return variable should be a Byte variable"
#endif
#if (Return_Type == Byte)
BYTE_BYTE SD_Extended_Return, Return_Var
#endif
#endif
#endif
#endif
Endm
'
'@LOCAL
'
'
'@CODE
'
'
'
'
'
'
'@END
'@HELP
'
SD_Write_String_To_File Macro
#if(Prm_Count != 0)
#error "No parameters required for SD_Write_String_To_File"
Exitm
#endif
GoSub SD_Write_String_To_File_Sub
#if (SD_Write_String_To_File_RETURN != 1)
#else
#if (Return_Type != Byte)
#error "SD_Write_String_To_File - Return variable should be a Byte variable"
#endif
#if (Return_Type == Byte)
BYTE_BYTE SD_Extended_Return, Return_Var
#endif
#endif
Endm
'
'@LOCAL
'
'
'@CODE
'
Dim SD_IO_String_Length As LOCALVARS#0
Dim SD_IO_String_Pos As LOCALVARS#1
Dim SD_IO_String As String * 200 At LOCALVARS#2
'
SD_Write_String_To_File_Sub:
SD_IO_String_Length = Len(SD_IO_String)
SD_IO_String_Length = SD_IO_String_Length - 1
For SD_IO_String_Pos = 0 To SD_IO_String_Length
SD_IO_Byte = SD_IO_String[SD_IO_String_Pos]
GoSub SD_Write_Byte_To_File_Sub
If SD_Extended_Return = 1 Then Return
Next SD_IO_String_Pos
Return
'
'
'@END
OverLibCode:
Hocam SD karta dosya açma işini anladım. Yani bir txt uzantılı dosya açıp içerisine bişeyler yazabiliyorum. Öğrenmek istediğim asıl şeyler txt dosyasının içerisini nasıl düzenleyeceğim. Yani Dİyelim sıcaklık ölçer daha doğrusu datalogger benzeri bir cihaz yapacağım. Ben bu dosyada dosya içerisindeki düzeni nasıl sağlayacağım txt dosyası içerisinde bi exel tablosuna benzer bir yapı yapmak istiyorum.
Ayrıca birde Protonda SD kart kütüphanesini kullanarak SD kartı nasıl eeprom gibi kullanabileceğimi öğrenmek isterim. Bu konuda bi bilginiz varmı
'Bir Deneme
Device 18F4520
Xtal 20
Include "2550proton_Lib.pbp"
Dim Recal As Byte
Dim Onay As Byte
Recal=SD_Init_FS ' Eğer SD kart hazır ise 1 döndürür.
Delayms 2000
Ana:
if Recal=1 then
Recal=0
GoSub New_File
GoSub Dosya_Kaydet
GoSub FileClose_
endif
GoTo Ana
'SD MMC Blogu
New_File: ' Creating a new File
SD_File_Name = "OC_" ' Set File Name
SD_File_Ext = "TXT" ' Set File Extension
Cls
Print At 1,1, "Y=",SD_File_Name,".",SD_File_Ext
New_File2: ' Creating a new File
Onay = SD_Check_For_File 'Check if file already exists
DelayMS 10 ' give user time to read display
Cls
Print At 1,1, "Y=",SD_File_Name,".",SD_File_Ext
DelayMS 2000 ' give user time to read display
If Onay = 1 Then ' If so then
SD_New_File ' Create and open new file
Cls
Print At 1,1, "Dosya Olustu. " ' Inform User
DelayMS 2000 ' give user time to read display
Cls
EndIf
Cls
DelayMS 500
Return
Dosya_Kaydet:
SD_IO_String = "Kayit Deneme"
SD_Write_String_To_File ' Write SD_IO_String to file
SD_Write_Byte_To_File 13 ' Write Carriage return to file
SD_Write_Byte_To_File 10 ' Write Line Feed to file
DelayMS 10
Return
FileClose_:
SD_Close_File ' Close File
Cls
Print At 1,1, "Dosya Kapaniyor.." ' Inform User
DelayMS 2000 ' give user time to read display
Cls
Return
Alıntı yapılan: pcb - 30 Eylül 2011, 21:30:12
aşağıdaki linkten library developer ve menager ı kur
http://wiki.picbasic.org/index.php?n=LibraryManager.Plugin (http://wiki.picbasic.org/index.php?n=LibraryManager.Plugin)
eklediğim resimde kısmen anlatmaya çalıştım.
(http://b1109.hizliresim.com/11/9/30/14381.jpg) (http://goo.gl/mc9cY)
Şu bahsedilen link'e ulaşamıyorum.Elinde linkten indirilen dosyalar mevcut olan tekrar yükleme yapabilirmi acaba ?
6 sene belki daha önce sd karta GPS koordinatlarını kayıt yaptırıyordum, açılan txt dosyasındaki alt alta yazdırma için gönderilen konutta sanırım bir detay vardı hatırlayamadım