|
|
View previous topic :: View next topic |
Author |
Message |
TL
Joined: 15 Sep 2003 Posts: 75
|
Editing hex file |
Posted: Fri Mar 06, 2009 3:37 am |
|
|
Hi, I have an old hex file but the original C files have been lost. I would like to make minor changes to some LCD text strings embedded in the hex file. Is it possible using an editor or process?
I have tried opening it with various hex editors but could not see the text strings I want.
Thanks. |
|
|
Ttelmah Guest
|
|
Posted: Fri Mar 06, 2009 4:20 am |
|
|
Yes, but....
A number of things apply.
First, so long as your new strings, are the same length, or shorter, it is possible. However if any are longer, then I'm afraid it is not really possible.
Second, you have to remember that every line in the hex file, itself carries a checksum. This will need to be updated as well.
Third, I'd guess this is on a PIC16 chip?. If so, then the constant data representing the strings, _won't_be stored as 'text', but as a program, which returns the text. This is done using 'RETLW' instructions, for each character.
So for example, if your string is "Hello", then the sequence stored will be:
'H' = 0x48
Retlw instruction = 0x34nn
Instruction to return 'H' = 0x3448
Then the 'e', becomes 0x3465
The 'l', becomes x346C
etc..
These would be the sequences you would have to find...
Now, if your strings are shorter or the same length, the first thing to do, is to write a table of the 'old' and 'new', using assembler, but hex for the value, so:
RETLW 0x48
RETLW 0x65
RETLW 0x6C
RETLW 0x6C
RETLW 0x6F
Then, don't try to edit the hex file directly, since this will be hard, both to track the instruction, and to get the checksums correct. Instead, load the file into MPLAB. Look at the assembler listing, and you should find several locations, with long lists of RETLW instructions (these are the constant storage). Look through these to find the sequence of the first string you are looking for - in the example, the sequence of RETLW instructions above. Once this is found, replace this with the new assembler sequence. You can then ask MPLAB, to output the resulting HEX file.
If a string is shorter, you can either just add a space, or zero character. If the code only accesses the data as 'strings', then it'll automatically stop on any given string, when it reaches the RETLW 0 instruction.
Longer is basically impossible, since you would have to relocate all code that follows. A major task.
Best Wishes |
|
|
TL
Joined: 15 Sep 2003 Posts: 75
|
|
Posted: Fri Mar 06, 2009 4:56 am |
|
|
Hi Ttelmah,
Thanks for your comments. The target mcu is PIC18F6720.
Quote: | Instead, load the file into MPLAB. Look at the assembler listing, |
I've OPENed and IMPORTed the hex file (in turn) under FILE in menu bar in MPLAB but cannot see the assembler listing. How do I enable it? I use MPLAB V8.10.
BTW, I don't have the original assembler file. I only have the original hex file. The assembler listing file is normally an output file. Did you mean I use the original assembler file OR use MPLAB to dis-assemble the hex file to obtain an assembler file? |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Fri Mar 06, 2009 8:14 am |
|
|
I suggest to use the CCS disassembler tool, available in the PCW IDE. |
|
|
Ttelmah Guest
|
|
Posted: Fri Mar 06, 2009 9:01 am |
|
|
On the 18 chips, the text will be there, without having to worry about the RETLW complexities. Makes it a lot simpler.
The assembler converter in CCS, is not useable in the same way. With MPLAB, you can edit the assembler 'live', and the result can be output as a hex file, which is directly what you want. I can't think of an equivalent way with the CCS tools.
Select the processor to match your target, then, if you import the .hex file, into MPLAB, and select 'view', 'program memory', you get the values for each location, and it's equivalent disassembly down the right hand side of the page.
On the page this opens, you have a number of options at the bottom. If you select 'Opcode Hex', you will get the hex code displayed, and on the right hand side of the window, the equivalent ASCII text. Most of this will be illegible, but the messages you want should be directly visible.
You can just click on the ASCII, and change it.
When finished select 'export', and this will offer to generate the hex file for you.
The file will be larger than the original (since it'll include 'empty' areas in the ROM), but this won't matter.
Best Wishes |
|
|
TL
Joined: 15 Sep 2003 Posts: 75
|
|
Posted: Tue Mar 10, 2009 6:42 am |
|
|
Thanks to both Ttelmah and FvM. I have tried the MPLAB and CCS methods, and I agree with Ttelmah that the MPLAB method is much easier to edit the ASCII text. |
|
|
|
|
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
|