
dsPIC30F Flash Programming Specification
DS70102K-page 62
2010 Microchip Technology Inc.
APPENDIX B: HEX FILE FORMAT
Flash programmers process the standard HEX format
used by the Microchip development tools. The format
supported is the Intel HEX 32 Format (INHX32).
Please refer to Appendix A in the “MPASM User’s
Guide” (DS33014) for more information about hex file
formats.
The basic format of the hex file is:
:BBAAAATTHHHH...HHHHCC
Each data record begins with a 9-character prefix and
always ends with a 2-character checksum. All records
begin with ‘:’ regardless of the format. The individual
elements are described below.
BB - is a two-digit hexadecimal byte count
representing the number of data bytes that appear
on the line. Divide this number by two to get the
number of words per line.
AAAA - is a four-digit hexadecimal address
representing the starting address of the data
record. Format is high byte first followed by low
byte. The address is doubled because this format
only supports 8-bits. Divide the value by two to
find the real device address.
TT - is a two-digit record type that will be ‘00’ for
data records, ‘01’ for end-of-file records and ‘04’
for extended-address record.
HHHH - is a four-digit hexadecimal data word. For-
mat is low byte followed by high byte. There will
be BB/2 data words following TT.
CC - is a two-digit hexadecimal checksum that is
the two’s complement of the sum of all the
preceding bytes in the line record.
Because the Intel hex file format is byte-oriented, and
the 16-bit program counter is not, program memory
sections require special treatment. Each 24-bit
program word is extended to 32 bits by inserting a so-
called “phantom byte”. Each program memory address
is multiplied by 2 to yield a byte address.
As an example, a section that is located at 0x100 in
program memory will be represented in the hex file as
0x200.
The hex file will be produced with the following con-
tents:
:020000040000fa
:040200003322110096
:00000001FF
Notice that the data record (line 2) has a load address
of 0200, while the source code specified address
0x100. Note also that the data is represented in “little-
endian” format, meaning the Least Significant Byte
(LSB) appears first. The phantom byte appears last,
just before the checksum.