Hey all,
I'm new here. Been enjoying the mbed so far. I'm trying to make a PIC programmer (reads a hex file from storage, outputs it in serial with a clocking signal).
I'm having a bit of a problem, though. The PIC expects the file to be passed in as 14-bit words, and as C++ only allows you to access a byte at a time, I'm reading the file in to an array of 14-boolean arrays (I know there are better ways to do it, such as on-the-fly or in a bitset, but I'll leave that maybe until later).
For some reason, my code never reaches the end of the file. It seems to hang at bit 180 (byte 0x16) every time. I've been going over it for ages, but I can't figure it out. I had thought it was a memory issue at first, but I don't think that's it (file is 100 bytes = 800 bits = 6kB if a boolean is 8 bits). The mbed just stops - even the log file has a partially completed line written.
Any thoughts?
Thanks,
K
bool **fileData;
fileData = new bool*[fsize/14];
for (int i = 0; i < 14; i++)
fileData[i] = new bool[14];
int curBS = 0;
int offset = 0;
int curInt = 0;
curInt = fgetc(hexFile);
do
{
//Convert it to binary
bool b_curInt[8];
intToBinary(curInt, 7, b_curInt);
//For each bit in the read integer
for (int b_curPos = 0; b_curPos < 8; b_curPos++)
{
//If the word is full, move to the next one
if (offset == 14)
{
curBS++;
offset = 0;
}
fileData[curBS][offset] = b_curInt[b_curPos];
fprintf(logFile, "WORD: %d\tOFFSET:%d\tVALUE:%d\n", curBS, offset, (b_curInt[b_curPos] == true ? 1:0) );
prgModeLED = (b_curInt[b_curPos] == true ? 1:0) ;
offset++;
}
curInt = fgetc(hexFile);
} while (curInt != EOF);
Hey all,
I'm new here. Been enjoying the mbed so far. I'm trying to make a PIC programmer (reads a hex file from storage, outputs it in serial with a clocking signal).
I'm having a bit of a problem, though. The PIC expects the file to be passed in as 14-bit words, and as C++ only allows you to access a byte at a time, I'm reading the file in to an array of 14-boolean arrays (I know there are better ways to do it, such as on-the-fly or in a bitset, but I'll leave that maybe until later).
For some reason, my code never reaches the end of the file. It seems to hang at bit 180 (byte 0x16) every time. I've been going over it for ages, but I can't figure it out. I had thought it was a memory issue at first, but I don't think that's it (file is 100 bytes = 800 bits = 6kB if a boolean is 8 bits). The mbed just stops - even the log file has a partially completed line written.
Any thoughts?
Thanks,
K
bool **fileData; fileData = new bool*[fsize/14]; for (int i = 0; i < 14; i++) fileData[i] = new bool[14]; int curBS = 0; int offset = 0; int curInt = 0; curInt = fgetc(hexFile); do { //Convert it to binary bool b_curInt[8]; intToBinary(curInt, 7, b_curInt); //For each bit in the read integer for (int b_curPos = 0; b_curPos < 8; b_curPos++) { //If the word is full, move to the next one if (offset == 14) { curBS++; offset = 0; } fileData[curBS][offset] = b_curInt[b_curPos]; fprintf(logFile, "WORD: %d\tOFFSET:%d\tVALUE:%d\n", curBS, offset, (b_curInt[b_curPos] == true ? 1:0) ); prgModeLED = (b_curInt[b_curPos] == true ? 1:0) ; offset++; } curInt = fgetc(hexFile); } while (curInt != EOF);