PostHeaderIcon PIC16F677 Firmware: Why Clock Configuration Has Nothing to Do With Code Protection

The PIC16F677 is a 20-pin device from Microchip’s low-pin-count Flash family: 2048 × 14 words of program memory, 128 bytes of SRAM, 256 bytes of data EEPROM, 18 I/O pins, twelve 10-bit A/D channels, two comparators and an SSP module with I²C address masking. It belongs to the PIC16F631/677/685/687/689/690 group, which shares one die family and one datasheet.

There is a persistent claim about this part that needs correcting plainly: that the protection mechanism can be bypassed by manipulating the clock source mode. It cannot. The oscillator configuration and the code-protect bit are separate subsystems that share a configuration word and nothing else. The confusion is understandable — both affect how a board behaves at power-up — but it leads analysis in entirely the wrong direction.

What the PIC16F677 actually contains

Item PIC16F677
Package 20-pin PDIP, SOIC, SSOP
Program memory 2048 × 14-bit Flash (3.5 KB)
Data SRAM 128 bytes
Data EEPROM 256 bytes
I/O pins 18 (17 bidirectional + 1 input-only)
A/D converter 12 channels, 10-bit
Comparators 2, with programmable CVREF
Serial SSP, SPI and I²C with address mask
Timers Timer0 (8-bit), Timer1 (16-bit), Timer2 (8-bit)
Programming ICSP, high voltage on MCLR

The clock tree, and what it actually does

The oscillator module offers external modes (LP, XT, HS crystal or resonator, and EC for an externally generated logic clock) and two internal oscillators: an 8 MHz HFINTOSC and a 31 kHz LFINTOSC. Selection is made by FOSC2:FOSC0 in the configuration word, and the running program can switch between them at runtime through the system clock select control.

Several behaviours in this subsystem are genuinely unusual and worth knowing:

Oscillator start-up timer. In LP, XT and HS modes, the OST waits 1024 oscillator cycles before releasing the device from reset. During that window the program counter does not advance and execution is suspended. That is a real delay — at 32 kHz in LP mode, 1024 cycles is over 30 milliseconds.

EC mode frees a pin. With an external clock on OSC1, OSC2 becomes a general-purpose I/O. The OST is bypassed entirely in EC mode, so there is no start-up delay after power-on or after wake from Sleep.

The core is fully static. Stopping the external clock halts the device with all data intact; restarting it resumes as if no time had passed. This is a design property of the core, not a protection feature, and it is frequently mistaken for one because it produces surprising bench behaviour.

Fail-safe clock monitor and two-speed start-up. FCMEN watches the clock and switches to the internal oscillator on failure. IESO allows a fast internal start followed by a handover to the crystal.

None of these touch program memory. There is no path from FOSC2:FOSC0, FCMEN or IESO to the read-protect logic. Clock configuration determines when and how fast code executes; CP determines whether an external programmer can read it. Changing the first has no effect on the second.

The configuration word at 2007h

The 16F677 shares its configuration register layout with the 16F684 — the same register in the programming specification covers PIC16F631/677/684/685/687/688/689/690. Bits 13:12 are unimplemented and read as 1.

Bit Field Meaning
11 FCMEN Fail-safe clock monitor; 1 = enabled
10 IESO Internal/external switchover; 1 = enabled
9:8 BOREN1:BOREN0 Brown-out detect selection
7 CPD Data memory code protection; 1 = disabled
6 CP Program memory code protection; 1 = disabled
5 MCLRE 1 = MCLR pin function, 0 = alternate function
4 PWRTE Power-up timer; 0 = enabled (inverted)
3 WDTE Watchdog; 1 = enabled
2:0 FOSC2:FOSC0 Oscillator selection

Note what is absent: there is no LVP bit. This part is programmed by applying high voltage to MCLR. And there is no partial protection — CP covers all 2048 words or none of them.

The programming specification also carries the clause that decides most practical questions:

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

So the logical sequence “clear CP, then read” is self-defeating on this device. Clearing CP bulk-erases the memory it was protecting.

Where the clock-protection confusion comes from

Three observations get conflated.

First, EC mode changes what a board does at power-up — no OST delay — so a device that fails to respond on a bench may appear to “behave differently” when the clock mode is changed. That is a timing effect.

Second, with MCLRE = 0 the MCLR pin becomes a digital input and MCLR is internally tied to VDD. Any procedure that expects to assert reset externally stops working, and the device looks unresponsive in a way that can be mistaken for protection.

Third, the static core means a halted clock freezes execution rather than resetting the device. A stopped device holding its state looks, from outside, like a locked one.

All three are clock and reset behaviour. None requires the protect bit to be involved, and none changes it.

What actually determines the outcome

For a PIC16F677 in unknown condition, the questions that matter are:

Is the die the part the marking claims? The 631, 677, 685, 687, 689 and 690 share one die family, and a remarked 16F685 sold as a 16F677 is a realistic scenario on the secondhand market. The device ID word at 2006h settles it. This is not a hypothetical: the pin counts and ADC channel counts differ within the group while the package can be identical.

What is the CP and CPD state? Readable from the configuration word at 2007h during programming, regardless of protection. This tells you whether the logical path is open or closed, and it costs nothing to check before committing to any approach.

What lives in the 256 bytes of EEPROM? With CPD at bit 7, external reads of that block can be blocked independently of Flash. On this part the EEPROM is where per-unit calibration typically sits — A/D gain and offset, comparator thresholds, bandgap-derived reference trims. An image without it produces a device that boots and reads the wrong values.

Why this work is requested

These parts sit in appliances, sensors and small power stages where the firmware is a few kilobytes and the product lifetime is a decade. The failure pattern is always the same shape: the board is the only surviving copy of the design, and the maintenance decision depends on getting the image off it. Related notes cover the 14-pin PIC16F684 built on the same core and configuration word, the smaller PIC16F676 in the same family, and the 8-pin PIC12F609.

FAQ

Can the protection be bypassed by changing the oscillator mode? No. FOSC2:FOSC0 selects a clock source. CP gates external reads of program memory. They are separate fields acting on separate subsystems.

Does EC mode affect code protection? No. It bypasses the oscillator start-up timer and frees OSC2 as I/O. Nothing else.

Does clearing CP let you read the firmware? No. Removing code protection erases the entire program memory on this family.

How do you tell a 16F677 from a 16F685? Read the device ID word at 2006h. The two share a datasheet and a die family, and both are available in 20-pin packages.

Is there partial code protection? No. CP is a single bit covering all 2048 words.

Conclusion

The PIC16F677 is a good reminder that a configuration word is a container, not a mechanism. It holds an oscillator selection, a watchdog enable, brown-out settings and two protect bits, and those fields do entirely different jobs. Reading the clock field and drawing conclusions about code protection is a category error — one that sends analysis toward the oscillator module when the answer is sitting in bits 6 and 7.

Related reading

Comments are closed.