jueves, 23 de enero de 2014

chipKIT Lesson: SD Card

22:13

chipKIT Lesson: SD Card

January 2nd, 2013  Posted at   ChipKIT Lesson
arrow   |   No Commentsarrow
SD Card Module top
SD Card Module bottom
Sekiranya projek memerlukan simpanan data yang besar, tidak mencukupi dengan simpanan di dalam microcontroller ataupun simpanan di dalam external EEPROM, SD Card boleh digunakan. SD Card boleh interface melalui SPI dan menggunakan FAT (File Allocation Table) system.
SD Card disambungkan menggunakan empat pin iaitu MISO, MOSI, SCK dan SS. Pin-pin pada chipKIT Max32 adalah
  • MISO = 50
  • MOSI = 51
  • SCK = 52
  • SS = 53
Berikut adalah videonya
ChipKIT Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
#include <SD.h>
 
#define chipSelect 53
File myFile;
 
void setup()
{
Serial.begin(9600);
pinMode(chipSelect,OUTPUT);
if (!SD.begin(chipSelect)) Serial.println("initialization failed!"); //Initializes the SD library and card.
else Serial.println("initialization done.");
}
 
void loop()
{
int data;
Serial.print("1:Check file exist ");
Serial.print("2:Create file ");
Serial.print("3:Remove file ");
Serial.print("4:Write file ");
Serial.println("5:Read file");
while(!Serial.available()) continue;
data=Serial.read();
if (data=='1')
{
if (SD.exists("example.txt")) Serial.println("example.txt exists."); //Tests whether a file or directory exists on the SD card.
else Serial.println("example.txt doesn't exist.");
}
if (data=='2')
{
Serial.println("creating example.txt");
myFile = SD.open("example.txt",FILE_WRITE); //Opens a file on the SD card.
myFile.close(); //Close the file
}
if (data=='3')
{
Serial.println("removing example.txt");
SD.remove("example.txt"); // delete file:
}
if (data=='4')
{
myFile = SD.open("example.txt",FILE_WRITE); //Opens a file on the SD card.
if (myFile)
{
Serial.println("writing to example.txt");
myFile.println("shahrulnizam.com");
myFile.close(); //Close the file
}
else Serial.println("error opening example.txt");
}
if (data=='5')
{
myFile = SD.open("example.txt"); //Opens a file on the SD card.
if (myFile)
{
Serial.println("reading from example.txt:");
while (myFile.available()) Serial.write(myFile.read());
myFile.close(); //Close the file
}
else Serial.println("error opening example.txt");
}
Serial.println();
}
view raw chipKIT SD Card hosted with ❤ by GitHub
Nuffnang Ads

Dah baca, tinggalkan komen anda disini






Written by

We are Creative Blogger Theme Wavers which provides user friendly, effective and easy to use themes. Each support has free and providing HD support screen casting.

0 comentarios:

Publicar un comentario

 

© 2013 Antikythera Electronica y domotica. All rights resevered. Designed by Templateism

Back To Top