Break IC PIC16F689 Software: The Config Word Is a Wiring Diagram
Most requests for this part arrive with the word “software” and an expectation of source code. What arrives first, in practice, is a description of hardware: the configuration word states which oscillator is in use and which pins are repurposed, the port setup in the first few hundred instructions states which pins drive and which listen, and the peripheral initialisation states which serial format the board speaks. On a design with no schematic, that is the documentation.
The PIC16F689 is a twenty-pin part: 4096 by 14 bits of program flash, 256 bytes of data EEPROM, 256 bytes of RAM, twelve analogue channels into a ten-bit converter, a synchronous serial port that can be SPI or I2C, an asynchronous serial port, two comparators, and an eight-megahertz internal oscillator. It is a general-purpose part, which means the same silicon appears in designs that share nothing but the pin count — and the code is what distinguishes them.
What the config word states
| Field | Values | What it tells you about the board |
|---|---|---|
| oscillator selection | internal, external crystal, external clock | whether a crystal should be present |
| reset pin function | reset, or digital input | whether an external supervisor exists |
| low-voltage programming | enabled or not | whether in-circuit access was intended |
| code protect | set or clear | whether the image should be readable at all |
| data protect | set or clear | whether the EEPROM is treated as secret |
| watchdog | enabled or not | whether the design tolerates a hang |
Read as a group, these are constraints on the circuit rather than preferences of the programmer. An external clock selection on a board with no crystal means the clock arrives from elsewhere — a host processor, a bus, a dedicated oscillator — which changes the guess about what the board does. A reset pin configured as a digital input means the design needed one more I/O line and gave up the reset, which is only safe on a board with a clean supply.
Why the oscillator field comes first
Every timing conclusion downstream depends on the clock. The code contains delay loops, baud rate divisors and timer reload values, and all three are computed from a frequency the programmer assumed. If the config word says the internal oscillator is in use and the code’s delay loops are calibrated for four megahertz, the loop counts should be consistent with four. If they are consistent with twenty, the part was clocked from an external source despite what the config word says — which happens when a design changes late and the config is inherited.
Checking that consistency takes a minute and settles the largest source of error in reconstructing behaviour.
Ports: direction, then function
The code writes the direction registers early, usually within the first dozen instructions after reset. Those writes are the pin budget: a bit set to input means the pin is fed from outside, a bit cleared means it drives. Combined with the analogue selection registers, they also say which pins are doing conversion rather than logic.
Three patterns are worth recognising.
A port where every pin is an output and every write is a fixed pattern is a display or a relay bank — the code is a truth table, and the image is easy to read because the table is in the code.
A port where one pin toggles in a tight loop with a delay between transitions is a clock or a bit-banged serial line. If the timing matches a known protocol, the peripheral configuration was bypassed and the format is in the code rather than in a register.
A port where a single input is polled repeatedly with debounce delays is a button or a sensor. Those loops are where the product behaviour lives, and they are the part of the image that a customer usually wants annotated.
The serial peripheral states the bus
The synchronous serial port can be configured as SPI master, SPI slave or I2C, and the choice is made in a control register rather than in the config word. That register write is the answer to “what is this board connected to”.
SPI at a high clock with a chip select on a port pin means an external memory, a display controller or another processor. I2C means a sensor or a small EEPROM, and the address in the code identifies the part number. Slave mode means this device is not the master, which changes the interpretation of the whole design: it is a peripheral, and its behaviour is defined by what the master expects.
The counterpart register also carries the clock divider, which combined with the oscillator gives the bus rate — the number that has to match for a replacement to work in place of the original.
Comparators and the analogue front end
Two comparators with a programmable reference mean the design can make threshold decisions without an ADC conversion. The reference value is written to a register at start-up, and that value, read against the supply voltage, states the threshold the product uses.
This is where recovered code turns into product knowledge. A comparator threshold at 40 percent of a five-volt rail is a battery monitor. A threshold that changes with a value read from the data EEPROM is a calibration. A pair of comparators with hysteresis and a latch is a zero-crossing detector. None of that is visible from the instruction listing alone; it becomes visible when the peripheral setup is read as a circuit description.
What “software” delivers here
| Deliverable | Content | Why it matters |
|---|---|---|
| image | full program array, stated convention | reproducible programming |
| data EEPROM | 256 bytes, raw | settings that the code depends on |
| config word | decoded bit fields | states oscillator, reset, protection |
| annotated disassembly | entry, interrupt, peripheral init, main loop | the part a person can work with |
| hardware note | ports, bus, thresholds, clocks | replaces a missing schematic |
The last two are the difference between a dump and a result. A customer who receives only the first two has a file; a customer who receives all five has a design they can maintain.
Protection, stated plainly
If code protect is set, the array reads as a repeating pattern through the programming interface, and the recovery moves to the die itself. The config word usually remains readable, so the oscillator, reset and data-protect states are known before the die is opened — which is useful, because it tells you whether the EEPROM is also going to need the same treatment.
If only data protect is set, the program array is available normally and the 256 bytes are not. This combination is worth checking before quoting, because the work is entirely different and the customer’s expectation is usually the opposite of what the bits say.
For the sibling in the same family where the two non-volatile arrays are the subject, PIC16F685 flash sets out the separation. Where the part in the same pin count has a quarter of the memory and therefore very different code structure, PIC16F610 binary covers the density problem. And where the same identification step has to be done from the config word alone on a part with no readable code, PIC16F677 firmware is the closer comparison.
The short version
Read the config word first, decode it, and write down what it implies about the board. Then read the port setup and the peripheral initialisation, and write those down too. By the time the instruction listing is annotated, most of the schematic exists — and that description, not the hex file, is what makes the recovery useful.