PostHeaderIcon Break IC PIC16F685 Flash: Two Non-Volatile Arrays, Two Different Switches

A request for this part almost always says “flash”. The PIC16F685 has two non-volatile arrays, and only one of them is flash. They are protected by different bits, they fail in different ways, and on a bench they are read through different sequences. A job scoped on the assumption that there is a single array tends to end with half the content delivered and a customer asking why the calibration values are missing.

The device itself is a twenty-pin mid-range part: 4096 by 14 bits of program memory, 256 bytes of data EEPROM, 256 bytes of RAM, twelve analogue inputs into a ten-bit converter, two comparators, an internal oscillator good to a few percent without trimming, and the usual complement of timers and capture-compare. For extraction none of that list matters as much as the fact that the config word contains two protection bits rather than one.

The two arrays at a glance

Array Size here Config bit Typical content Read by
program flash 4096 words code protect instruction stream, constant tables, calibration constant core-side sequence, word addressable
data EEPROM 256 bytes data protect thresholds, serial numbers, user settings, run counters serial interface, byte addressable
config word one word not protected as data oscillator mode, reset behaviour, both protect bits separate read, always last

The third row is the one that causes arguments. The config word sits at the top of the program map, but it is not part of the program array in any functional sense: it is read at reset by hardware, not fetched by the core. Tools that treat it as “the last word of the image” will either include it in a checksum that should not contain it, or drop it from a file that must contain it.

Why the protect bits are deliberately separate

Code protect and data protect exist as separate bits because they answer different questions. Code protect is about the instruction stream — the intellectual property. Data protect is about the contents of the EEPROM, which on this part often holds values that are worth more than the code: a calibration table derived from a production-line characterisation, a customer-specific threshold set, a rolling counter that the vendor does not want reset.

A part can be shipped with code protected and data open, and this combination is common in designs where the code is generic but the EEPROM contents are unique per unit. It can also be shipped the other way round, though that is rare because code protection also blocks the reading path that most people use to reach the EEPROM.

The practical consequence: the first question about any 16F685 is not “can it be read” but “which of the two bits is set”. The answer determines whether the job is a straightforward read or a decapsulation, and it changes the shape of the quote before any work begins.

Reading the program array

The program array is word organised. The core fetches fourteen-bit words, the programming interface accepts them, and the image that comes back has to be converted to bytes with a stated convention. On this family the low byte is stored first and the top two bits of the high byte carry nothing, which means a file length of 8192 bytes for 4096 words. A file of 4096 bytes is not a shorter version of the same thing; it is the packed convention, and mixing the two produces an image where every pair of words is fused into one.

The first word is the check. On a working image it decodes to a jump or a load, never to an arbitrary value. If word zero does not decode, the convention is wrong, and no amount of downstream verification will fix it.

Reading the data EEPROM

The EEPROM is byte organised and reached through a two-register interface from the core: address in one register, data in the other, a control bit to start the access. Through the programming interface it is a separate command with its own address space starting at zero, which is convenient — the EEPROM address space does not collide with the program space, so both images can be carried in one session without ambiguity provided the file records which is which.

Two details cost people time. The first is that an erased EEPROM cell reads as all ones, so a 256-byte image of 0xFF is a legitimate result and not a failed read; it means the unit never wrote its EEPROM. The second is that a partially written row — power lost mid-write — leaves a mix of old and new bytes with no checksum to detect it. On a field failure this is exactly the state that is being investigated, so the raw bytes matter and a “cleaned” image destroys the evidence.

What the config word tells you before you start

The config word is readable on most units even when code protection is set, and it is worth reading first rather than last. It states the oscillator mode, whether the reset pin is configured as a reset or as an input, whether low-voltage programming is enabled, and the state of both protection bits.

Low-voltage programming deserves a note. When it is enabled, the part can enter programming mode without the high voltage that the standard sequence uses, which is convenient for in-circuit work and irrelevant for bench work on a removed die. When it is disabled, the high-voltage sequence is mandatory, and a fixture that does not supply it will appear to communicate and will return nothing useful.

Failure modes that belong to this part specifically

Three are worth knowing.

The first is a program image that reads cleanly but disassembles into nonsense at one address. On a 4K-word part, address 0x0005 is the interrupt vector on some configurations and ordinary code on others depending on how the design is built. A single misplaced word there is usually a reading artefact, not a corrupt program.

The second is a data EEPROM that reads consistently but does not match the code’s expectations — a threshold that the code compares against is outside the range the algorithm accepts. This usually means the EEPROM was written by a production fixture after programming, and the unit being read is a service replacement rather than the original.

The third is code protection that appears to be off because the config word says so, while the array still reads as a repeating pattern. That pattern is the protection behaviour, not content, and it is the single most common false positive in automated triage.

Scoping the job in one question

What the request says What is actually wanted What the job becomes
“read the flash” instruction stream program array read, config word separately
“get the eeprom” 256 bytes of settings data read, raw bytes preserved, no cleaning
“clone the chip” a programmable unit program + EEPROM + config, plus a build check
“recover the code” maintainable source image, then disassembly with segment boundaries

Four different jobs, one part number. The paragraph of clarification that separates them is shorter than the rework that follows from guessing.

For the four-kilobyte sibling in the same generation, where the small array and the eight-pin package change the fixture rather than the protection, PIC16F684 binary recovery covers the other end of the family. For the eight-pin OTP parts where there is no EEPROM to read at all, PIC12F508 code recovery shows what the job looks like when there is only one array. And where the same two-array problem appears on a part with a serial peripheral that has to be identified from the config word, PIC16F689 software takes the next step.

The short version

Two arrays, two protect bits, two read paths, one config word that describes both. Reading the config word first tells you which job you are quoting, and delivering two clearly labelled files instead of one merged blob prevents the question that otherwise arrives a week later.

Comments are closed.