Datasheet

PIC16F57
DS41208C-page 12 Preliminary © 2007 Microchip Technology Inc.
4.0 CODE PROTECTION
For the PIC16F57, once code protection is enabled, all
program memory locations above 0x3F read all ‘0’s.
Program memory locations 0x00-0x3F are always
unprotected. The ID locations and the Configuration
Word read out in an unprotected fashion. It is possible
to program the ID locations and the Configuration Word
once CP
is enabled.
4.1 Disabling Code Protection
It is recommended that the following procedure be
performed before any other programming is attempted.
It is also possible to turn code protection off (CP = 1)
using this procedure. However, all data within the
program memory will be erased when this
procedure is executed, and thus, the security of the
code is not compromised.
To disable code-protect:
a) Enter Programming mode
b) Execute Bulk Erase Program Memory (001001)
c) Wait T
ERA
4.2 Embedding Configuration Word
and ID Information in the Hex File
4.3 Checksum Computation
4.3.1 CHECKSUM
Checksum is calculated by reading the contents of the
PIC16F57 memory locations and adding up the
opcodes up to the maximum user addressable location,
(e.g., 0x7FF for the PIC16F57). Any carry bits exceed-
ing 16 bits are neglected. Finally, the Configuration
Word (appropriately masked) is added to the check-
sum. Checksum computation for the PIC16F57 is
shown in Table 4-1.
The checksum is calculated by summing the following:
The contents of all program memory locations
The Configuration Word, appropriately masked
Masked ID locations (when applicable)
The Least Significant 16 bits of this sum is the
checksum.
The following table describes how to calculate the
checksum for each device.
TABLE 4-1: CHECKSUM COMPUTATIONS
(1)
To allow portability of code, the programmer is
required to read the Configuration Word and ID
locations from the hex file when loading the hex file.
If Configuration Word information was not present in
the hex file, then a simple warning message may be
issued. Similarly, while saving a hex file, Configura-
tion Word and ID information must be included. An
option to not include this information may be
provided.
Microchip Technology Incorporated feels strongly
that this feature is important for the benefit of the end
customer.
Note: The checksum calculation differs
depending on the code-protect setting.
The Configuration Word and ID locations
can always be read regardless of the
code-protect setting.
Device
Code
Protect
Checksum*
Blank
Value
0x723 at 0
and Max
Address
PIC16F57 OFF SUM[0x000:0x7FF] + CFGW & 0x00F + 0xFF0 0x07FF 0xF647
ON SUM[0x000:0x3F] + CFGW & 0x00F + 0xFF0 + SUM_ID 0x17B6 0xFD22
Legend: CFGW = Configuration Word
SUM[a:b] = [Sum of locations a to b inclusive]
SUM_ID = ID locations masked by 0xF then made into a 16-bit value with ID0 as the Most Significant
nibble.
For example, ID0 = 0x1, ID1 = 0x2, ID2 = 0x3, ID3 = 0x4, then SUM_ID = 0x1234.
*Checksum = [Sum of all the individual expressions] modulo [0xFFFF]
+ = Addition
& = Bitwise AND
Note 1: Checksum shown assumes that SUM_ID contains the unprotected checksum.