Posts Tagged ‘copia cip eeprom’
Breaking a PIC16C716 to a Hex File: What That Image Actually Contains
“Heximal” is industry shorthand for the hex image — the file a programmer writes and a reader returns. It is worth being precise about what that file holds, because a PIC image is not a flat dump of bytes. It is a map of 14-bit instruction words, each padded into two bytes, plus configuration and identification data that sits outside the program space entirely. Recovering the wrong shape of file is one of the most common ways for a technically successful read to produce a device that will not run.
The part in context
The PIC16C716 is a mid-range 8-bit part with EPROM program memory, a 13-bit program counter, and an 8-bit A/D converter. It is closely related to the PIC16C712, which differs mainly in program memory size.
| Property | PIC16C716 |
|---|---|
| Program memory | 2K × 14 words EPROM |
| Address range | 0000h–07FFh |
| Program counter | 13-bit (8K × 14 address space) |
| Data memory | 128 bytes |
| I/O pins | 13 |
| A/D converter | 4 channels, 8-bit |
| Package | 18-pin PDIP/SOIC, 20-pin SSOP |
| Program memory type | EPROM / OTP |
The 13-bit counter can address 8K × 14, but only 2K is implemented. Accessing above 07FFh wraps around — a behaviour that makes a short read look complete.
How the memory is laid out
The device has two separate memory blocks, program and data, each with its own bus, which is what allows an instruction fetch and a data access to proceed concurrently. That Harvard arrangement is the reason a 14-bit instruction word can coexist with 8-bit data without bus contention.
The reset vector sits at 0000h and the interrupt vector at 0004h. Every routine in the firmware is reachable from those two words.
Data memory is divided into banks of 128 bytes (7Fh). The low addresses of each bank are reserved for Special Function Registers; General Purpose Registers, implemented as static RAM, sit above them. High-use SFRs are mirrored across banks so that common operations do not need a bank switch — which is convenient for the original programmer and a nuisance for anyone reading the disassembly, because the same address means different registers depending on the current bank.
Two registers dominate any reading of a recovered image:
- STATUS holds the ALU result flags, the reset status, and the bank-select bits. It can be the destination of any instruction, but writes to the Z, DC, and C bits are suppressed when it is, and the TO and PD bits are not writable — so an instruction targeting STATUS does not do what its mnemonic implies. Disassemblers that ignore this produce subtly wrong output.
- PCL and PCLATH split the program counter. PCL is readable and writable; the high bits are not directly accessible and are updated only through PCLATH. Computed jumps therefore appear as a write to PCLATH followed by a write to PCL, and that pattern is the single most reliable signal that a table-driven branch is being used rather than ordinary control flow.
The eight-level hardware stack is not part of either memory space, which means a recovered image contains no stack contents to recover — calls and returns are implicit.
From instruction words to Intel HEX
A PIC image is stored in Intel HEX format, where each line is a record:
“ :LLAAAATT[DD...]CC “
LL is the byte count, AAAA the address, TT the record type, the DD bytes the payload, and CC a checksum formed as the two’s complement of the sum of all preceding bytes. Data records use type 00 and end-of-file is type 01.
The conversion that matters is arithmetic: a 14-bit instruction word occupies two bytes, low byte first, with the two unused high bits zero. So 2K words of program occupies 4,096 bytes in the file, and the file’s address space is byte-oriented while the device’s is word-oriented. Converting between them is mechanical and unforgiving — an off-by-one in the byte order produces an image that reads correctly in a hex editor and executes as garbage.
Three regions sit outside the program array and all three have to be captured:
| Region | Address | Contents |
|---|---|---|
| Program | 0000h–07FFh | 2K instruction words |
| ID locations | 2000h–2003h | User identification words |
| Configuration word | 2007h | Oscillator mode, watchdog, code protect, and other device options |
Why the configuration word decides whether it boots
A recovered program that omits the configuration word is not a recovery. The configuration word selects the oscillator mode, which alone determines whether the device starts at all on the target board; it sets watchdog behaviour; and it carries the code-protect bit. An image with the program intact and the wrong configuration word produces a device that either does not oscillate or resets continuously — behaviour that is easily misread as a failed read rather than a wrong rebuild.
How protection works on this part
The code-protect bit is part of that configuration word at 2007h, and the configuration word lives in the same EPROM array as the program. When the bit is set, the program memory cannot be read out through the programming interface, in-circuit serial programming included.
The consequence is the familiar asymmetry: because configuration and program share one array, clearing the bit through the documented path erases the program. On a windowed part, ultraviolet erase clears both. On an OTP part, there is no erase at all.
Routes beyond the documented one are the same families that apply across this architecture — a timing disturbance during the protection check, or a physical read of the floating-gate cells after decapsulation. Sibling parts show the same structure at different sizes: PIC16C715 firmware for the smaller array, PIC16C717 program recovery for the larger part with a ten-bit converter.
Why this part turns up locked
The PIC16C716 was aimed at designs that needed a small A/D front end and not much else — sensors, panel controls, small appliances. Those products shipped in volume, the design houses that wrote the firmware have often closed, and the OTP parts in the field carry the only copy of the program. Because the part is OTP, there is no benign route to a spare image: no erase, no re-read, no recovery from a programmed device without addressing the protection.
Limits worth stating upfront
- Two bytes per word. A byte-count check is not a word-count check, and mismatches here are silent.
- The configuration word is not optional. Omitting it produces a non-booting result that looks like a bad read.
- Bank state changes meaning. The same SFR address resolves differently depending on STATUS, so a disassembly without bank tracking is unreliable.
- OTP means one attempt per device. There is no erase to fall back on.
FAQ
What exactly does “heximal” mean? The hex file representing the device image — program words, ID locations, and configuration word — in Intel HEX format.
Why does a 2K-word part produce a 4 KB file? Because each 14-bit word is stored in two bytes. The file is byte-addressed; the device is word-addressed.
Can the image be rebuilt without the configuration word? Not usefully. The oscillator selection alone determines whether the rebuilt device starts, so the configuration word has to come from the original device or be reconstructed deliberately.
Is the eight-level stack recoverable? There is nothing to recover. The stack is hardware, outside both memory spaces, and holds no persistent contents.
Conclusion
Breaking a PIC16C716 to a usable hex file is a question of shape as much as of access: 2K words padded to 4,096 bytes, plus ID locations at 2000h and a configuration word at 2007h that decides whether the result runs. Getting past the code-protect bit is one problem. Producing an image that a blank part will actually boot from is a second, and it is the one that separates a dump from a recovery.