• AVR Freaks

Hot!pragma Configuration Words ON-OFF

Author
EfYuri
Starting Member
  • Total Posts : 30
  • Reward points : 0
  • Joined: 2016/08/09 22:38:24
  • Location: 0
  • Status: offline
2021/01/26 21:48:51 (permalink)
0

pragma Configuration Words ON-OFF

Hi, I have a trouble (which I made by myself) with switching Configuration Words of PIC16, maybe it has a solution. I found nothing on forum, sorry if this question has already been answered.
 
In ".h" file of the project I defined ON = 1 and OFF = 0, so all regular hardware registers and states of program flags reading comfortably. But not Configuration Words, because they have own ON-OFF meanings. For example "PWRTE: Power-Up Timer Enable bit" has inverted value: 1 - disable, 0 - enable, and it conflicts with my ON-OFF define.
How should I properly isolate Configuration Words from the rest of program or maybe smth else?
Now Configuration Words are located in the same .c file with device initialization and interrupt functions.
post edited by EfYuri - 2021/01/26 22:03:18
#1

10 Replies Related Threads

    ric
    Super Member
    • Total Posts : 29861
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: pragma Configuration Words ON-OFF 2021/01/26 22:08:51 (permalink)
    +5 (5)
    Move all your #include lines for header files to AFTER the config settings.
    That's how the XC8 user guide recommends you do it, and also when you generate the config bits using MPLABX it tells you the same thing.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    mad_c
    Super Member
    • Total Posts : 1289
    • Reward points : 0
    • Joined: 2010/12/12 17:48:27
    • Location: Brisbane, Australia
    • Status: offline
    Re: pragma Configuration Words ON-OFF 2021/01/26 22:11:12 (permalink)
    +4 (4)
    Hi,
     
    The user's guide states:
     
    It is recommended that the setting-value pairs be quoted to ensure that the preprocessor does not perform macro substitution of these tokens, for example:
    #pragma config "BOREN=OFF"
     
    which would allow you to have your own defines that do not interfere with the configuration. But additionally, moving these pragmas to a source file of their own would be even better.
     
    Jeff.
     
    #3
    ric
    Super Member
    • Total Posts : 29861
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: pragma Configuration Words ON-OFF 2021/01/26 22:16:04 (permalink)
    +5 (5)
    mad_c
    ...
    The user's guide states:
     
    It is recommended that the setting-value pairs be quoted to ensure that the preprocessor does not perform macro substitution of these tokens, for example:
    #pragma config "BOREN=OFF"

    Did anyone point that out to the MPLABX config bit editor authors?

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #4
    EfYuri
    Starting Member
    • Total Posts : 30
    • Reward points : 0
    • Joined: 2016/08/09 22:38:24
    • Location: 0
    • Status: offline
    Re: pragma Configuration Words ON-OFF 2021/01/26 22:41:19 (permalink)
    0
    Ow, I've been using mplab for 5 years now and didn't notice that. Good point to read manual carefully. I'll try to test both methods on Program Memory Self-Write Protection word which has "11" value for OFF.
     
    #5
    EfYuri
    Starting Member
    • Total Posts : 30
    • Reward points : 0
    • Joined: 2016/08/09 22:38:24
    • Location: 0
    • Status: offline
    Re: pragma Configuration Words ON-OFF 2021/01/26 22:52:28 (permalink)
    +2 (2)
    Yes,
    moving includes after Config OR quotation marks for setting-value pairs "WRT = OFF" solves the trouble.
    Thank you very much.
    #6
    GlennP
    Super Member
    • Total Posts : 852
    • Reward points : 0
    • Joined: 2009/03/29 15:04:55
    • Location: El Paso County, CO, USA
    • Status: offline
    Re: pragma Configuration Words ON-OFF 2021/01/27 00:15:55 (permalink)
    0
    EfYuri ... Program Memory Self-Write Protection word which has "11" value for OFF.

     
    All configuration defaults are '1' bits (the erased state).  That is why one sees Protect=OFF have the 0b11 value.  The default (erased) state is no Self-Write protection.
     
    When I first used PICs (lo these many years) I was initially taken aback by the sense of the bits.  Until I realized erasing the memory produced all 1's and those values were the defaults.
     
    GP
    #7
    ric
    Super Member
    • Total Posts : 29861
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: pragma Configuration Words ON-OFF 2021/01/27 01:38:10 (permalink)
    +2 (2)
    glennp17321
    All configuration defaults are '1' bits (the erased state).  That is why one sees Protect=OFF have the 0b11 value.  The default (erased) state is no Self-Write protection.

    It's a little more complex than that..
    Each "#pragma config" setting interprets the parameters in a unique way, depending upon what item is being set.
    Sometimes "ON" will mean "1", and sometimes it will mean "0", or even "0b101" etc...
    If something #defines "ON" to a constant value, it totally bypasses this context senstivity.
     
     
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #8
    1and0
    Access is Denied
    • Total Posts : 12080
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: pragma Configuration Words ON-OFF 2021/01/27 08:32:25 (permalink)
    +1 (1)
    ric
    Each "#pragma config" setting interprets the parameters in a unique way, depending upon what item is being set.

    The configuration definitions for the #pragma config are defined in the .cfgdata files.
     

    Sometimes "ON" will mean "1", and sometimes it will mean "0", or even "0b101" etc...

    ... for example, ON=1 for Watchdog Enable, while ON=0 for Code Protection bits.
     
    #9
    Murton Pike Systems
    Super Member
    • Total Posts : 223
    • Reward points : 0
    • Joined: 2020/09/10 02:13:01
    • Location: 0
    • Status: offline
    Re: pragma Configuration Words ON-OFF 2021/01/27 13:03:13 (permalink)
    +1 (1)
    "Windows" "Target memory views" "configuration bits"
    Go in there and set config bits accordingly then click on "generate source code to output"
    Stick it at top of your code and should run fine.
    Its a god send.
     
    #10
    ric
    Super Member
    • Total Posts : 29861
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: pragma Configuration Words ON-OFF 2021/01/27 14:54:56 (permalink)
    +1 (1)
    nigelwright7558
    "Windows" "Target memory views" "configuration bits"
    Go in there and set config bits accordingly then click on "generate source code to output"
    Stick it at top of your code and should run fine.
    Its a god send.

    "top of your code" is very relevant here.
    As already described above, including a header file before it, which redefines "OFF" or "ON", will kill it.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #11
    Jump to:
    © 2021 APG vNext Commercial Version 4.5