while(1)
{
//USB stack process function
USBTasks();
//if thumbdrive is plugged in
if(USBHostMSDSCSIMediaDetect())
{LATDbits.LATD10 = 1;
deviceAttached = TRUE;
//now a device is attached
//See if the device is attached and in the right format
if(FSInit())
{
//Opening a file in mode "w" will create the file if it doesn't
// exist. If the file does exist it will delete the old file
// and create a new one that is blank.
myFile = FSfopen("test.txt","w");
//Write some data to the new file.
FSfwrite("This is a test.",1,15,myFile);
//Always make sure to close the file so that the data gets
// written to the drive.
FSfclose(myFile);
//Just sit here until the device is removed.
while(deviceAttached == TRUE)
{
USBTasks();
}
}
}
}
return 0;
}