Convert long .hex file to array.

All,

I am working on a project where I need to write a firmware code to a chips SRAM (Pcap02). The firmware comes in a .hex file. Looks something like this;

00 00 00 7A C0 CF FF F0 D2 43 7A D0 34 72 62 63 
00 65 7A C4 D1 43 7A D0 33 AB 5E 42 5C 48 B0 01 
20 68 B1 02 78 20 60 B2 01 20 68 B3 1B 7A C2 D1 
43 7A DB 33 AB 00 7F 7A D4 43 7A E4 44 7A C3 D1 
43 7A DB 33 AB 00 78 20 60 B5 0B 72 62 7F 7A D4 
43 7A E4 44 20 60 00 B7 02 78 20 60 84 01 25 80 
01 00 00 00 00 00 20 1B 7A C0 D1 43 7A DB 33 AB 
00 7F 23 98 84 01 25 80 20 91 43 58 7A C0 D1 43 
6A C0 44 7A C4 D1 43 7A D0 3A 66 67 76 77 66 20 
1B 7A C0 C0 C0 C8 D2 43 7A DE 44 7A C0 C0 C1 D1 
D2 43 7A DD 44 7A C0 C0 C0 C8 D2 41 25 D1 6A D0 
43 7A D9 44 6A D1 43 7A DA 44 6A D2 43 7A DB 44

The file is over 500 lines long, see attached if interested.

What I need to do is somehow load the file into an array of bytes in the IDE. However, I am not sure this is possible. Maybe something like

#include file.hex

byte array[] = {file.hex}

I know I can convert the file into an array by rewriting the whole set as
byte array[] = {0x00,  0x00,  0x00, 0x7A,  0xC0, ...

I am just wondering if there is a better way to do this.

Thanks.

The file is over 500 lines long, see attached if interested.

Apparently, it slipped your mind to actually attach the file.

500+ lines with 16 values per line will need more than 8000 bytes of SRAM to store. Only the Due has that much memory.

tex_downey:
What I need to do is somehow load the file into an array of bytes in the IDE.

That seems a rather strange thing to do. Why would the IDE want an array of anything?

If you mean that you want to convert the file so that it appears in the style in which an array is entered into program code than I suggest you write a short Python (or your favourite PC programming language) to do the conversion.

You might even be able to do it with search and replace in a text editor.

...R

I do need to learn python. :frowning:

I can transfer the hex file into an array using MATLAB, I was just hoping there was a "cleaner" way.

Doing the conversion in MATLAB means I have to copy this long piece into the IDE.

byte HexStandard[] = {0x90, 0x00, 0x0,  0x0,  0x0,  0x7A, 0xC0, 0xCF, 0xFF, 0xF0, 0xD2, 0x43, 0x7A, 0xD0, 0x34, 0x72, 0x62, 0x63, 0x0,  0x65, 0x7A, 0xC4, 0xD1, 0x43, 0x7A, 0xD0, 0x33, 0xAB, 0x5E, 0x42, 0x5C, 0x48, 0xB0, 0x1,  0x20, 0x68, 0xB1, 0x2,  0x78, 0x20, 0x60, 0xB2, 0x1,  0x20, 0x68, 0xB3, 0x1B, 0x7A, 0xC2, 0xD1, 0x43, 0x7A, 0xDB, 0x33, 0xAB, 0x0,  0x7F, 0x7A, 0xD4, 0x43, ... for 8000 hex numbers

tex_downey:
I have to copy this long piece into the IDE.

Won't you have to do that no matter how the data is transformed?

Perhaps you could put the data in a .h file in the same directory as your .ino file and then use #include "myFile.h"

...R

YES,

That is what I was looking for.

If I do that, how do I call out the contents of the file?

Lets say I had an array in my .h file that I would like to call in my .ino. How would I call the array in the .h file? I have a few cases where I would like to changing out arrays by just changing the .h file.

I know this is a basic programming technique but I am having trouble getting it to work.

How would I call the array in the .h file?

You don't call arrays. You call functions.

You access an array declared in a header file included in the sketch just like it was declared in the sketch.