PIC16F57 Hex Data: Twelve-Bit Words Do Not Sit in Bytes
The last stage of a read is the one that quietly ruins projects, because it produces a file rather than a device and nobody tests a file until it is too late. A 2048-word array of twelve-bit words does not map onto a byte stream by any obvious rule, and every tool in the chain has an opinion about where the pieces go.

Where the words go in a file
Two twelve-bit words make twenty-four bits, which is exactly three bytes. So the natural packing puts word pairs into byte triples, low word first, and the decoder on the other side has to know that rule or the file becomes nonsense at every odd address. The alternative families that use a sixteen-bit container simply pad each word and waste a quarter of the file; both conventions exist, and a file produced under one and opened under the other looks like corrupted firmware rather than a formatting mismatch.
The configuration word is not in the range
| Item | Reachable by address | Comes from |
|---|---|---|
| Program words | Yes, 2048 of them | The array |
| Configuration word | No | A separate read command |
| Device ID | No | A separate read command |
| Calibration word | Yes, top address | The array |
The second row is where files lose information. A twelve-bit program counter cannot address the configuration word, so the programmer asks for it explicitly, and a decode that only walks the address range never asks. The result is an image that is complete as code and silent about oscillator mode, watchdog and protection, which means the second unit built from it will not behave like the first even when every instruction matches.
Why the checksum disagrees
Programmers and hex formats compute checksums differently: per record, per file, over words or over bytes, with or without the configuration word. Two correct tools can therefore report two different numbers for the same device, and the discrepancy is routinely interpreted as a failed read. The fix is to agree on the definition before the job starts, and to state in the deliverable which definition was used, so the customer’s verification step compares like with like.
The array that answers with zeros
Decoding is a formatting job and formatting cannot invent content. A protected array returns zeros, and a competent decoder will happily produce a well-formed hex file containing 2048 no-operations with a correct checksum. That file will pass every structural check and be worthless. The ordering rule is therefore: confirm the read produced real bits before spending time on the encoding, and treat a suspiciously regular array as a signal rather than a result. A file full of the same word is the signature of a protection bit, not of a decoder bug.
Why the tool is not the answer
Every programmer, every disassembler and every converter has an opinion about word order, padding and checksums, and none of them is wrong within its own convention. The failure is in assuming two tools share one. Export from the programmer in the most explicit format available, convert once with a script that records its assumptions, and keep that script with the deliverable. A conversion that a customer can re-run and compare against is worth more than a file that happens to open.
What a decode owes the customer
Four things: the program words, the configuration word, the device ID, and a statement of the packing convention. A decoder that omits the last is not being modest, it is transferring a hidden assumption to whoever opens the file next. On a part with an odd number of words the convention matters even more, because the final triple has one word’s worth of padding and the padding value is a choice.
The verification that catches packing errors
Disassemble the result and read the first twenty instructions. A correctly packed image from this family starts with a sensible initialisation sequence: clear a register, set up the ports, jump. A wrongly packed image produces instructions that are legal but absurd, and the pattern of absurdity usually repeats with a period of two words, which is the signature of the packing being off by one. That test takes a minute and saves a re-read.
Where the awkward parts actually are
The smaller array in PIC16C58B data has the same packing rule and the same out-of-range configuration word, so a decoder written for one works for the other. On parts where the protection is set and the array reads as zeros, the decode has nothing to do until the physical route has produced real bits, which is the situation described in reverse locked PIC16F54. The general treatment of formats and their verification is in extracting MCU code, and the way an image is confirmed against a running device is in reading MCU code.