Recover Microcontroller PIC16F506 Binary: A Device With No Interrupt Vector
Most guidance about reading a microcontroller image assumes structures that this device does not have. There is no interrupt vector because there are no interrupts. There is no context save because nothing preempts. There is no data EEPROM because there is nowhere to put it. What remains is a smaller and in some ways harder problem: a single linear program in an array short enough that its whole shape is visible at once and every word matters.
Working on parts like this is a useful corrective, because it strips the job down to its essentials. The image is either right or wrong, and there is not enough of it for the wrongness to hide.
The device in numbers
| Attribute | Value |
|---|---|
| core | baseline, 12-bit |
| program memory | about 1K instruction words |
| data EEPROM | none |
| RAM | under a hundred bytes |
| interrupt sources | none |
| analogue | comparator, plus a converter on this variant |
| package | eight or fourteen pins |
The absence of interrupts is the structural fact. On a mid-range device the image is organised around a handler: code at address zero jumps past a vector to initialisation, the vector at a fixed address jumps to the handler, and the handler’s structure reveals the product’s priorities. Here none of that exists. Address zero is the start of the program, the program runs from beginning to end, and any repetition is a polling loop the engineer wrote by hand.
What a linear image looks like
Because nothing preempts, the code has a distinctive shape. It initialises, then enters a main loop, and every function is called from that loop in a fixed order. Long stretches execute in a predictable sequence, and timing is achieved by counting instruction cycles rather than by waiting on a timer interrupt.
This has two consequences for reading the image.
The first is that the beginning is unusually informative. The first few dozen words configure the oscillator, the I/O directions, the comparator and the analogue channel, and the order of those configuration writes is a direct statement of what the designer considered necessary at startup. On a device with a handler, the same information is scattered.
The second is that delay loops are visible as a structural feature. A counted loop that exists only to waste time appears as a decrement, a test and a branch with nothing inside, and its repeat count is the timing budget of whatever follows. Reading a product’s timing behaviour out of such loops is often easier than reading it out of the rest of the code.
Small arrays demand a different verification strategy
On a large device, statistical reasoning is useful. A single wrong word in sixty thousand is invisible, and the checks that matter are structural — vectors, table extents, configuration plausibility.
On this device a single wrong word is a tenth of a percent of the image, and if it lands in a branch condition or an operand it changes behaviour. The verification has to be absolute rather than structural, which means reading the array more than once and requiring agreement on every word.
The procedure is short.
- Read the array twice, at the intended supply voltage, and compare word by word.
- Re-read any word that disagrees, at a slightly different supply voltage, since a marginal cell often resolves consistently off its nominal operating point.
- Report any word that remains unstable, by address, rather than choosing a value.
- Compute a device-side checksum and a host-side checksum and compare them, to prove the transfer rather than the content.
- Confirm the configuration word decodes to a combination the silicon accepts.
Step three is the uncomfortable one and the one that makes the delivery honest.
The configuration word and the calibration constant
The configuration word on a baseline part controls the oscillator selection, the watchdog, the master clear pin’s function, the code protection and the low-voltage programming option. It sits at a fixed address near the top and it is not code.
On variants of this family with an internal oscillator, a calibration value for that oscillator is programmed by the factory and lives in the same top region. Its exact position relative to the configuration word varies by family, and the safe procedure is the same regardless: read the entire top region, then decode it, rather than assuming a layout.
Where the calibration value is present and the device is being reproduced, the value belongs to the donor die and not to the target. Writing it into a fresh device produces a clock trimmed for the wrong silicon — a small frequency error that keeps everything working and makes every timing-dependent function slightly wrong.
Protection on a part this size
Code protection on this generation blocks the programming interface from reading the array. Because the array is small, the practical consequence is sharper than on a large device: there is no partial result to salvage, no portion of the code that survives the block, and no structural inference that substitutes for the missing words.
What does survive is behaviour. A device with a comparator, an analogue input and a handful of outputs produces observable responses, and on a program this short the responses are often enough to reconstruct the decision logic even when the instructions cannot be read. That is a different kind of deliverable and it should be described as such.
What polling costs, and why it shows up in the image
A linear program responds to events when it next looks. Between looks, nothing happens. The interval between looks is the sum of the worst-case path through the main loop, and every routine the loop calls adds to it.
That has a consequence visible in the code: routines that could be written for clarity are written for speed, and the ones that cannot be made fast enough are moved out of the loop or triggered less often. A product that polls a comparator once per loop has a response time equal to the loop period; one that polls it every tenth iteration has ten times that, and the reason is usually a display multiplex or a serial transfer that cannot be interrupted.
Reading the loop and listing the calls in order, with the delay constants attached, produces the product’s latency budget as a table. That is the single most useful measurement available from an image on this class of device, and it explains most field complaints about a product that misses fast events.
Where the recovered image is actually used
Two customers dominate this class of work. The first maintains equipment built around a part that is no longer in production and needs to be able to program replacement controllers. The second has a board that fails and needs to know whether the failure is in the program or elsewhere.
For the first, the image plus the configuration word plus a note on the calibration value is the whole answer. For the second, the useful artefact is often not the image at all but a comparison between it and a known-good image from a working unit — a difference of one or two words is a diagnosis, and finding it requires both images to have been read with the same convention.
That comparison is worth building into the job from the start. Where two units are available, read both before delivering either.
For the mid-range device where the vector and handler appear and the image acquires the structure this one lacks, PIC16F616 heximal recovery is the direct comparison. The smallest members of the same line, where the array is barely larger and the pin count forces the programming interface to share pins with the application, are covered in PIC12F609 heximal recovery. And for a part with a genuine data array alongside the program, where the scope question reappears, PIC12C671 image copying sets out what the extra region changes.