Electronic – What PIC processor was this HEX-file meant for

assemblyhexpic

I have this .hex file:

:020000040000FA
:020000000528D1
:080008000528831686138312FC
:1000100015280F30A0000D2008007F30A100A00B94
:1000200012280800A10B12280D2886130920861714
:040030000920152866
:02400E00B03FC1
:00000001FF

I know it has been burned on a PIC, but I don't know what PIC.

What can we say about the identity (part number, family, etc.) of the chip with only this data?

Best Answer

The first thing to do is to see what values the HEX file contains at what addresses. Here is the output of my HEX_DUMP program on your HEX file:

00000000-00000001 (2): 05 28
00000008-0000000F (8): 05 28 83 16 86 13 83 12
00000010-0000001F (16): 15 28 0F 30 A0 00 0D 20 08 00 7F 30 A1 00 A0 0B
00000020-0000002F (16): 12 28 08 00 A1 0B 12 28 0D 28 86 13 09 20 86 17
00000030-00000033 (4): 09 20 15 28
0000400E-0000400F (2): B0 3F

The last line is most likely the config word, which means this is for a traditional PIC 16. For those PICs, the HEX file addresses are doubled since each PIC address holds 14 bits and HEX files only hold 8 bits of data per address. The last line is therefore setting the PIC address 2007h to 3FB0h, which is exactly the kind of thing you'd expect the end of a HEX file for one of these PICs to contain.

The exact PIC 16 model is impossible to tell. Since we know it is a PIC 16, we can have MPLAB show us the dissassembled code:

To get this I set the processor in MPLAB to a 16F877, since that is a full memory traditional PIC 16.

Note that the instructions are quite plausible, although this is clearly written by someone that didn't really know what they were doing and probably didn't even use the linker.

The GOTO at 0 is probably attempting to jump 1 past the interrupt routine at 4, although that doesn't apparently exist since a GOTO 5 there makes no sense (at least to anyone that knows what they are doing, there is a lot of bad code out there). The next instruction attempts to set the bank, mess with TRISB, mess with the bank again, and jump to 15h.

I'm not going to try to decode the rest of this mess, but it seems quite certain we have the right processor architecture. We can't know the exact model because this would actually run on most basic PIC 16. If you decode the config word, you might get a clue to narrow down the model more, but I really don't think you can get to a exact model because this code will in fact run on a bunch of them.