Announcement

Collapse
No announcement yet.

Do Not comment the CONFIGS

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Do Not comment the CONFIGS

    I have to give Charles Leo and Leonard Zerman a big round of applause here.

    One of the most annoying tasks when creating a PBP program has been changing the default configuration bits that are specified in the .inc files. I'm sure you've seen the "Overwriting Previous Address" error a few times. Then after you comment one, the next patch won't run until you re-install PBP.

    Well that's a thing of the past ... PBP3 has added a #CONFIG/#ENDCONFIG block.
    Anything in a #CONFIG/#ENDCONFIG block will override (replace) the default configuration.

    For example, adding this snippet from the manual to your code is all you need to configure a 16F877A.

    Code:
    'Config for 16F877A
    #CONFIG
        __config _XT_OSC & _WDT_ON & _LVP_OFF & _CP_OFF
    #ENDCONFIG
    The defaults will be replaced with the new configs.
    See section 4.9 in the new manual.

    With 18F's you can even use the new style config directive that looks something like this ...

    Code:
    #CONFIG
        CONFIG OSC   = HS
        CONFIG XINST = OFF
        CONFIG WDTPS = 512
    #ENDCONFIG
    PBP3 Manual : Microchip Datasheets - 10F, 12F, 16F, 18F
    Never download a PIC datasheet from anywhere but microchip.com

  • #2
    That's great to hear! Whoo hoo! (Applause heard from in front of a computer in Gilroy, CA)

    Also like many of the new descriptions in the manual! Nice!

    Comment


    • #3
      I'll take a modest bow for conceptualizing the method. Leonard honed the logic and made it work.

      I'd like to point out that one of my goals in the restructuring of PBP was to remove ANY foreseeable need to edit the device include files (.PBPINC files). If anyone can think of a reason why the PBPINC would need to be edited by the user, please post.

      Because of our licensing system, we will no longer need to provide minor updates via patch files. Users can simply download the latest trial version and their existing activation will bring it to life. The PBPINC files will be overwritten in the process and any edits will be lost.

      An edited copy of the PBPINC can be placed in the project source folder and the compiler will use it instead of the original file, but my desire is to alleviate the need to do so.
      Charles Leo
      ME Labs, Inc.
      http://melabs.com

      Comment


      • #4
        With the new option, I can't see any reason for anyone to ever mess with an include file.
        Regards,

        Bruce
        http://www.rentron.com

        Comment


        • #5
          Here's an example of how you can set the configuration bits according to the chip being compiled for.
          It uses the Conditional Compile directives (#IF/#ELSE/#ENDIF) along with the #CONFIG blocks.

          Only the configs for the selected chip will be used.
          And if any other chip besides the 25K20 or 25K22 are selected, it will give an error.

          Code:
          #IF __PROCESSOR__ = "18F25K22"
              #config
                  CONFIG  FOSC = HSHP
                  CONFIG  WDTEN = OFF
                  CONFIG  PWRTEN = ON
                  CONFIG  BOREN = OFF
                  CONFIG  PBADEN = OFF
                  CONFIG  MCLRE = INTMCLR
                  CONFIG  LVP = OFF
                  CONFIG  DEBUG = OFF
                  CONFIG  XINST = OFF
              #endconfig
              ANSELA = 0   ; All Digital
              ANSELB = 0
              ANSELC = 0
          #ELSE
              #IF __PROCESSOR__ = "18F25K20"
                  #config
                      CONFIG  FOSC = HS
                      CONFIG  WDTEN = OFF
                      CONFIG  PWRT = ON
                      CONFIG  BOREN = OFF
                      CONFIG  PBADEN = OFF
                      CONFIG  MCLRE = OFF
                      CONFIG  LVP = OFF
                      CONFIG  DEBUG = OFF
                      CONFIG  XINST = OFF
                  #endconfig
                  ANSEL = 0  ; All Digital
                  ANSELH = 0
              #ELSE
                   #ERROR "This program does not support the " + __PROCESSOR__
              #ENDIF
          #ENDIF
          Note that it also sets the ANSEL? registers differently for each chip.
          Anything else specific to a particular chip can be set this way too.
          PBP3 Manual : Microchip Datasheets - 10F, 12F, 16F, 18F
          Never download a PIC datasheet from anywhere but microchip.com

          Comment


          • #6
            This works really well. I guess one could make a config using Darrel's example for all the pics they mostly use, then just include that in each program.

            I must say, the config setup clearly answers my wishlist for conditional configs . I am sure it was already in the works before I wished for it, but it is still pretty neat.

            If I could just get that header wizard (hint hint) . but using the example above, it is a great work around. I can just spend lots of time building a huge header for my pics, then add to it as I add to the collection. And NEVER again build headers each time.
            -Bert
            MPLAB 8.7, WIN7 64 - Home Premium, PK2, PK3, Microchip ICD2 & 3.

            Comment


            • #7
              Darrel,
              In using your code in post #5 of this thread for using the same PBP code but with different micros I have run into a situation that I though would work, but it doesn't in using the conditional #IF/Then statements.

              Code:
              #IF __PROCESSOR__ = "18F25K22"
                  UART_Buff_Error    var  RCSTA1.1
                  UART_Frame_Error var  RCSTA1.2 
                  UART_Rx_EN         var  RCSTA1.4
                  UART_Pwr            var  RCSTA1.7
                  ANSELA = %00000001   ' All Digital except A1 for ADC batt input
                  ANSELB = 0           ' All Digital
                  ANSELC = 0           ' All Digital 
                  
              #ELSE
                  #IF __PROCESSOR__ = "18F2525"
                  UART_Buff_Error    var  RCSTA.1
                  UART_Frame_Error var  RCSTA.2 
                  UART_Rx_EN         var  RCSTA.4
                  UART_Pwr            var  RCSTA.7
                  #ELSE
                       #ERROR "This program does not support the " + __PROCESSOR__
                  #ENDIF
              #ENDIF
              I have code where I am turning ON/OFF the HW UART and checking for errors in different routines in my code. It would be nice to have one PBP source code that I can easily compile for two different micros. Since the RCSTA register has the same function but two different names, I was hopping to use the conditional compile statements above to automatically take care of this issue. Unfortunately the above code does not compile as it sees duplicate variable names.
              Is this a bad example for the use of the #IF/THEN statements or is there a different way to do this successfully.

              Thanks,
              Terry

              Comment


              • #8
                Hi Terry,

                Your code should be OK.
                Are you getting compiler errors?

                If you are just seeing the red x's in MicroCode Studio, you can ignore them.
                MicroCode doesn't know about the conditional compiling, and can't tell if variables or labels get used only once or not.
                PBP3 Manual : Microchip Datasheets - 10F, 12F, 16F, 18F
                Never download a PIC datasheet from anywhere but microchip.com

                Comment


                • #9
                  Hi Darrel,
                  I have been using the above code very successfully and just ignoring the red X's in Microcode studio. I now need to add a third PIC to the list which is a PIC18F26K22, it is almost identical to the PIC18F25K22, so the settings are all the same. I was hoping I could simply add an OR operation to the first line, but it didn't work. I can certainly add another nested IF THEN, but is there a cleaner way to do this, thanks.

                  Comment


                  • #10
                    I'm not sure why your OR didn't work, but this will ...
                    Code:
                    #IF __PROCESSOR__ = "18F25K22" OR __PROCESSOR__ = "18F26K22"
                    PBP3 Manual : Microchip Datasheets - 10F, 12F, 16F, 18F
                    Never download a PIC datasheet from anywhere but microchip.com

                    Comment


                    • #11
                      Thanks Darrel,
                      I did not add the "_Processor_=", I only added the OR with processor name in quotes.

                      Comment


                      • #12
                        Manual?

                        Can someone point me to the manual referenced above "The defaults will be replaced with the new configs. See section 4.9 in the new manual."

                        The one that I found on the melabs website appears to still be for 260 and section 4.9 talks about String Constants...
                        http://melabs.com/resources/index.htm#Manuals
                        or
                        http://melabs.com/downloads/PBP_Manual_0609_260.pdf

                        Thank you,
                        Rodney

                        Comment


                        • #13
                          You can get the Manual and any updates to PBP3 from ...
                          http://pbp3.com/download.html
                          PBP3 Manual : Microchip Datasheets - 10F, 12F, 16F, 18F
                          Never download a PIC datasheet from anywhere but microchip.com

                          Comment

                          Working...
                          X