 |
 |
| View previous topic :: View next topic |
| Author |
Message |
andrewg
Joined: 17 Aug 2005 Posts: 316 Location: Perth, Western Australia
|
|
Posted: Thu Feb 19, 2009 10:05 pm |
|
|
| PCM programmer wrote: | | I now think that you want some sort of compiler feature where you #include a .BIN file in your source program, with a starting address specified, and the compiler automatically turns it into data in the .HEX file. I don't think such a feature exists. |
In the IDE it's "Tools -> Convert Data to C". I've not used it in an actual project, but it seems to do the business. _________________ Andrew |
|
 |
alphadog Guest
|
|
Posted: Fri Feb 20, 2009 3:59 pm |
|
|
I made the asked changes, the program is still not working.
| Code: |
#define buffer 64
int erase_size= getenv("FLASH_ERASE_SIZE");
int write_size= getenv("FLASH_WRITE_SIZE");
void main (void)
{
BYTE value,a,c;
//BYTE buffer;
int i= 0x1019;
int j= 0x1019;
if (erase_size = write_size)
{
for (i=0x1019; i<= 0x2943; i++)
{
value=fgetc(USER);// get data from RS-232
write_program_memory(i, &value, 1);
fputc(value,USER);
fputc(value,HOSTPC); // display data on LCD.
delay_ms(10);
}
read_program_memory (j, buffer, 64);
c=buffer;
fputc(c,USER);
for (j=0x1019; j<=0x2943; j+64)
{
read_program_memory (j, buffer, 64);
c=buffer;
fputc(c,USER);
}
}else
{
fprintf(USER, "ERROR");
}
}
] |
|
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Feb 20, 2009 4:08 pm |
|
|
| Quote: | #define buffer 64
//BYTE buffer; |
You have to actually allocate the RAM memory for the buffer.
You must declare buffer as an array of 64 bytes, like this:
| Quote: | | read_program_memory (j, buffer, 64); |
Remember, when you do the above, you are telling it to read 64 bytes
from program memory, starting at address 'j', and put the bytes into the
RAM array 'buffer'.
Because 'buffer' is an array, if you want to read the first byte in the
array, you must do this:
|
|
 |
Ttelmah Guest
|
|
Posted: Fri Feb 20, 2009 4:12 pm |
|
|
You have 'buffer' defined as the number '64', and you are asking the read, to read to this _address_.
Also, you just then output this number as a character, rather than the contents.
You need something like:
| Code: |
#define buffer_size (64)
char buffer[buffer_size+1]; //One extra for string terminator
//Then to read the memory
buffer[64]='\0'; //ensure buffer is null terminated
for (j=0x1019; j<=0x2943; j+64) {
read_program_memory (j, buffer, 64);
fprintf(USER,"%s",buffer); //will send the data buffer contents
//as a string to the user RS232
}
|
Best Wishes |
|
 |
alphadog Guest
|
|
Posted: Tue Feb 24, 2009 11:50 am |
|
|
Here is the new code, but it still does not seem to work..any ideas?
| Code: |
int erase_size= getenv("FLASH_ERASE_SIZE");
int write_size= getenv("FLASH_WRITE_SIZE");
int8 buffer[64];
int buffinc,maininc;
void main (void)
{
int1 done=FALSE;
int i= 0x1019;
int j= 0x1019;
buffinc=0;
maininc=0;
if (erase_size = write_size)
{
while(!done)
{
buffer[buffinc] = fgetc(USER);// It seems to get stuck at this line
write_program_memory(i, buffer, 2);
delay_ms(10);
buffinc+1;
i+1;
if(buffinc=64)
{
buffinc=0;//do something to enable overwriting on the 64 bytes already written,
maininc+1;
if (maininc=100)
{
done=TRUE;
}
}
}
for (j=0x1019; j<=0x2943; j+64)
{
read_program_memory (j, buffer, 64);
fprintf(USER,"%s",buffer);
}
}
else
{
fprintf(USER, "ERROR");
}
}
|
|
|
 |
Ttelmah Guest
|
|
Posted: Tue Feb 24, 2009 12:00 pm |
|
|
You are still trying to print the buffer as a string, without having a terminator character on it....
Best Wishes |
|
 |
alphadog Guest
|
|
Posted: Tue Feb 24, 2009 12:13 pm |
|
|
Sorry about that Ttelmah, I did add that into the code but still it did not get beyond the fgetc command.
Possible reasons? |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|