...
If its fine to waster space then i would do this..
Setup a #define to set the max to write or what ever our pic can handle like
#define SIZE 128
So we know how much data the pic can buffer and just read from start of 512 byte and read those 128 bytes then you can skip the rest.
Then you can alter the 128 bytes and write it back to start of sector you are on.
...
OK, that is a very obvious solution and it works.
But now when your PC reads the data file from the card you have 2 problems;
1. It needs to know the chunk SIZE
2. It needs special software to parse the file, ie read the chunks and ignore the padding.
With my method the data in the file is contiguous, and can be read simply as a file by any PC. It just stores the data as "word" 32bit not as "char" 8bit. Since "word" is a default for most windows software that is all fine.
Mr RB so you would still have to read 512 bytes dude lol what if i want to edit data in on the 100th byte? how would i edit it without losing the other data?
The system I used for reading the data from a file was just to read a whole block of 512 (because you have to read a whole block) and just keep the data required by the PIC. In the example above the PIC reads a 512 byte block, keeps every 4th byte and stores in its 128 byte ram array. So you have seamless reading and writing of a whole memory card in blocks of 512 using just 128 bytes of PIC ram.
Now if you need the PIC to read data written by the PC, you can get the PC to write 1byte data as "words" as explained above.
If the PC has written 512 actual bytes, then you can read that 512 byte block and just keep the 128 (etc) bytes you need. But you cant write 512 actual data bytes unless you have 512 bytes of ram or buffer with the PIC eeprom memory (there are some examples of that on the net).
In my first post I was not saying anything you did was wrong, you said you weren't using file access as you didnt have 512 bytes of ram and I suggested a nice kludge solution I developed that works, to allow proper file systems with only 128 bytes of ram needed. There's a lot of people think you just CAN'T do memory card file systems on the 16F PICs, but my system lets you do it quite elegantly, the only drawback is the 1:4 data size wasted in the memory card.