Menu

pic code protection bits

Help
2016-04-09
2016-04-10
  • tony golding

    tony golding - 2016-04-09

    im just curious as to how gcb works with regard to commands for the pic code protection bits.

    the pics config registers show the protection as being on (set) when each bit is set to zero and off when the appropriate bit is set to 1.

    using gcb commands to set the config when it comes to code protection i just need some clarification, the gcb commands CPD_ON, CP_ON do they refer to the bits in the sense of yes the code is protected or simply as yes the CP bit is set on meaning code protection off?

    if that makes sense i just wanted to verify they either refer to the bits state as i am assuming or if the gcb commands are in fact setting them inverse i.e CP_ON would instead set the bit for code security on rather than the bit being off if set as per the datasheet.

    tony

     
  • William Roth

    William Roth - 2016-04-10

    Hi Tony

    As an example, refer to the datasheet for PIC12F1840. (See Page 42)

    There are 3 bits for Code Protection:

    CP
    CPD
    WRT

    Notice that in the datasheet these bits are "overscored". Technically, that means the actual bit names are:

    NOT CP
    NOT CPD
    NOT WRT

    This means that the function related to the bit is active when the bit is 'NOT'
    (or in simpler terms a zero)

    Text editors do not generally support overscore fonts, so Microchip assumes that you understand in the Datasheet what the overscore bar means. Therefore, in code, the overscore bar is assumed with CP, CPD, & WRT (and others). GCB does not invert anything here, but instead follows the convention required by MPASM (Asembler).

    So when you use #config WDT=ON, you are turning the function related to the bit "ON" and not necessarily the bit itself.

    So when using #config Bitname = ON:

    1) If a bit name has an overscore in the datasheet, then bitname=ON will clear the bit in the register to "0"

    2) If a bitname does not have an overscore, bitname = ON will set the bit to "1".

     

    Last edit: William Roth 2016-04-10
  • tony golding

    tony golding - 2016-04-10

    thanks bill, i did end up messing around with mplab and reading one of my chips with the code protection set on and off with the gcb commands.

    with gcb comand CP_ON ect i was able to read back some data for each line of the hex at the beginning and end of each line but the data between was pure zeroes and setting the bits CP_OFF ect i was able to get back a hex file that i could reload straight onto another chip and run correctly.

    thanks for the explanation bill, i was not too sure if it would set the bit on as a 1 meaning no protection as per datasheet but thankfully as you pointed out it does indeed set the function on or off, it took a while getting mplab to co-operate to test it lol but its good to have additional clarification/knowledge to ensure i dont accidentally end up leaving my code up for grabs to some unscrupulous customers armed with the means to read it.

    tony

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.