Here's the problem, I don't know what I am doing.
I want to program a PIC 8-bit MCU using another MCU. The target chip in this case is the PIC18F2539..
(1) I wrote a program in C
(2) The program is compiled and the output result is a ASCII Intel .Hex file ready to feed to the chip.
(3) But I am a little confused, which byte is which??
Ok, so here's the first few lines of the .Hex file:
:04000000
2BEF02F0F0
:0400080047EF05F0C9
:10001800D8CF41F0E8CF42F0E0CF43F08B88F2A48C
:1000280001D001D05ED0F90ED76E9F0ED66EF29435
:10003800
6A50400AD8A401D001D003D02B2A2C2A18
Now I know the format of the .hex file
Take the last line above, for instance, the payload bytes(grouped in sets of four consecutive) are:
6A 50 40 0A D8 A4 01 D0 01 D0 03 D0 2B 2A 2C 2A
And I guess the starting address for these bytes to be wrote to is 0x38
Fine enough, but the devil is always in the details!
The Programming Datasheet for this chip I got from Microchip
shows exactly how to program this chip, all I gotta do is figure out what it is trying to tell me.
I understand how to do the programming to accomplish the instructions below, except I am a bit confused on how to get from the
ASCII .hex representation to the format described below in the 'Sequence" below:
Basically my question boils down to this: Which byte is which?
To program the chip, 8-words are loaded into a buffer, then the buffer is written to the chip..no problem!
Here's the steps in question:
Again:
Load Address Pointer Upper, High and Low
4-bit Command Payload Core Instruction
1100 <LSB><MSB> Write two bytes and post increment by 2
1100 <LSB><MSB> Write two bytes and post increment by 2
1100 <LSB><MSB> Write two bytes and post increment by 2
1111 <LSB><MSB> Write two bytes and start programming
//the code above is sending a serial-bit stream to the MCU to be programmed in a
LSbit to MSbit order.Low=Low+8; //increment Low address pointer by 8 and loop back to Again until all bytes from .Hex are programmed into the chip.
if(Low<LastAddress2B_Programmed) goto Again;
So here's the question, as you see the first two bytes from the example line of code above are
6A 50Now to present these bytes to the instruction shown, which byte is <LSB> and which byte is <MSB>
I get it that I must store them in an Uint16 word, lets call the variable name DW
DW is the 16bit Uint16 fed to the Load2Bytes and Increment by two Table Write command.
Looks easy, but I am not sure how to proceed.
I will program my work in C.
If I parse and convert the ASCII hex literals into sets of two, convert the values to a 16-bit integer and
and store them in a Uint16 type array called PgmCode[(size=num of prog words ],
I first must know which byte is which.
But storing the bytes in an integer would have a <Hibyte><LoByte> order of bits. and reversing the bit order would mean a lotta code for each word write!
Exactly the opposite of what is needed.