ajex
Member level 4
- Joined
- Nov 7, 2009
- Messages
- 70
- Helped
- 6
- Reputation
- 12
- Reaction score
- 6
- Trophy points
- 1,288
- Location
- Sri lanka
- Activity points
- 1,813
hello..
I have a problem in Microchip MDD library function. I want to open an existing file to read some byte. there is a function call "FSfopenpgm" but its only work on PIC18F divices. Then how can read an existing file to read using dsPIC30F6014A ??? please help me in this...! :lol:
I saw a example code like below. But its using "FSfopenpgm" function, because its PIC18F device..
#include “FSIO.h”
#define bfrsize 5
void main(void)
{
FSFILE *pOldFile, pNewFile;
char myData[20];
char bfr [6];
int bytesRead, bytesWritten;
char newFile[] = “newfile.txt”;
char writeArg = “w”;
// Must initialize the FAT16/FAT32 library. It also initializes SPI and other related
pins.
if( !FSInit() )
// Failed to initialize FAT16 – do something…
return 1; // Card not present or wrong format
// Create a new file
pNewFile = FSfopen (newFile, writeArg);
// Open an existing file to read
pOldFile = FSfopenpgm (“myfile.txt”, “r”);
if ( pOldFile == NULL )
// Either file is not present or card is not present
return 1;
// Read 10 bytes of data from the file.
bytesRead = FSfread((void*)myData, 10, 1, pOldFile);
// read bfrSize (5) items (of size 1 byte). returns items count
bytesRead = FSfread( (void *)bfr, 1, bfrSize, pOldFile );
// Write those fifteen bytes to the new file
bytesWritten = FSfwrite ((void *) myData, 10, 1, pNewFile);
bytesWritten = FSfwrite ((void *) bfr, 1, bfrSize, pNewFile);
// After processing, close the file.
FSfclose( pOldFile );
FSfclose (pNewFile);
//Delete the old file
FSremovepgm (“myfile.txt”);
}
I have a problem in Microchip MDD library function. I want to open an existing file to read some byte. there is a function call "FSfopenpgm" but its only work on PIC18F divices. Then how can read an existing file to read using dsPIC30F6014A ??? please help me in this...! :lol:
I saw a example code like below. But its using "FSfopenpgm" function, because its PIC18F device..
#include “FSIO.h”
#define bfrsize 5
void main(void)
{
FSFILE *pOldFile, pNewFile;
char myData[20];
char bfr [6];
int bytesRead, bytesWritten;
char newFile[] = “newfile.txt”;
char writeArg = “w”;
// Must initialize the FAT16/FAT32 library. It also initializes SPI and other related
pins.
if( !FSInit() )
// Failed to initialize FAT16 – do something…
return 1; // Card not present or wrong format
// Create a new file
pNewFile = FSfopen (newFile, writeArg);
// Open an existing file to read
pOldFile = FSfopenpgm (“myfile.txt”, “r”);
if ( pOldFile == NULL )
// Either file is not present or card is not present
return 1;
// Read 10 bytes of data from the file.
bytesRead = FSfread((void*)myData, 10, 1, pOldFile);
// read bfrSize (5) items (of size 1 byte). returns items count
bytesRead = FSfread( (void *)bfr, 1, bfrSize, pOldFile );
// Write those fifteen bytes to the new file
bytesWritten = FSfwrite ((void *) myData, 10, 1, pNewFile);
bytesWritten = FSfwrite ((void *) bfr, 1, bfrSize, pNewFile);
// After processing, close the file.
FSfclose( pOldFile );
FSfclose (pNewFile);
//Delete the old file
FSremovepgm (“myfile.txt”);
}