Break MCU PIC16F876 Flash: Four Protection Bits Make Sixteen Answers
“The chip is protected” is a sentence that carries almost no information. On this family protection is not a single state but a small set of bits, each acting on a different region, each settable independently, and each with a different consequence for what can be recovered. Two customers can both say “protected” and be describing jobs that differ by a factor of five in effort.
The PIC16F876 is the twenty-eight-pin member with 8192 by 14 bits of program memory, 368 bytes of RAM, 256 bytes of data EEPROM and a ten-bit converter with five channels. Eight thousand words is the largest array in the family, and on the largest array the protection choices matter most, because that is where the code is worth the most.
The four bits and what each one guards
| Bit | Guards | Effect when set | Reversible on an erased part |
|---|---|---|---|
| code protect | the program array | reads through the interface do not return content | yes, by a full erase |
| data protect | the data EEPROM | the 256 bytes are not readable | yes, but the erase destroys them |
| write protect | a region of the program array | self-writes to that region are blocked | yes |
| low-voltage programming | the entry mechanism | entry requires high voltage | yes |
The distinction between the first two is the one that changes jobs. The distinction between the third and the first is the one that changes designs: write protect exists to protect a boot block from an application that might overwrite it, not to protect intellectual property.
The fourth bit is not a protection at all, but it is the one that most often causes a failed session. A field-programmed unit with low-voltage programming disabled needs a twelve-volt entry that a bench fixture may not provide, and the symptom is no communication rather than a refusal.
The combinations that actually occur
Sixteen combinations exist; four are common in shipped product.
| Code | Data | Situation | What is available |
|---|---|---|---|
| clear | clear | in-house or unprotected | everything, by the interface |
| set | clear | commercial product, calibration not secret | data and config by interface, program by die |
| clear | set | rare: calibration protected, code not | program by interface, data by die or infer |
| set | set | fully closed | config only, everything by die |
The second row accounts for most jobs, and it has an economic consequence worth stating: the part of the content that a customer most often wants — the unit-specific calibration — is frequently readable while the program is not, so a job can sometimes be solved at the EEPROM level alone without touching the die.
The third row is the one that surprises people. It is uncommon but real, and it usually indicates a product whose value is in its characterisation rather than its firmware, such as an instrument calibrated per sensor.
Reading the bits before the array
The configuration word on this family is readable through the interface in most states, which means the bits can be determined before any irreversible step. That single read converts an unknown job into a known one.
Two cautions. A read that returns a configuration word which claims everything is unprotected while the array returns a pattern indicates a damage or interface fault rather than a genuine open device — the config word and the array should agree. And the config word itself reads as all ones on a blank device, which on a part with protection set is not the same as a part that has never been programmed.
The cross-check is the array: a protected array returns an identical value at every address; a blank array returns all ones at every address; a programmed array returns varied values. Three cases, three diagnoses.
What each combination costs in effort
| Combination | Extraction effort | Analysis effort | Total shape of job |
|---|---|---|---|
| open | minutes | the whole engagement | a reading project |
| code protected | die work, single pass | the whole engagement | a recovery project |
| data protected | die work plus inference | the whole engagement | a reconstruction project |
| both protected | die work | the whole engagement | the largest case |
The first row explains why quoting by part number is unreliable: for an unprotected part the work is analysis, and it is the same analysis regardless of the part. For a protected one, the work is recovery, and the analysis is a second phase that a customer may not need.
What an erase costs when the data is protected
There is one situation in which the reversibility of the program array is not a gift. When code protect is set and data protect is also set, the program array can be made readable by erasing the device — but the erase takes the EEPROM with it, and on a unit whose calibration has never been backed up, that trade is not one to make casually.
The sequence to think through before touching anything: erasing gives the code and destroys the data, reading through the die gives both but consumes the package, and leaving the unit alone gives neither but preserves the option. On a product with a single surviving unit, the third choice is sometimes correct while a replacement is sourced.
On a unit where only the code is protected, the erase is cheap by comparison — the data stays, and the code comes back. That asymmetry is worth stating to a customer before they authorise work, because the assumption is usually that an erase is harmless.
Eight thousand words and what it changes
On the largest array in the family, three things become true that are not true on a two-kilobyte part.
The image is too large to read by inspection, so the reachability analysis is mandatory rather than optional. The program will contain a boot region, an application region and probably a table region, and the boundaries between them are a design statement. And the code is likely to be compiler output rather than hand-written assembly, which changes the reading: regular function prologues, a consistent register convention, and pointer-based access rather than absolute addresses.
That last difference is worth stating to a customer who expects the readability of older hand-written code. Compiler output is more systematic and less idiomatic: it is easier to navigate and harder to understand, because the structure is the compiler’s rather than the author’s.
Where the protection mechanism on an OTP part is a different physical thing entirely, PIC16C771 firmware sets out the contrast. Where the maintainable-source conversion follows the recovery, PIC16F873 software covers the four passes. And where a sibling’s unit-to-unit comparison is used to find what is unit-specific, PIC16F874 eeprom follows the parameter block.
The short version
Four bits, four guards, sixteen combinations. Read the configuration word first, decide which combination applies, and quote the job from the combination rather than from the word “protected” — because the difference between the common cases is the difference between an afternoon and a project.