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 support@ccsinfo.com

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







How to store a .bin file in 18f4680
PostPosted: Fri Jan 23, 2009 4:19 pm     Reply with quote

Hi,

I am trying to store a 7 KB .bin file onto the 18F4680. Based on the data sheet it could be done cause the flash memory size of the PIC is about 64K. Now the question is how do I do it, since this binary file is not readable..is there a process I could just write this file onto the PIC.

Cheers

Alpha
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jan 23, 2009 4:30 pm     Reply with quote

You could convert the file to an Intel Hex file and then use a programmer
to load it in a PIC. See the command line options available for this
program:
http://www.testech-elect.com/keil/c51/bin2hex.htm
alphadog
Guest







PostPosted: Fri Jan 23, 2009 4:34 pm     Reply with quote

Thanks PCM, But I need the file in binary format itself, cause I am sending this file over the RS232 port.

So it would be essential to store the file in .bin format and send it over through the RS232 port of the PIC.

Thanks

Alpha
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jan 23, 2009 4:36 pm     Reply with quote

Write a small program in the PIC to receive the incoming bytes.
Call CCS flash memory routines to write to the flash memory in the PIC.

I have a question. Are you basically talking about a bootloader ?
Is that what you want to do ? If so, see the CCS example files
for a bootloader and also search for bootloader topics on this board.
alphadog
Guest







PostPosted: Fri Jan 23, 2009 4:47 pm     Reply with quote

No, Not a bootloader. Its more like I want to store this .bin file in the flash and send it over the RS232 and check the data that is being sent.
Since this binary file will be used for DSP programming.
alphadpg
Guest







PostPosted: Fri Jan 23, 2009 5:03 pm     Reply with quote

So, I still dont know how to write the .bin file using the CCS compiler.

Any ideas?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jan 23, 2009 5:12 pm     Reply with quote

Use the Ex_Sisr.c example program to receive bytes from RS-232
and save them in a buffer. Pull the bytes out of the receive buffer
and put them in another (smaller) buffer. When you have 64 of them
in the 2nd buffer, then call the write_program_memory() function.
The "FLASH_WRITE_SIZE" of the 18F4680 is 64 bytes. The CCS manual
refers to this value. You could use a smaller buffer size.

See this function in the CCS manual. It's on page 288 in the Acrobat reader:
Quote:
write_program_memory()

http://www.ccsinfo.com/downloads/ccs_c_manual.pdf

See these CCS files for examples of how to call the function:
Quote:
c:\program files\picc\examples\ex_usb_bootloader.c
c:\program files\picc\drivers\loader.c


I don't want to write the program for you.
alphadog
Guest







PostPosted: Fri Jan 23, 2009 5:31 pm     Reply with quote

Thanks for the info. No I needed a better idea of how to do it.

Will post the code once I am done for some trouble shooting.
.
Thanks Smile
crystal_lattice



Joined: 13 Jun 2006
Posts: 164

View user's profile Send private message

PostPosted: Sat Jan 24, 2009 1:18 am     Reply with quote

To me it sounds like you want to store a firmware file for another pic in the 18F4680 and use the 18F4680 as a programmer/loader for the other pic.

I would open the file in a hex editor and copy this data to a "const" table created somewhere in your code. Then you just have to access your table to enable you to transmit the data via rs232.

PCM Programmer's method enables you to load different files without having to reprogram the 18F4680 everytime you want to load a new file.

You say you can't open the file, what do you mean by this?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jan 24, 2009 1:37 am     Reply with quote

If that's what he wants to do, WinHex will turn binary data into C source
code that initializes an array. It has an option to do that.
alphadog
Guest







PostPosted: Sat Jan 24, 2009 8:28 am     Reply with quote

Yes guys thats what I want to do. PCM, I did not quite understand the reason for conversion of the data using Winhex.
alphadog
Guest







PostPosted: Sat Jan 24, 2009 1:27 pm     Reply with quote

I have tried the const table for storing the binary file, unfortunately this method cannot be used cause since I would like to store the binary file in its original format in the code, creating tables with bin format data is tough.

Is there any other way?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jan 24, 2009 1:58 pm     Reply with quote

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. I don't see it in the manual or the
Readme.txt file.

Say you have a .BIN file with this data at offset 0000:
Quote:
0000 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F


WinHex can make it into this source code:
Code:
unsigned char data[16] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
};


Here's how to get to it in the Winhex menu:
Quote:
Edit / Copy All / C Source

The source code will be copied to the Windows clipboard. You can then
paste it into a source file in your editor.
alphadog
Guest







Storing .bin file..using RS232__PROBLEMS
PostPosted: Thu Feb 19, 2009 2:49 pm     Reply with quote

Hey guys,

A follow up on this thread, I wrote a code which would be capable of writing 6kb of data coming from the PIC's RS232 interface onto its program memory. It has not worked so far, any suggestions?


Code:


#use rs232(baud=19200, xmit=PIN_C1,rcv=PIN_C0, STREAM=HOSTPC)
#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7, STREAM=USER,parity=N,stop=1)

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");
      }
}



Thanks

Alpha
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 19, 2009 3:13 pm     Reply with quote

Quote:

BYTE value,a,c;
BYTE buffer;

write_program_memory(i, value, 1);
read_program_memory (j, buffer, 64);
read_program_memory (j, buffer, 64);


Read the CCS manual's description of these functions.
Quote:

read_program_memory( )

Syntax: read_program_memory(address, dataptr, count );
Parameters: address is 16 bits on PCM parts and 32 bits on PCH parts.
The least significant bit should always be 0 in PCM.
dataptr is a pointer to one or more bytes.
count is a 8 bit integer

-------------------------------
write_program_memory( )

Syntax:
write_program_memory( address, dataptr, count );
Parameters: address is 16 bits on PCM parts and 32 bits on PCH parts.
dataptr is a pointer to one or more bytes
count is a 8 bit integer


For the middle parameter, you have put in a byte variable, not a pointer.
You need to fix this. In the case of 'value', a pointer to it is done by
putting an amperand in front of the variable name: &value
In the latter two cases, you are referencing a 64 byte array.
You need to declare 'buffer' as a 64 byte array.
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 1, 2  Next
Page 1 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