sd kart yazma ve okuma
Dependencies: mbed sd_kart_yazma_okma
main.cpp@3:103fa9f462eb, 2019-10-21 (annotated)
- Committer:
- marvas
- Date:
- Mon Oct 21 08:02:31 2019 +0000
- Revision:
- 3:103fa9f462eb
- Parent:
- 2:f6685eb40c9d
SD KART
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 0:bdbd3d6fc5d5 | 1 | #include "mbed.h" |
mbed_official | 0:bdbd3d6fc5d5 | 2 | #include "SDFileSystem.h" |
marvas | 3:103fa9f462eb | 3 | SDFileSystem sd(D11, D12, D13, D10, "sd"); // mosi, miso, sclk, cs(scl) |
marvas | 3:103fa9f462eb | 4 | unsigned char c; |
marvas | 2:f6685eb40c9d | 5 | |
marvas | 3:103fa9f462eb | 6 | int main() |
marvas | 3:103fa9f462eb | 7 | { |
marvas | 2:f6685eb40c9d | 8 | mkdir("/sd", 0777); |
marvas | 2:f6685eb40c9d | 9 | //mkdir klasör oluşturur. |
marvas | 2:f6685eb40c9d | 10 | //0777 dosyaya veri yazıp okumayı etkinleştirir. |
marvas | 3:103fa9f462eb | 11 | while(1) { |
marvas | 3:103fa9f462eb | 12 | FILE *fp = fopen("/sd/veritabani.txt", "a"); |
marvas | 3:103fa9f462eb | 13 | /* a - dosyanın içerisine var olan verinin yanına ekleme yapar |
marvas | 3:103fa9f462eb | 14 | r - Dosyadan okuma yapar |
marvas | 3:103fa9f462eb | 15 | w - Dosyadan verileri siler yeni veriyi ekler. |
marvas | 3:103fa9f462eb | 16 | */ |
marvas | 3:103fa9f462eb | 17 | if(fp == NULL) { |
marvas | 3:103fa9f462eb | 18 | error("Yazma icin dosya acilamadi \n"); |
marvas | 3:103fa9f462eb | 19 | printf("Yazma icin dosya acilamadi \n"); |
marvas | 3:103fa9f462eb | 20 | } |
marvas | 3:103fa9f462eb | 21 | |
marvas | 3:103fa9f462eb | 22 | else { |
marvas | 3:103fa9f462eb | 23 | //Sd karta yazar |
marvas | 3:103fa9f462eb | 24 | fprintf(fp, "mehmet akif arvas"); |
marvas | 3:103fa9f462eb | 25 | fclose(fp); //Dosya kapat |
marvas | 3:103fa9f462eb | 26 | // |
marvas | 3:103fa9f462eb | 27 | FILE *fpr = fopen("/sd/veritabani.txt", "r"); |
marvas | 3:103fa9f462eb | 28 | //Okunacak dosya seçildi |
marvas | 3:103fa9f462eb | 29 | |
marvas | 3:103fa9f462eb | 30 | //file end of. Okuma işlemi bitene kadar devam et. |
marvas | 3:103fa9f462eb | 31 | //Dosya sonuna kadar okumaya devam et. |
marvas | 3:103fa9f462eb | 32 | while (!feof(fpr)) { |
marvas | 3:103fa9f462eb | 33 | c=fgetc(fpr); |
marvas | 3:103fa9f462eb | 34 | printf("%c",c); |
marvas | 3:103fa9f462eb | 35 | } |
marvas | 3:103fa9f462eb | 36 | fclose(fpr); |
marvas | 3:103fa9f462eb | 37 | } |
mbed_official | 0:bdbd3d6fc5d5 | 38 | } |
marvas | 3:103fa9f462eb | 39 | } |