123
Dependencies: SDFileSystem mbed
main.cpp
00001 // SDFileSystem---1. https://developer.mbed.org/users/mbed_official/code/SDFileSystem/ 00002 // 2. https://developer.mbed.org/users/simon/code/SDCardTest/ 00003 // VCC:3.3v 00004 #include "mbed.h" 00005 #include "SDFileSystem.h" 00006 00007 //SDFileSystem sd(PA_7, PA_6, PA_5, PB_6, "sd"); // mosi, miso, sclk, cs 00008 //SPI spi(SPI_MOSI, SPI_MISO, SPI_SCK); 00009 //SPI_MOSI = PA_7, SPI_MISO = PA_6, SPI_SCK = PA_5, SPI_CS = PB_6, 00010 SDFileSystem sd( D4, D5, D3, D6, "sd"); // mosi, miso, sclk, cs 00011 00012 int main() 00013 { 00014 printf("Hello World!\n"); 00015 00016 mkdir("/sd/Amber", 0777); //SD裡面的資料夾叫Amber,在此做宣告 00017 FILE *fp = fopen("/sd/Amber/Amber77.txt", "w"); //將檔案存進SD的資料夾Amber裡面,並取名為Amber77.txt 00018 00019 /*mkdir("/sd/mydir", 0777); //SD裡面的資料夾叫mydir,在此做宣告 00020 FILE *fp = fopen("/sd/mydir/Amber77.txt", "w");*/ //將檔案存進SD的資料夾mydir裡面,並取名為sdtest.txt 00021 00022 /* 00023 mkdir("/sd/Amber20170222", 0777); //SD裡面的資料夾叫Amber77,在此做宣告 00024 FILE *fp = fopen("/sd/Amber20170222/AngVel_PWM20170222a.csv", "a"); 00025 //將檔案存進SD的資料夾Amber77裡面,並取名為PWM_AngVel_PWM.xls/.xlsx/.csv 00026 fprintf(fp,"RunTime,Now_angularVelocity,control_PWM_Value\n"); 00027 00028 if(fp == NULL) 00029 { 00030 error("Could not open file for write\n"); 00031 } 00032 fprintf(fp,"%.3f,%.3f,%.3f\n", RunTime,Now_angularVelocity,control_PWM_Value); 00033 00034 if(!mybutton) 00035 { 00036 StopRun.write(1); 00037 CW_CCW.write(1); // clockwise:0 counterclockwise:1 00038 PWM.write(0); 00039 break; 00040 } 00041 } 00042 fclose(fp); 00043 00044 */ 00045 00046 00047 if(fp == NULL) 00048 { 00049 error("Could not open file for write\n"); 00050 } 00051 fprintf(fp, "Go to the file "); //檔案如sdtest.txt裡面的資料內容 00052 fclose(fp); 00053 00054 printf("Goodbye World!\n"); 00055 }
Generated on Thu Jul 28 2022 02:21:12 by 1.7.2