3 Overview of Code Protection Features in 8-bit PIC Microcontrollers

The Program Flash Memory (PFM), Data Flash memory (DFM) or EEPROM and Configuration Bytes sections of 8-bit PIC microcontrollers contain the user’s proprietary application firmware, data and device configurations, which often require protection against unauthorized access and device malfunctioning.

The code protection features incorporated into 8-bit PIC microcontrollers effectively block any attempts to read or write to the program and data flash memory regions of a microcontroller.

The various sections of the device’s program memory can be categorized based on the type of data they store, read/write privileges, and level of protection offered by the 8-bit PIC microcontrollers.

Table 3-1 highlights the classification of 8-bit PIC microcontroller memory sections based on the type of data they store and the available protection features.

Table 3-1. Protection Features in 8-bit PIC Microcontrollers
Memory RegionMemory SectionAvailable ProtectionImpact of Bulk Erase Operation
Program Flash MemoryProgram MemoryRead and writeCompletely erases the memory
Data Flash MemoryData EEPROM
Configuration BytesConfiguration BytesWrite
Program Flash MemoryUser IDNo Protection
Device Configurations DIANo ProtectionNo Effect
DCI
Dev ID
Rev ID

Table 3-2 highlights the protection features available for the different sections of device memory in the 8-bit PIC microcontrollers.

Table 3-2. Code Protection Features Offered for Various Memory Sections in 8-bit PIC Microcontrollers
Memory RegionMemory SectionType of ProtectionAssociated Configuration BitProhibited ActionRemarks
Program Flash MemoryBoot BlockWrite(1, 3)WRTBWrite operation through ICSP and self-write operationBulk Erase operation through ICSP interface disable the read/ write protection
Code(2, 3)CPRead and write operations through ICSP
Application BlockWrite(1, 3)WRTAPPWrite operation through ICSP and self-write operation
Code(2, 3)CPRead and write operations through ICSP
SAF BlockWrite(1, 3)WRTSAFWrite operation through ICSP and self-write operation
Code(2, 3)CPRead and write operations through ICSP
Data Flash MemoryData EEPROMWrite(1, 3)WRTDWrite operation through ICSP and self-write operation
Code(2, 3)CPDRead and write operations through ICSP
Configuration BytesConfiguration BytesWrite(1, 3)WRTCWrite operation through ICSP and self-write operation
Note:
  1. Self-write operation is not allowed.
  2. Self-write operation is allowed.
  3. Internal access through CPU to read the memory is allowed.

The code protection feature allows the device to be protected from unauthorized access. Both program memory protection (CP) and data memory protection (CPD) settings are referred to as code protection.

The CP Configuration bit protects the entire program memory space from external read and write operations. When CP = 0, external read and write operations of program memory are inhibited, and a read will return all zeros. The CPU can continue to read the program memory, regardless of the protection bit settings.

The CPD Configuration bit protects the entire data EEPROM memory space from external read and write operations. When CPD = 0, external read and write operations of the data EEPROM memory are inhibited, and a read will return all zeros.

The CP and CPD settings are controlled independently. Self-writes and NVM read functions to the program memory are unaffected by any of the code protection settings.

The write protection configuration bits protect the respective memory sections from self-write operations. Any attempts to write to a protected location will set the WRERR bit.

The code protection (CP, CPD) and write protection (WRTAPP, WRTSAF, WRTD, WRTC, WRTB) settings can be disabled through a Bulk Erase operation, which will also erase all memory locations.