|
|
View previous topic :: View next topic |
Author |
Message |
alphadog Guest
|
How to store a .bin file in 18f4680 |
Posted: Fri Jan 23, 2009 4:19 pm |
|
|
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
|
|
|
alphadog Guest
|
|
Posted: Fri Jan 23, 2009 4:34 pm |
|
|
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
|
|
Posted: Fri Jan 23, 2009 4:36 pm |
|
|
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
|
|
Posted: Fri Jan 23, 2009 4:47 pm |
|
|
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
|
|
Posted: Fri Jan 23, 2009 5:03 pm |
|
|
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
|
|
Posted: Fri Jan 23, 2009 5:12 pm |
|
|
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
|
|
Posted: Fri Jan 23, 2009 5:31 pm |
|
|
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 |
|
|
crystal_lattice
Joined: 13 Jun 2006 Posts: 164
|
|
Posted: Sat Jan 24, 2009 1:18 am |
|
|
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
|
|
Posted: Sat Jan 24, 2009 1:37 am |
|
|
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
|
|
Posted: Sat Jan 24, 2009 8:28 am |
|
|
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
|
|
Posted: Sat Jan 24, 2009 1:27 pm |
|
|
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
|
|
Posted: Sat Jan 24, 2009 1:58 pm |
|
|
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 |
Posted: Thu Feb 19, 2009 2:49 pm |
|
|
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
|
|
Posted: Thu Feb 19, 2009 3:13 pm |
|
|
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. |
|
|
|
|
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
|