No announcement yet.

Bonehead Part IV

  • Filter
  • Time
  • Show
Clear All
new posts

  • Bonehead Part IV

    Got the info on config files for 3.1.1. Quick Question are there any operational (the way the code works) or constraints (the amount of memory, time, compilation, or size) differences between these two ways of doing the config files? The reason I ask this is that it is a lot easier for me to annotate and understand these commands and edit them in Method #2.

    Also, does each line need its own __config command or can I simply do the & to replace them all except the first one?



    Method #1:


    Method #2

    ; __config _INTRC_OSC_NOCLKOUT
    ; __config _WDT_ON
    ; __config _MCLRE_ON
    ; __config _IOSCFS_4MHZ
    ; __config _CP_OFF

  • #2
    The CONFIG registers only have 8 bits each. How you write the code doesn't affect those 8-bit registers. Furthermore, the CONFIG settings are only used one time, when you program the PIC. It is not part of active code in operation. Each CONFIG register will require its own section, regardless of how you write it on your screen. Most of the more modern PICs have 2 or more CONFIG Registers; CONFIG1, CONFIG2, and so forth.
    We can crack this cotton PIC'n thang!


    • #3
      I'm not sure if that is a yes or a no. Now i understand that once I write the #CONFIG routine it is only executed once, so it matters little to the program itself.

      But is the second way of writing the CONFIG routine equivalent to making a single line of it, and do I need the _config line in each of the lines. I'm thinking that the semicolon just connects the lines in series, so I ought to be able to just use the & connector. Yes? No?



      • #4
        When you open the Device in the DEVICE_REFERENCE file in the PBP3_1 folder, it is formatted correctly for that device. I just copy/paste the default CONFIGs from the document, then go through and change and add (not all options are listed in the "default" CONFIG example) as needed. I find most of the PIC12_16F devices use the horizontal listing, while the PIC18F devices seem to favor the vertical arrangement. Again, this is from copying from the included PBP file.
        We can crack this cotton PIC'n thang!


        • #5
          When placed within a #CONFIG/#ENDCONFIG block, "__CONFIG" and "CONFIG" are directives that are passed to the MPASMX assembler. You can look them up in the MPLABX help:

          Help > Help Contents, then:
          MPASMX Toolsuite/MPASM Assembler/Directives/__config - Set Processor Configuration Bits
          MPASMX Toolsuite/MPASM Assembler/Directives/config - Set Processor Configuration Bits (PIC18 MCUs)

          PBP's #CONFIG/#ENDCONFIG is the same as ASM/ENDASM, except that #CONFIG always relocates the enclosed code to a specific location in the asm files. Whenever PBP encounters a #CONFIG block, it replaces all previous config directives. The result is that only the last #CONFIG block encountered in the program code will affect the assembly.

          __CONFIG is intended to be used only once per config word. In other words, use the & operators and list the parameter definitions on one line, as in your first example. There are some tricks to make it appear as a vertical list, but this is the simplest, safest format:
                __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_ON & _IOSCFS_4MHZ & _CP_OFF

          CONFIG works differently and only works for PIC18 devices. It can be used repeatedly, once for each parameter definition. Hence the vertical-list format:
              CONFIG FEXTOSC = OFF     ;Oscillator not enabled
              CONFIG RSTOSC = HFINTOSC_64MHZ     ;HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1
              CONFIG CLKOUTEN = OFF     ;CLKOUT function is disabled
              CONFIG CSWEN = ON     ;Writing to NOSC and NDIV is allowed
              CONFIG FCMEN = ON     ;Fail-Safe Clock Monitor enabled
              CONFIG MCLRE = EXTMCLR     ;If LVP = 0, MCLR pin is MCLR; If LVP = 1, RE3 pin function is MCLR
              CONFIG PWRTE = ON     ;Power up timer enabled
              CONFIG LPBOREN = OFF     ;ULPBOR disabled
              CONFIG BOREN = ON     ;Brown-out Reset enabled according to SBOREN
              CONFIG BORV = VBOR_245     ;Brown-out Reset Voltage (VBOR) set to 2.45V
              CONFIG ZCD = OFF     ;ZCD disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON
              CONFIG PPS1WAY = OFF     ;PPSLOCK bit can be set and cleared repeatedly (subject to the unlock sequence)
              CONFIG STVREN = ON     ;Stack full/underflow will cause Reset
              CONFIG DEBUG = OFF     ;Background debugger disabled
              CONFIG XINST = OFF     ;Extended Instruction Set and Indexed Addressing Mode disabled
              CONFIG WDTCPS = WDTCPS_31     ;Divider ratio 1:65536; software control of WDTPS
              CONFIG WDTE = ON     ;WDT enabled regardless of sleep
              CONFIG WDTCWS = WDTCWS_7     ;window always open (100%); software control; keyed access not required
              CONFIG WDTCCS = LFINTOSC     ;WDT reference clock is the 31.0 kHz LFINTOSC
              CONFIG WRT0 = OFF     ;Block 0 (000800-003FFFh) not write-protected
              CONFIG WRT1 = OFF     ;Block 1 (004000-007FFFh) not write-protected
              CONFIG WRT2 = OFF     ;Block 2 (008000-00BFFFh) not write-protected
              CONFIG WRT3 = OFF     ;Block 3 (00C000-00FFFFh) not write-protected
              CONFIG WRT4 = OFF     ;Block 4 (010000-013FFFh) not write-protected
              CONFIG WRT5 = OFF     ;Block 5 (014000-017FFFh) not write-protected
              CONFIG WRT6 = OFF     ;Block 6 (018000-01BFFFh) not write-protected
              CONFIG WRT7 = OFF     ;Block 7 (01C000-01FFFFh) not write-protected
              CONFIG WRTC = OFF     ;Configuration registers (300000-30000Bh) not write-protected
              CONFIG WRTB = OFF     ;Boot Block (000000-0007FFh) not write-protected
              CONFIG WRTD = OFF     ;Data EEPROM not write-protected
              CONFIG SCANE = ON     ;Scanner module is available for use, SCANMD bit can control the module
              CONFIG LVP = ON     ;Low voltage programming enabled. MCLR/VPP pin function is MCLR. MCLRE configuration bit is ignored
              CONFIG CP = ON    
              CONFIG CPD = OFF     ;DataNVM code protection disabled
              CONFIG EBTR0 = OFF     ;Block 0 (000800-003FFFh) not protected from table reads executed in other blocks
              CONFIG EBTR1 = OFF     ;Block 1 (004000-007FFFh) not protected from table reads executed in other blocks
              CONFIG EBTR2 = OFF     ;Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks
              CONFIG EBTR3 = OFF     ;Block 3 (00C000-00FFFFh) not protected from table reads executed in other blocks
              CONFIG EBTR4 = OFF     ;Block 4 (010000-013FFFh) not protected from table reads executed in other blocks
              CONFIG EBTR5 = OFF     ;Block 5 (014000-017FFFh) not protected from table reads executed in other blocks
              CONFIG EBTR6 = OFF     ;Block 6 (018000-01BFFFh) not protected from table reads executed in other blocks
              CONFIG EBTR7 = OFF     ;Block 7 (01C000-01FFFFh) not protected from table reads executed in other blocks
              CONFIG EBTRB = OFF     ;Boot Block (000000-0007FFh) not protected from table reads executed in other blocks

          Charles Leo
          ME Labs, Inc.