3.4.7 How Can I Prevent Misuse of My Code?
First, many devices with flash program memory allow all or part of this memory to be write protected. The device Configuration bits need to be set correctly for this to take place; see 5.2.4 Configuration Bit Access and your device data sheet.
Second, you can prevent third-party code being programmed at unused locations in the program memory by filling these locations with a value rather than leaving them in an unprogrammed state. You can choose a fill value that corresponds to an instruction or set all the bits so values cannot be further modified (consider what will happen if your program somehow reaches and starts executing from these filled values).
The compiler’s HEXMATE utility (see 8.2 Hexmate) has the capability to fill unused locations and can be requested using a command-line driver option (see 4.6.11.10 Fill Option). As HEXMATE only works with HEX files, this feature is only available when producing HEX/COF file outputs (as opposed to binary, for example), which is the default operation.
And last, if you wish to make your library files or intermediate p-code
files available to others but do not want the original source code to be viewable, then
you can obfuscate the files using the -mshroud
option (see 4.6.1.21 Shroud Option).