CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

How to store a .bin file in 18f4680
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Thu Feb 19, 2009 10:05 pm     Reply with quote

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







PostPosted: Fri Feb 20, 2009 3:59 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Feb 20, 2009 4:08 pm     Reply with quote

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:
Code:
int8 buffer[64];


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'.

Quote:
c=buffer;

Because 'buffer' is an array, if you want to read the first byte in the
array, you must do this:
Code:
c = buffer[0];
Ttelmah
Guest







PostPosted: Fri Feb 20, 2009 4:12 pm     Reply with quote

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







PostPosted: Tue Feb 24, 2009 11:50 am     Reply with quote

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







PostPosted: Tue Feb 24, 2009 12:00 pm     Reply with quote

You are still trying to print the buffer as a string, without having a terminator character on it....

Best Wishes
alphadog
Guest







PostPosted: Tue Feb 24, 2009 12:13 pm     Reply with quote

Sorry about that Ttelmah, I did add that into the code but still it did not get beyond the fgetc command.
Possible reasons?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
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