Conditional default config's


+ Reply to Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869

    Default Conditional default config's

    I wish I could have a define, something like
    Code:
    DEFINE DCFG 1
    in my program. Then when it compiles, the default configs in the .INC would be skipped. Is this hard to do? I am happy to add an IF Then to my inc's if someone wants to point me at how to pass the variable's to the INC file.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default Re: Conditional default config's

    I have not tried it with configs but an include file might work.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869

    Default Re: Conditional default config's

    I have been trying this:
    Code:
    ifdef DCFG
      LIST
            __CONFIG    _CONFIG1L, _CPUDIV_NOCLKDIV_1L & _USBDIV_OFF_1L
            __CONFIG    _CONFIG1H, _FOSC_HS_1H & _PLLEN_OFF_1H & _PCLKEN_ON_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
            __CONFIG    _CONFIG2H, _WDTEN_ON_2H & _WDTPS_512_2H
    endif
    then in my program
    Code:
    DEFINE DCFG 1
    the most I can figure is the DEFINE is not being passed to the .INC file. So either it can't , or I just don't know how to do it. I am hoping I just don't know how yet.
    Now I am pretty sure this will always evaluate false as I never get the overwrite error. If i change to
    Code:
    ifndef DCFG
    I always get the error. So I think the code added to the .INC works, just have no way to pass DCFG
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default Re: Conditional default config's

    Bert,

    Comment out the default configs in the .inc file like normal.
    Code:
    ;****************************************************************
    ;*  18F4520.INC                                                 *
    ;*                                                              *
    ;*  By        : Leonard Zerman, Jeff Schmoyer                   *
    ;*  Notice    : Copyright (c) 2010 microEngineering Labs, Inc.  *
    ;*              All Rights Reserved                             *
    ;*  Date      : 05/21/10                                        *
    ;*  Version   : 2.60a                                           *
    ;*  Notes     :                                                 *
    ;****************************************************************
            NOLIST
        ifdef PM_USED
            LIST
            "Error: PM does not support this device.  Use MPASM."
            NOLIST
        else
            LIST
            LIST p = 18F4520, r = dec, w = -311, w = -230, f = inhx32
            INCLUDE "P18F4520.INC"   ; MPASM  Header
    ;        __CONFIG    _CONFIG1H, _OSC_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
    ;        __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
    ;        __CONFIG    _CONFIG3H, _CCP2MX_PORTC_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
    ;        __CONFIG    _CONFIG4L,  _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L
            NOLIST
        endif
            LIST
    EEPROM_START EQU 0F00000h
    BLOCK_SIZE EQU 32
    Copy the defaults or create your own in a .cfg file like this ...

    18F4520.cfg
    Code:
    ASM
      ifndef CONFIGOVERRIDE
        __CONFIG    _CONFIG1H, _OSC_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
        __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
        __CONFIG    _CONFIG3H, _CCP2MX_PORTC_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
        __CONFIG    _CONFIG4L,  _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L
      endif
    ENDASM
    INCLUDE that file from the .bas file
    Code:
    '****************************************************************
    '*  18F4520.BAS                                                 *
    '*                                                              *
    '*  By        : Leonard Zerman, Jeff Schmoyer                   *
    '*  Notice    : Copyright (c) 2004 microEngineering Labs, Inc.  *
    '*              All Rights Reserved                             *
    '*  Date      : 12/29/04                                        *
    '*  Version   : 2.46                                            *
    '*  Notes     :                                                 *
    '****************************************************************
    BANKA   $0000, $007F
    BANK0   $0080, $00FF
    BANK1   $0100, $01FF
    BANK2   $0200, $02FF
    BANK3   $0300, $03FF
    BANK4   $0400, $04FF
    BANK5   $0500, $05FF
    'EEPROM  $F00000, $F000FF
    LIBRARY "PBPPIC18"
            include "PIC18EXT.BAS"
    PORTL   VAR     PORTB
    PORTH   VAR     PORTC
    TRISL   VAR     TRISB
    TRISH   VAR     TRISC
            include "PBPPIC18.RAM"
            include "18F4520.cfg"
    '*----------------------* EOF 18F4520.BAS *---------------------*
    Then in your main program, you can do what you wanted.
    Code:
    DEFINE CONFIGOVERRIDE
    ASM
        __CONFIG    _CONFIG1H, _OSC_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
        __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
        __CONFIG    _CONFIG3H, _CCP2MX_PORTC_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
        __CONFIG    _CONFIG4L,  _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L
    ENDASM
    HTH,
    Last edited by Darrel Taylor; - 8th May 2011 at 01:58.
    DT

  5. #5
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869

    Default Re: Conditional default config's

    Thanks Darrel. I suppose that is what Dave was pointing at, but I didn't get it. That will do what I want, (be able to use defaults conditionally). So we CAN pass things to the .BAS just not the .INC?

    Now to refresh the python skills or work on liberty basic and parse the files so I can be lazy and not do it by hand. OK I know it will be far easier to just open the files and change them. But what will I learn that way??
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default Re: Conditional default config's

    That is not what I was thinking.
    I did not know
    DEFINE CONFIGOVERRIDE
    even existed.

    Thanks Darrel!
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869

    Default Re: Conditional default config's

    Hi Dave,
    I don't think
    Code:
    DEFINE CONFIGOVERIDE
    is a pre existing anything. I think it could have been
    Code:
    DEFINE BERTISLAZY
    and have the same effect. In the .CFG file, the
    Code:
    ifndef CONFIGOVERIDE
    or
    ifndef BERTISLAZY
    tells PBP or MPASM (not clear here) to see if the DEFINE exists. If not then do the following code. If it does exist then endif.

    I am going to have a play with this and verify this is how it works. I will report back if anyone is intrested.

    BTW, the reason I want this is so I can test forum code that uses the default config's, without having to change things all the time for my own code.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  8. #8
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default Re: Conditional default config's

    I will report back if anyone is intrested.
    I am interested.
    Dave
    Always wear safety glasses while programming.

  9. #9
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default Re: Conditional default config's

    Quote Originally Posted by cncmachineguy View Post
    So we CAN pass things to the .BAS just not the .INC?
    ...
    tells PBP or MPASM (not clear here) to see if the DEFINE exists. If not then do the following code. If it does exist then endif.
    DEFINE's are currently only passed on to the assembler unchanged, and do not directly affect PBP code.

    Those DEFINES are added to the ASM after the .inc file, but before the .bas file.
    This allows them to affect the library code that is included from the .bas file, but the items in the .inc file have already been processed.

    The example above was for an 18F.
    For a 16F, the .cfg file should be a little different
    Code:
    ' -- 16F877a.cfg --
    ASM
      ifndef PM_USED
        ifndef CONFIGOVERRIDE
          __config _XT_OSC & _WDT_ON & _LVP_OFF & _CP_OFF
        endif
      endif
    ENDASM
    The usage in the main program is essentially the same.
    Code:
    DEFINE CONFIGOVERRIDE
    @      __config _HS_OSC & _WDT_ON & _LVP_OFF & _CP_OFF
    A better method has been developed by Charles and Leonard that allows defaults to be overridden automatically, and the new style CONFIG statements to be used in your programs as well.
    It will be available in the coming months, so you may not want to spend to much time editing all the files.
    Last edited by Darrel Taylor; - 8th May 2011 at 19:17.
    DT

  10. #10
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,578

    Default Re: Conditional default config's

    A better method has been developed by Charles and Leonard that allows defaults to be overridden automatically, and the new style CONFIG statements to be used in your programs as well.
    It will be available in the coming months, so you may not want to spend to much time editing all the files.
    Hi, Darrel

    Petty good news !!! re-Commenting defaults @ each PBP patch release became a bit boring ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  11. #11
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869

    Default Re: Conditional default config's

    Oh too cool!!! Does this count as me getting my wish?
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts