Loading a HEX file with PICkit 2
I think I know the problem. In your first hex file, the alignment is correctly on 2 byte, with 16 bytes on each line. The first few addresses are (in hexadecimal):

6830
6840
6850
6860
6870
6880
6890
68A0


Notice how the addresses go up in increments of 16bytes (10h), but crucially, notice how the lower digit is always zero (well strictly speaking a multiple of 2).

In the corrected hex file, the addresses are:

6829
6839
6849
6859
6869
6879
6889
6899
68A9


Here they are no longer correctly aligned. Notice how the lower digit is not a multiple of 2 - it is 9.

This is a problem simply because the PIC's program memory is organised in 2byte (16bit) chunks - each instruction is 16bit or 32bit IIRC.

Technically the hex file is correct, however it will confuse the heck out of the tools because technically address 0x6829 does not exist (0x6828 and 0x682A both do). The PICKit software will realign the hex file when it opens it - essentially adding in an extra 0xFF word at the beginning to realign the data to the correct place, and as a result the upload works and the program runs fine.



As to why it is happening, I really haven't a clue beyond a bug in a toolchain which is already glitchy at the best of times (the reason I gave up with PICs and went for AVRs instead!).

There may be a setting somewhere in the project to select the alignment of the hex file. If not, perhaps you could try adding an extra byte sized variable in the program memory (or make an existing one an extra byte in size) and see if that tricks the toolchain into realigning the hex file.