PostHeaderIcon Breaking a PIC16F684: Why Turning the Lock Off Is Not the Same as Reading the Code

The PIC16F684 is a 14-pin part from Microchip’s low-pin-count Flash family: 2048 × 14 words of program memory (3.5 KB), 128 bytes of SRAM, 256 bytes of data EEPROM, 12 I/O pins, an eight-channel 10-bit A/D converter, two analog comparators and an Enhanced CCP module that can drive four PWM outputs with programmable dead time. It is a common choice for small motor drives, LED supplies, sensor front ends and battery chargers.

Its protection model is simpler than the PIC16F87X generation — one CP bit, one CPD bit, no partial ranges. And that simplicity is exactly what makes the common description of it wrong. The frequently repeated line is that code protection can be “turned off” and the memory then read. On this part, those two operations cannot both happen.

What the PIC16F684 actually contains

Item PIC16F684
Package 14-pin PDIP, SOIC, TSSOP
Program memory 2048 × 14-bit Flash (3.5 KB)
Data SRAM 128 bytes
Data EEPROM 256 bytes
I/O pins 12
A/D converter 8 channels, 10-bit
Comparators 2, with programmable CVREF
PWM ECCP, 1/2/4 channels with dead band
Timers Timer0 (8-bit), Timer1 (16-bit), Timer2 (8-bit)
Programming ICSP, high voltage on MCLR

The 14 pins are fully allocated: 12 are I/O, and of the remaining two, one is VDD and one is VSS. RA3 doubles as MCLR. There is no spare pin, which is why the MCLRE bit matters here in a way it does not on larger packages.

The configuration word at 2007h

The word is 14 bits wide but only the lower 12 are implemented — bits 13:12 read as 1.

Bit Field Meaning
13:12 — Unimplemented, read as 1
11 FCMEN Fail-safe clock monitor; 1 = enabled
10 IESO Internal/external switchover; 1 = enabled
9:8 BOREN1:BOREN0 Brown-out detect: 11 on, 10 on except Sleep, 01 via SBODEN, 00 off
7 CPD Data memory code protection; 1 = disabled
6 CP Program memory code protection; 1 = disabled
5 MCLRE 1 = RA3 is MCLR, 0 = RA3 is digital input
4 PWRTE Power-up timer; 1 = disabled, 0 = enabled
3 WDTE Watchdog; 1 = enabled
2:0 FOSC2:FOSC0 111 RC, 110 RCIO, 101 INTOSC, 100 INTOSCIO, 011 EC, 010 HS, 001 XT, 000 LP

Two absences are worth naming explicitly, because they are what most write-ups get wrong.

There is no LVP bit. This device is programmed by applying high voltage to MCLR/RA3. There is no single-supply programming path to consider, and correspondingly no fixture variation based on a low-voltage enable. The MCLRE bit changes whether RA3 behaves as a reset pin or a digital input during normal operation, but it does not remove the programming voltage requirement.

There is no partial protection. CP is one bit covering all 2048 words. There is no equivalent of the PIC16F87X’s CP1:CP0 field with its intermediate ranges.

The line that changes the analysis

Microchip’s PIC12F6XX/16F6XX programming specification attaches two notes to the CPD and CP bits, and they are easy to read past:

The entire data EEPROM will be erased when the code protection is turned off. The entire program memory will be erased when the code protection is turned off.

Read together with the CP definition — protection is enabled by clearing the bit to 0 — the sequence implied by “just clear CP and read it” is: clear CP, which triggers a bulk erase, which destroys the content you were trying to read.

This is not a quirk of the 16F684. It is the standard Microchip behaviour for the family, and it is the single most useful fact to hold when evaluating any claim about this chip. Unprotecting and recovering are mutually exclusive operations on a protected device. What remains is the physical route, which is a question about the die rather than about a configuration bit — and the answer depends on the silicon revision, not on the software.

That distinction matters because it changes what “feasibility” means. On a PIC16F87X with CP1:CP0 = 10, feasibility is a matter of reading the configuration word and doing arithmetic on address ranges. On a 16F684 with CP = 0, the configuration word tells you only that the logical path is closed. Nothing in the register map tells you whether the die is one where the physical path exists.

MCLRE and the 14-pin constraint

With MCLRE = 0, RA3 becomes a digital input and MCLR is internally tied to VDD. On a 14-pin part this is the only way to recover a pin for the application, so it is common in production firmware — and it changes how the assembled board behaves under any bench procedure that expects to drive MCLR externally.

It does not change the programming requirement. Programming still uses the MCLR/RA3 pin at high voltage. The bit affects runtime behaviour, not the programming interface.

What a complete image contains

  • 0000h–07FFh — 2048 × 14-bit program Flash
  • 2000h–2003h — four user ID locations
  • 2006h — device ID word
  • 2007h — the configuration word
  • 256 bytes of data EEPROM, separate from the Flash address space, protected by CPD

The 256 bytes of EEPROM are frequently where the interesting constants live on this part: ADC offset and gain corrections, PWM dead-time values tuned per motor, or a calibrated current-sense threshold. A recovered image without them produces a board that runs and measures wrong — a failure mode that is much harder to diagnose than one that does not start.

Why this part is still worked on

The 16F684 sits in products with long service lives and short development budgets: pump controllers, LED drivers, small appliances, adapters. The economics are the same every time — replacing a production line because a 3.5 KB binary was never archived is not a realistic option, and the device on a working board is the only copy that exists.

Related notes cover the 20-pin PIC16F677 firmware built on the same core with a larger pin count, the smaller PIC16F676 in the same family, and the older 8-pin PIC12F609 that shares this protection model.

FAQ

Can the CP bit be cleared without losing the program? No. The programming specification states that the entire program memory is erased when code protection is turned off.

Does the 16F684 support low-voltage programming? No. Its configuration word has no LVP bit; programming requires high voltage on MCLR/RA3.

Is there partial protection like on the PIC16F87X? No. CP is a single bit covering all 2048 words.

What does CPD protect? External reads of the 256-byte data EEPROM. Internal reads and writes are unaffected regardless of CP and CPD.

Does MCLRE = 0 disable programming? No. It makes RA3 a digital input at runtime with MCLR tied internally to VDD. Programming still applies high voltage to that pin.

Conclusion

The PIC16F684 is the clearest example of why configuration-bit reasoning has limits. One CP bit, no LVP, no partial ranges — the register map is trivial to read and tells you almost nothing about what is possible. The clause that decides the matter is the one stating that removing protection erases memory. Everything after that is a question about the die.

Related reading

Comments are closed.