Break IC PIC16F84 Code: Two Customers, Two Deliveries, One Part
Very few microcontrollers have had a service life this long. The PIC16F84 — 1024 by 14 bits of program flash, 68 bytes of RAM, 64 bytes of data EEPROM, thirteen I/O pins, one timer, no converter — was the part that introduced a generation of engineers to microcontrollers, and it is still inside equipment that is still in use: door controllers, timers, coin-operated machines, laboratory fixtures built in the 1990s and never replaced because they still work.
That longevity is why a request for its code is usually urgent and almost never straightforward. The part is easy to read. The difficulty is that “read the code” means two different things depending on who is asking, and the two answers are not interchangeable.
The two requirements
| Requirement | Who asks | What they need | What they do with it |
|---|---|---|---|
| a device that works | maintenance, service, replacement | image plus configuration, verified on a blank part | program a replacement board |
| a design that can be changed | the equipment owner’s engineer | structure, constants, named memory map | modify behaviour, add a feature |
The first is a cloning job. The second is an analysis job. Both begin with the same read, and the read is perhaps a tenth of the second one.
Mixing them up is expensive in both directions. A service company that receives an annotated listing and no verified image has been given the wrong artefact; an engineering team that receives a hex file and a patched binary has been given something they cannot maintain.
What a clone actually requires
A clone is not a copy of the program array. It is a device that behaves identically, which requires four things to be right at once.
The program image, over the full address range, with a stated word convention. The configuration word, decoded — on this part it selects the oscillator type, the watchdog, the code protection and the power-up timer, and any one of those being different changes behaviour. The data EEPROM’s 64 bytes, which on many designs hold a serial number or a set-up value written at production. And the calibration value for the internal oscillator, if the design uses it.
The fourth item is the one that gets missed. A design using the internal oscillator with the factory trim value absent will run, at a frequency a few percent off, and every timing in the product will be slightly wrong. On a timer application that means a clock that gains a minute a day; on a serial link it means a baud rate that works on one unit and not on the next.
Verification of a clone is behavioural, not file-based: program a blank part, fit it, and run the product through its functions. Comparing hex files proves the file is the same; it does not prove the device works.
What an analysis actually requires
The image is the input. The output is a description.
Three artefacts carry it. A memory map that names the 68 bytes of RAM by role, since the original variable names are gone and only the usage pattern remains. A constant table giving the timer reload values, the delay counts and the comparison thresholds, with the physical quantity each corresponds to. And a control-flow description: what the main loop does, what the interrupt handler is for, and where the state variables live.
On this part the analysis is unusually tractable, because the code was written by hand in an era when compilers for eight-pin parts produced poor code. Hand-written assembly has regular shapes: a main loop with a polling sequence, a timer interrupt with a reload, a display or output routine with a table. Those shapes are easier to read than optimised compiler output, and they document the design intent more directly.
Why the two clients want different files
A maintenance company wants the smallest set of files that will produce a working board: image, config, EEPROM, and a note on the oscillator value. Extra documentation is noise to them.
An engineering team wants the opposite: the image is a necessary attachment, and the value is in the map and the notes. Giving them a patched binary instead of a description is a common failure of the service model, because it appears to solve the problem — the device now does the new thing — while leaving them unable to do the next thing.
The practical resolution is to ask one question at the start: is the goal to replace the unit, or to change it. The answer determines the deliverable, the effort and the price, and it is a thirty-second conversation.
The protection case on this part
Many units were shipped with code protection engaged, because the designs were commercial and the protection bit cost nothing. When protection is set, the array does not read through the interface, and the job moves to the die.
Two things are worth knowing before that step. The configuration word is often still readable, which tells you whether the data EEPROM is also protected. And on parts of this vintage, the date code is a useful predictor of how the protection behaves, because mask revisions across a long production life are not identical.
If the part was never protected — which happens on in-house equipment built for internal use — the entire job is a socket, a read and a decode, and it can be done in an afternoon.
Delivering in a form that survives
Whatever the requirement, three things should accompany the files.
A statement of the word convention used in the image, because this family is old enough that tools disagree about it. A record of the configuration word as decoded fields rather than a hex value. And a short note on the observed behaviour of the source unit at power-up, which is the only independent evidence that the image corresponds to the product described.
Where a sibling part in the same package shows what an interrupted write looks like in an image, PIC16F83 eeprom recovery covers the damaged-device case. Where the same cloning question is asked of an OTP part that cannot be reprogrammed, PIC16C711 program breaking sets out the constraints. And where the design is an analogue instrument rather than a logic controller, PIC16C717 program shows what the constants reveal.
The short version
One part, two services. A clone needs four items verified on real hardware; an analysis needs a map, a constant table and a control-flow description. Ask which one is wanted before starting, because the reading is the cheap part of both.