Recover MCU 12F508 Code: The Package Decides the Job Before the Silicon Does
Five hundred and twelve instruction words. Twenty-five bytes of RAM. No data EEPROM, no interrupts, one timer, six I/O pins, an internal oscillator fixed at four megahertz, and a price that made it the default choice for a decade of timers, chargers, toys and latching relays. There is nothing about the PIC12F508 that is difficult to understand, and that is precisely why the difficulty of recovering code from one is so often misjudged: people assume small means simple.
The silicon is simple. The work is not, because almost everything that determines whether a job succeeds happens outside the die — in the package, in the fixture, and in the fact that OTP memory has no undo.
What the part actually holds
| Item | Size | Notes for recovery |
|---|---|---|
| program memory | 512 × 12 bits | one-time programmable, no erase |
| RAM | 25 bytes | lost at power down, no recovery value |
| data EEPROM | none | requests for “eeprom” mean the program array |
| config word | one word | oscillator calibration and protection |
| stack | 2 levels | shapes how the code is written, not what is read |
Two facts from that table do most of the work. There is no data EEPROM, so the entire non-volatile content is the instruction array plus one config word — a complete image is under a kilobyte of file. And there are two stack levels, which means the original code was written without nested calls, using repetition where a larger part would have used a subroutine. A recovered image from this part therefore looks odd to anyone expecting conventional structure, and the oddness is authentic rather than an artefact.
Why the eight-pin body sets the ceiling
Programming and reading happen through the in-circuit serial programming interface, which needs five connections: two supply rails, a clock, a data line, and the reset pin held above its normal operating voltage. On an eight-pin device those five signals occupy five of the eight pins. There is no spare pin to trigger a test mode, no second port to sample behaviour while the core is halted, and no room for a probe clip that does not also touch something else.
On a plastic dual-in-line part this is manageable: the leads are on a 2.54 mm pitch and a socket does the work. On the small surface-mount bodies the situation changes. A 2 by 3 millimetre dual flat no-lead package has no leads at all — the contacts are pads underneath, and the only way to reach them is to place the part on a custom footprint or to remove it and treat it as a bare die with a carrier. Every handling step after that is a chance to lose the part, and the part cannot be replaced from stock with the same content.
This is the first thing to establish about a 12F508 job, and it is a physical question rather than an electronic one: what package is on the board, and is the unit worth the risk of removal.
The high-voltage requirement
The reset pin on this family doubles as the programming voltage input. To enter programming mode the fixture must raise it well above the supply rail, typically to around twelve volts, in a defined sequence relative to the clock and data lines.
Two failure modes follow. A fixture that supplies only the logic rail will clock and data the part happily and get nothing back, which looks like a dead device and is not. A fixture that applies the high voltage in the wrong order, or removes it while the clock is still running, can leave the part in an indeterminate state — usually recoverable by a clean power cycle, occasionally not.
On a bench with a socketed part this is a solved problem. On a populated board it is not, because raising one pin to twelve volts while the rest of the circuit is powered can forward-bias protection diodes elsewhere on the net. The usual answer is to isolate the pin, which means the part comes off, which returns the job to the package question.
Reading an OTP array without a second chance
OTP memory is written once. There is no erase cycle, no bulk erase, no way to rewrite a word. From a recovery standpoint that is good news and bad news.
The good news is that the content is stable. A cell that was programmed in 2004 reads the same today unless the charge has leaked, and on this technology the leakage is slow enough that a part stored in a drawer for two decades still reads correctly. There are no wear-levelling artefacts, no half-erased rows, no history of rewrites to untangle.
The bad news is that a word which did not program correctly at manufacture stays wrong forever, and the recovery has to distinguish between three states that all look like data: a word that was deliberately programmed, a word that was never programmed and reads as all ones, and a word that failed to program and reads somewhere between the two. On a twelve-bit word the middle state is visible if you look at the raw values rather than the disassembly. A word reading 0x3FF is empty; a word reading 0x1FF, 0x2FF or 0x3FE in a region that should be code is a programming failure, and it is a property of the original manufacturing step rather than of the read.
The config word and the calibration constant
The config word on this part carries the usual oscillator and reset selections, and — on parts with an internal oscillator — the factory calibration value that trims the four megahertz source to its specified tolerance. On some family members the calibration value lives in the last program word rather than in the config word itself.
This matters at delivery, not at extraction. A delivered image that omits the calibration word will program a blank part and run, at the wrong frequency, with every timing-dependent behaviour shifted. On a design that uses the internal oscillator to time a relay or a charge cycle, the failure is subtle and gets blamed on the recovered code.
The rule that avoids it: the delivered image is the full address range including the last word, with the calibration value called out separately so that a customer who erases and reprograms knows which value must be preserved.
What a complete delivery looks like
Four items, and the fourth is the one that gets forgotten.
The image itself, in a file format whose word convention is stated in a header comment. The config word decoded into bit fields rather than left as a hex value. A note on which addresses read as blank and why, so that a later reader does not assume the array ended early. And a short description of the pin behaviour observed at power-up, which on a design with no readable code is often the only independent evidence that the image is complete.
When the part is the wrong target
Two situations recur. The first is a board that contains a 12F508 in one revision and a 12F509 or a flash-based 12F510 in another, with the same silkscreen. The three parts are pin-compatible and the difference only appears in the top marking and in the memory size returned by the programming interface. Reading the marking before building a fixture saves a wasted session.
The second is a request to recover code from a part that was never programmed — a spare from the production bin. It reads as blank, which is a correct result and not a failure.
For the sibling part where the file format rather than the package is the subject, PIC12F609 heximal covers the record structure in detail. Where a part in the same eight-pin class does have a data EEPROM and therefore a second array to read, PIC16F685 flash sets out the two-switch problem. And where the same small-array job is complicated by an unmarked device whose identity has to be established first, CF755 dump recovery deals with that preliminary step.
The short version
On a 512-word OTP part the memory is not the obstacle. The package is, the high-voltage sequence is, and the absence of any second chance is. Establish the package and the marking first, expect a complete image under a kilobyte, and include the calibration word in what you deliver.