![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
SDFileSystem
Dependencies: mbed PowerControl SDFileSystem
Fork of SDFilesystem by
main.cpp@0:8d235efb1150, 2016-12-09 (annotated)
- Committer:
- tomoya123
- Date:
- Fri Dec 09 05:02:42 2016 +0000
- Revision:
- 0:8d235efb1150
- Child:
- 1:47daa1a922c4
SDcard
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tomoya123 | 0:8d235efb1150 | 1 | #include "mbed.h" |
tomoya123 | 0:8d235efb1150 | 2 | #include "SDFileSystem.h" |
tomoya123 | 0:8d235efb1150 | 3 | Serial pc(USBTX,USBRX); |
tomoya123 | 0:8d235efb1150 | 4 | SDFileSystem sd(p11, p12, p13, p15, "sd"); |
tomoya123 | 0:8d235efb1150 | 5 | |
tomoya123 | 0:8d235efb1150 | 6 | int main() { |
tomoya123 | 0:8d235efb1150 | 7 | pc.baud(9600);//ボーレートの設定 |
tomoya123 | 0:8d235efb1150 | 8 | pc.printf("Hello world!\r\n"); |
tomoya123 | 0:8d235efb1150 | 9 | char str[100];//文字列を定義 |
tomoya123 | 0:8d235efb1150 | 10 | mkdir("/sd/mydir", 0777);//SDファイルへのアクセス許可 |
tomoya123 | 0:8d235efb1150 | 11 | printf("helloworld\r\n"); |
tomoya123 | 0:8d235efb1150 | 12 | FILE *fp = fopen("/sd/mydir/sdtest.txt","w");//ファイルオープン |
tomoya123 | 0:8d235efb1150 | 13 | if(fp == NULL) { |
tomoya123 | 0:8d235efb1150 | 14 | error("Could not open file for write\r\n"); |
tomoya123 | 0:8d235efb1150 | 15 | } |
tomoya123 | 0:8d235efb1150 | 16 | for(int i=0;i<10;i++)fprintf(fp,"Hello my name is HEPTA!\r\n"); |
tomoya123 | 0:8d235efb1150 | 17 | fclose(fp); |
tomoya123 | 0:8d235efb1150 | 18 | fp = fopen("/sd/mydir/sdtest.txt","r"); |
tomoya123 | 0:8d235efb1150 | 19 | for(int j=0;j<10;j++){ |
tomoya123 | 0:8d235efb1150 | 20 | fgets(str,100,fp); |
tomoya123 | 0:8d235efb1150 | 21 | puts(str); |
tomoya123 | 0:8d235efb1150 | 22 | } |
tomoya123 | 0:8d235efb1150 | 23 | fclose(fp); |
tomoya123 | 0:8d235efb1150 | 24 | printf("Goodbye!!\r\n"); |
tomoya123 | 0:8d235efb1150 | 25 | } |