Code protect PIC in MPLAB?

I have searched high and low for this. Must be missing something very obvious.

How do you code protect a PIC mircoprocessor in MPLAB?

Bill Moyers

Reply to
Bill Moyers
Loading thread data ...

On at least some of the PIC chips (the 18F2220 is the one I'm looking at now), code protection is enabled by setting bits in one of the device configuration registers. The specifics of which bits, in which config registers, will protect various ranges of code memory is chip-specific.

So, you'd specify code protection in the source code, in basically the same way you would specify the oscillator type, brownout detection settings, power-up timer enable, and so forth... just define data bytes/words to be programmed at the device-specific address which sets up the configuration registers.

--
Dave Platt                                    AE6EO
Friends of Jade Warrior home page:  http://www.radagast.org/jade-warrior
 Click to see the full signature
Reply to
Dave Platt

At a hardware level, you code protect a Microchip PIC by programming special locations that are outside of the code memory map- called the "Configuration Bits" or something similar.

To create a hex file that specifies how these locations are to be programmed, you typically include some special statements in your assembly or higher-level code that specifies what is to be programmed to 0 from the default 1. It's the same way you program oscillator type, watchdog on/off and similar stuff.

If you look at the data sheets, include files and example and/or template code for a given processor, it should all become obvious. For example, the PIC16F688 has config bits at 0x2007.

The assembly template includes these lines:

list p=16f688 ; directve to define processor

#include ; processor specific variable definitions __CONFIG _CP_OFF & _CPD_OFF & _BOD_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT & _MCLRE_ON & _FCMEN_OFF & _IESO_OFF

(note the double underscore preceding CONFIG)

The inc file (which is where the above constants are defined in the first place) contains these lines:

;========================================================================== ; ; Configuration Bits ; ;==========================================================================

_FCMEN_ON EQU H'3FFF' _FCMEN_OFF EQU H'37FF' _IESO_ON EQU H'3FFF' _IESO_OFF EQU H'3BFF' _BOD_ON EQU H'3FFF' _BOD_NSLEEP EQU H'3EFF' _BOD_SBODEN EQU H'3DFF' _BOD_OFF EQU H'3CFF' _CPD_ON EQU H'3F7F' _CPD_OFF EQU H'3FFF' _CP_ON EQU H'3FBF' _CP_OFF EQU H'3FFF' _MCLRE_ON EQU H'3FFF' _MCLRE_OFF EQU H'3FDF' _PWRTE_OFF EQU H'3FFF' _PWRTE_ON EQU H'3FEF' _WDT_ON EQU H'3FFF' _WDT_OFF EQU H'3FF7' _LP_OSC EQU H'3FF8' _XT_OSC EQU H'3FF9' _HS_OSC EQU H'3FFA' _EC_OSC EQU H'3FFB' _INTRC_OSC_NOCLKOUT EQU H'3FFC' _INTRC_OSC_CLKOUT EQU H'3FFD' _EXTRC_OSC_NOCLKOUT EQU H'3FFE' _EXTRC_OSC_CLKOUT EQU H'3FFF' _INTOSCIO EQU H'3FFC' _INTOSC EQU H'3FFD' _EXTRCIO EQU H'3FFE' _EXTRC EQU H'3FFF'

Each processor can be different. Doing it in C is a similar exercise.

When you check it out, make sure 'Config bits set in code' is checked off and verify the setup is the way you want it in the IDE Configure tab when the code is built. If you look at the emitted hex file, you should be able to see the config bits defined near the end of the file.

formatting link

Best regards, Spehro Pefhany

--
"it's the network..."                          "The Journey is the reward"
speff@interlog.com             Info for manufacturers: http://www.trexon.com
 Click to see the full signature
Reply to
Spehro Pefhany

Configure->Select Device => select your device Configure->Configuration Bits => Look for the code protect

You may need to enlarge the window and drag the columns wider.

My preference is to do this all in a .h file with #pragma config There is a help file in the MPLAB install directory, I think under doc something like PIC18ConfigSet.chm or such. Look in the help file for the C18 compiler.

--
Joe Chisolm
Marble Falls, Tx.
Reply to
Joe Chisolm

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.