1

Dependencies:   SDFileSystem mbed

Committer:
yu10078999
Date:
Sat Sep 10 02:46:15 2016 +0000
Revision:
0:4e67ce020359
Child:
1:1c3f6ffb47c6
0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yu10078999 0:4e67ce020359 1 #include "mbed.h"
yu10078999 0:4e67ce020359 2 #include "SDFileSystem.h"
yu10078999 0:4e67ce020359 3
yu10078999 0:4e67ce020359 4 Serial pc(USBTX, USBRX);
yu10078999 0:4e67ce020359 5 SDFileSystem sd(PC_3, PC_2, PB_10, PE_2, "sd"); // MOSI, MISO, SCK, CS
yu10078999 0:4e67ce020359 6
yu10078999 0:4e67ce020359 7 FILE *fp;
yu10078999 0:4e67ce020359 8 char data[100];
yu10078999 0:4e67ce020359 9
yu10078999 0:4e67ce020359 10 int main() {
yu10078999 0:4e67ce020359 11 wait(1);
yu10078999 0:4e67ce020359 12 pc.printf("Initializing\r\n");
yu10078999 0:4e67ce020359 13
yu10078999 0:4e67ce020359 14 fp = fopen("/sd/hello.txt", "r"); //檔名可以任意改
yu10078999 0:4e67ce020359 15
yu10078999 0:4e67ce020359 16 if (fp == NULL) {
yu10078999 0:4e67ce020359 17 pc.printf("Fail\r\n");
yu10078999 0:4e67ce020359 18 }
yu10078999 0:4e67ce020359 19
yu10078999 0:4e67ce020359 20 fread( data, sizeof(data), 1, fp );
yu10078999 0:4e67ce020359 21 fclose(fp);
yu10078999 0:4e67ce020359 22 pc.printf("File successfully read!\r\n");
yu10078999 0:4e67ce020359 23 pc.printf(" Your data:\n%s\n",data);
yu10078999 0:4e67ce020359 24 }