sd kart yazma ve okuma

Dependencies:   mbed sd_kart_yazma_okma

Committer:
marvas
Date:
Wed May 15 10:50:17 2019 +0000
Revision:
2:f6685eb40c9d
Parent:
0:bdbd3d6fc5d5
Child:
3:103fa9f462eb
sd kart yazma ve okuma

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:bdbd3d6fc5d5 1 #include "mbed.h"
mbed_official 0:bdbd3d6fc5d5 2 #include "SDFileSystem.h"
marvas 2:f6685eb40c9d 3
marvas 2:f6685eb40c9d 4 SDFileSystem sd(D11, D12, D8, D10, "sd"); // mosi, miso, sclk, cs(scl)
marvas 2:f6685eb40c9d 5 Serial pc(USBTX,USBRX);
marvas 2:f6685eb40c9d 6 unsigned char c;
marvas 2:f6685eb40c9d 7
mbed_official 0:bdbd3d6fc5d5 8 int main() {
marvas 2:f6685eb40c9d 9 pc.printf("Karta yazma ve okuma islem basladi \n");
mbed_official 0:bdbd3d6fc5d5 10
marvas 2:f6685eb40c9d 11 mkdir("/sd", 0777);
marvas 2:f6685eb40c9d 12 //mkdir klasör oluşturur.
marvas 2:f6685eb40c9d 13 //0777 dosyaya veri yazıp okumayı etkinleştirir.
mbed_official 0:bdbd3d6fc5d5 14
marvas 2:f6685eb40c9d 15 FILE *fp = fopen("/sd/ornek.txt", "a");
mbed_official 0:bdbd3d6fc5d5 16 if(fp == NULL) {
marvas 2:f6685eb40c9d 17 error("Yazma icin dosya acilamadi \n");
mbed_official 0:bdbd3d6fc5d5 18 }
marvas 2:f6685eb40c9d 19 else
marvas 2:f6685eb40c9d 20 {
marvas 2:f6685eb40c9d 21 fprintf(fp, "Merhaba. Bu yazi Sd karta yazilacak!");
marvas 2:f6685eb40c9d 22 fclose(fp); //Dosya kapat
mbed_official 0:bdbd3d6fc5d5 23
marvas 2:f6685eb40c9d 24 pc.printf("Yazma islemi bitti! \n");
marvas 2:f6685eb40c9d 25
marvas 2:f6685eb40c9d 26 pc.printf("Okuma islemi basladi! \n");
marvas 2:f6685eb40c9d 27 FILE *fpr = fopen("/sd/ornek.txt", "r");
marvas 2:f6685eb40c9d 28 //Okunacak dosya seçildi
marvas 2:f6685eb40c9d 29
marvas 2:f6685eb40c9d 30 //file end of. Okuma işlemi bitene kadar devam et.
marvas 2:f6685eb40c9d 31 //Dosya sonuna kadar okumaya devam et.
marvas 2:f6685eb40c9d 32 while (!feof(fpr)){
marvas 2:f6685eb40c9d 33 c=fgetc(fpr);
marvas 2:f6685eb40c9d 34 printf("%c",c);
marvas 2:f6685eb40c9d 35 }
marvas 2:f6685eb40c9d 36 fclose(fpr);
marvas 2:f6685eb40c9d 37 }
mbed_official 0:bdbd3d6fc5d5 38 }