Presetting Configuration Fuses (PIC Defines) into your Program


+ Reply to Thread
Results 1 to 40 of 83

Hybrid View

  1. #1
    Join Date
    Nov 2004
    Location
    Saskatchewan Canada
    Posts
    189


    Did you find this post helpful? Yes | No

    Default

    So in PBC NOT pro there is no @ DEVICE command so I assume there is another way to set fuses and pin defaults or is it only done in the programmer itself?

    Further if you did MCLR_OFF are you telling the chip not to look for 5 volts on start up?

    Thanks,

    Bart

    I don't have PBC so can't answer your question regarding it. One day I'll go and get myself a copy just for the fun of it. With MCLR_OFF, the PIC handles it's Power-On RESET internally allowing you to use that pin for other purposes. - Melanie

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Red face

    Hi, Mel ...

    There's a little problem in that using MPLAB ( 7.01 ) and Picstart ...

    When compiling ( PM or MPASM ), everything seems to go pretty well, except this "double definition error"
    You can program the chip ... yesss ...wonderful !!!

    BUT ... the corresponding HEX file is never stored on your Hard Disk !!!

    Rather difficult to send the hex file to poor waiting friends.

    as it is impossible to cancel the error message ...Do you have a solution ???

    I just want to set OSC to HS ( in PbPlibs, it's Ok but boring ,I know.) and PWRTE to ON ( Where to find it ? )

    Alain

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    O.K. This is ask really often. Worth to be discussed NOW!

    What to do if i get "overwriting previous address content" error message?

    This error is return by PBP because your configuration fuse overwrite 'PBP default'. If you open with notepad, in PBP directory, the .INC file of your PIC, let's say 16F628, the file will look like this
    Code:
    ;**************************************************************
    ;*  16F628.INC                                                  *
    ;*                                                              *
    ;*  By        : Leonard Zerman, Jeff Schmoyer                   *
    ;*  Notice    : Copyright (c) 2002 microEngineering Labs, Inc.  *
    ;*              All Rights Reserved                             *
    ;*  Date      : 09/27/02                                        *
    ;*  Version   : 2.43                                            *
    ;*  Notes     :                                                 *
    ;**************************************************************
            NOLIST
        ifdef PM_USED
            LIST
            include 'M16F62x.INC'   ; PM header
            device  pic16F628, xt_osc, wdt_on, pwrt_on, mclr_on, lvp_off, protect_off
            XALL
            NOLIST
        else
            LIST
            LIST p = 16F628, r = dec, w = -302
            INCLUDE "P16F628.INC"   ; MPASM  Header
            __config _XT_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
            NOLIST
        endif
            LIST
    So if you try to define HS oscillator, wich is already define, you'll overwrite the previous content of the PBP setting.

    To fix it, just comment those lines :
    Code:
    ;device  pic16F628, xt_osc, wdt_on, pwrt_on, mclr_on, lvp_off, protect_off
    OR
    Code:
    ;__config _XT_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
    depending what you are using to compile your code, MPASM or PM.

    OR some will prefer to edit those line directly... as you wish...
    Where can i find the configuration fuse for my PIC ?

    All the configuration fuse are in the according .INC file located in the MPLAB directory. In MPLAB 7.01, the default directory, i suppose, is C:\Program Files\Microchip\MPASM Suite.

    If you open the appropriate .INC file, you will find all the configuration fuse for your PIC at the end of the file.

    looks like this for a 16F628...only the end
    Code:
    ;==========================================================================
    ;
    ;       Configuration Bits
    ;
    ;==========================================================================
    
    _BODEN_ON                    EQU     H'3FFF'
    _BODEN_OFF                   EQU     H'3FBF'
    _CP_ALL                      EQU     H'03FF'
    _CP_75                       EQU     H'17FF'
    _CP_50                       EQU     H'2BFF'
    _CP_OFF                      EQU     H'3FFF'
    _DATA_CP_ON                  EQU     H'3EFF'
    _DATA_CP_OFF                 EQU     H'3FFF'
    _PWRTE_OFF                   EQU     H'3FFF'
    _PWRTE_ON                    EQU     H'3FF7'
    _WDT_ON                      EQU     H'3FFF'
    _WDT_OFF                     EQU     H'3FFB'
    _LVP_ON                      EQU     H'3FFF'
    _LVP_OFF                     EQU     H'3F7F'
    _MCLRE_ON                    EQU     H'3FFF'
    _MCLRE_OFF                   EQU     H'3FDF'
    _ER_OSC_CLKOUT               EQU     H'3FFF'
    _ER_OSC_NOCLKOUT             EQU     H'3FFE'
    _INTRC_OSC_CLKOUT            EQU     H'3FFD'
    _INTRC_OSC_NOCLKOUT          EQU     H'3FFC'
    _EXTCLK_OSC                  EQU     H'3FEF'
    _LP_OSC                      EQU     H'3FEC'
    _XT_OSC                      EQU     H'3FED'
    _HS_OSC                      EQU     H'3FEE'
    
            LIST
    Last edited by mister_e; - 5th March 2005 at 18:04.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Wink

    Hi,Steve

    Thank you for the answer, I finally found what I was looking for : in the M16F84.inc,and others .inc all the values do not appear !!!
    So, I simply had to add them ...

    My question was more about how to have the Hex file written on the HDD ...
    as it appears in the program window and can be downloaded to the Pic.

    IF this stupid uncancellable error message was only a Warning things would be so simpler !!! ( errorlevel - ... etc )

    So, I ask it again : is there something reasonnably possible to memorize the content of the program window ??? ( yeah, write it on a paper .... Thanks !!! )

    Mhhh ... fore core calculation, have a look here :
    http://www.epcos.com/web/generator/W...locale=en.html

    read you soon
    Have a nice Sunday

    Alain

  5. #5
    RUBiksCUbe's Avatar
    RUBiksCUbe Guest


    Did you find this post helpful? Yes | No

    Talking

    Oh yeah! Got it working!! I needed to put in the PIC defines in the beginning. It was giving me those errors because I didn't need the line:

    @ INCLUDE "P18F252.INC" ; MPASM Header

    I'm not sure why I dont need it, but I think its because 18F252.INC has an identical line in it, so I was including it twice. Thanks soooo much!!!

  6. #6
    eoasap's Avatar
    eoasap Guest


    Did you find this post helpful? Yes | No

    Default

    Hi, i'm using the 18F452 chip so required to use MPASM compiler through Picbasic.
    if i try to set a fuse using ONLY (for example) the line below

    @ __config _LVP_OFF

    i get this error:
    x.asm 112: symbol not previously defined (_LVP_OFF)
    x.asm 112: argument out of range (not a valid config register address)



    if i put the following code:
    @ INCLUDE "P18F452.INC" ; MPASM Header
    @ __config _LVP_OFF

    i get errors like the following:
    '1042: duplicate label ("DDRA" or redefining symbol that cannot be redefined)
    1607: superseding current maximum RAM and RAM map
    120: symbol not previously defined (_LVP_OFF)
    etc..

    i've been trying for a while now with no luck setting the fuses. any ideas what i'm doing wrong?

    thanks!

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    The 18F serie work different from the other. In the MPASM directory open the according .INC file. Look at the end you'll discover how to use the Config directive.

    Free example here...
    Code:
    @ __CONFIG _CONFIG1H, _OSCS_OFF_1H & _HS_OSC_1H
        ' Oscillator switch OFF
        ' Use HS oscillator (20MHZ here)
        '
    @ __CONFIG _CONFIG2L, _BOR_ON_2L & _PWRT_ON_2L & _BORV_45_2L
        ' Brown out reset ON @ 4.5Volts
        ' Power-up timer ON
        '
    @ __CONFIG _CONFIG2H, _WDT_ON_2H 
        ' Watch dog timer ON
        '
    @ __CONFIG _CONFIG4L, _STVR_ON_4L & _LVP_OFF_4L & _DEBUG_OFF_4L
        ' Stack over/underflow ON
        ' Low Voltage programming OFF
        ' Background debugger OFF
    Last edited by mister_e; - 29th October 2005 at 16:27.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  8. #8
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile PBC Options for Fuse Setting

    So in PBC NOT pro there is no @ DEVICE command so I assume there is another way to set fuses and pin defaults or is it only done in the programmer itself? ...
    PIC BASIC COMPILER USERS (PBC), see this thread for some options on presetting fuses

    http://www.picbasic.co.uk/forum/showthread.php?t=4158

    (don't let the name of the thread fool you, what you want is toward the bottom)

    Paul Borgmeier
    Salt Lake City, Utah
    USA

  9. #9
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    To save reading the thread Paul cited, this syntax (case insensitive) works with both PBC and PBP when using PM.
    Code:
    asm
            DEVICE PIC12F629, INTRC_OSC_NOCLKOUT	;4MHz INT OSC
            DEVICE PIC12F629, WDT_OFF		;WATCHDOG
            DEVICE PIC12F629, PWRT_ON		;POWER ON TIMER
            DEVICE PIC12F629, MCLR_OFF		;GPIO.3 = INPUT
            DEVICE PIC12F629, BOD_ON		;BROWNOUT RESET
            DEVICE PIC12F629, PROTECT_OFF           ;CODE PROTECT
            DEVICE PIC12F629, CPD_OFF               ;EEPROM PROTECT
    endasm
    Last edited by dhouston; - 2nd July 2006 at 15:47.

  10. #10
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default

    Hi to all !
    I use 16F628A in one project ; I try this codes :
    @ DEVICE pic16F628A, INTRC_IO, WDT_OFF, PWRT_OFF, BOD_OFF, MCLR_OFF, LVP_OFF, CPD_OFF, PROTECT_OFF 'VAR 1


    'asm 'VAR 2
    ' DEVICE PIC16F628A, INTRC_IO
    ' DEVICE PIC16F628A, WDT_OFF ;WATCHDOG
    ' DEVICE PIC16F628A, PWRT_OFF ;POWER ON TIMER
    ' DEVICE PIC16F628A, MCLR_OFF ;GPIO.3 = INPUT
    ' DEVICE PIC16F628A, BOD_FF ;BROWNOUT RESET
    ' DEVICE PIC16F628A, PROTECT_OFF ;CODE PROTECT
    ' DEVICE PIC16F628A, CPD_OFF ;EEPROM PROTECT
    'endasm

    but no one don't work ! I receive the message : "Undefined Symbol 'INTRC_IO'".
    Please help ! Thanks in advance !

  11. #11
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Wink

    Hi, Fratello

    Did you had a look to the VERY first post of that thread ???

    just " cut and paste " needed !!!

    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 " !!!
    *****************************************

  12. #12
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default

    Even I try this :
    @ DEVICE pic16F628, INTRC_IO
    the message is still : Undefined symbol 'INTRC_IO' .
    All the others line
    @ DEVICE pic16F628, WDT_OFF
    @ DEVICE pic16F628, PWRT_OFF.... are OK. Just the first one give me error !!!

  13. #13
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default

    The correct syntax is :
    INTOSC_OSC and not INTRC_IO ! I read in M16F62xA.INC.
    Thanks !

  14. #14
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default Re: Presetting Configuration Fuses (PIC Defines) into PBP3 (Only version 3.0 +)

    Here are a few examples of how to use the new #CONFIG block syntax for PBP3. (This will NOT work on previous versions of PBP ... Get your upgrade now )

    PBP3 makes it a little easier to figure out, and set up your configs. It has eliminated the need to comment out the default configurations set up by PBP. It still has default settings - these can be found in the /PBP3/DEVICES file under yourchip.PBPINC . Here is an example of default settings for the PIC18F45K22:
    Code:
    ; CUT rest of file out for display purposes
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;  The #CONFIG block is passed directly to the asm file, but PBP will replace it
    ;  automagically with the contents of a user-defined #CONFIG block if one is
    ;  found in the PBP source program.
    
    #CONFIG
            __CONFIG    _CONFIG1H, _FOSC_INTIO67_1H
            __CONFIG    _CONFIG3H, _PBADEN_OFF_3H
            __CONFIG    _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
    #ENDCONFIG
    
    ; CUT rest of file out for display purposes
    If you want to change the default configs in PBP3, DON'T edit the above file. You can just declare them in your code using the #CONFIG #ENDCONFIG block. For all the possibilities of config settings for your chip, check out the /PBP3/DEVICE_REFERENCE folder, and select the yourchip.INFO file. It will look something like this:
    Code:
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;
    ;  File:    PIC18F45K22.INFO
    ;  Date:    07/24/11
    ;  Generated by melabs File Manager
    ;
    ;  PICBASIC PRO(tm) Compiler version: 3.0.0.x
    ;
    ;  Copyright 2011 microEngineering Labs, Inc.   All Rights Reserved
    ;  The content herein is intended to facilitate embedded development using
    ;  PICBASIC PRO Compiler.  Reproduction or utilization for other purposes
    ;  is prohibited without written permission from microEngineering Labs, Inc..
    ;  
    ;  microEngineering Labs, Inc.
    ;  2845 Ore Mill Road STE 4
    ;  Colorado Springs, CO  80904
    ;  719-520-5323
    ;  fax: 719-520-1867
    ;  http://melabs.com
    ;  [email protected]
    ;
    ;  Modifications to this file in the \DEVICE_REFERENCE folder will be overwritten when
    ;  you install future upgrades.
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;MPASM CONFIG Directive Options
    ;
    ;  This section is included for reference only.  The following options may
    ;  be used with the MPASM CONFIG directive to specify configuration settings
    ;  in the source program using the #CONFIG/#ENDCONFIG block.
    ;  Example:
    ;
    ;  #CONFIG
    ;    CONFIG  OSC = HS
    ;    CONFIG  WDTE = ON
    ;  #ENDCONFIG
    ;
    ;
    ;  Oscillator Selection bits
    ;    CONFIG FOSC = RC        ;111X External RC oscillator, CLKOUT function on RA6
    ;    CONFIG FOSC = ECLPIO6        ;EC oscillator (low power, <500 kHz)
    ;    CONFIG FOSC = ECLP        ;EC oscillator, CLKOUT function on OSC2 (low power, <500 kHz)
    ;    CONFIG FOSC = ECMPIO6        ;EC oscillator (medium power, 500 kHz-16 MHz)
    ;    CONFIG FOSC = ECMP        ;EC oscillator, CLKOUT function on OSC2 (medium power, 500 kHz-16 MHz)
    ;    CONFIG FOSC = INTIO7        ;Internal oscillator block, CLKOUT function on OSC2
    ;    CONFIG FOSC = INTIO67        ;Internal oscillator block
    ;    CONFIG FOSC = RCIO6        ;External RC oscillator
    ;    CONFIG FOSC = RC        ;External RC oscillator, CLKOUT function on OSC2
    ;    CONFIG FOSC = ECHPIO6        ;EC oscillator (high power, >16 MHz)
    ;    CONFIG FOSC = ECHP        ;EC oscillator, CLKOUT function on OSC2 (high power, >16 MHz)
    ;    CONFIG FOSC = HSMP        ;HS oscillator (medium power 4-16 MHz)
    ;    CONFIG FOSC = HSHP        ;HS oscillator (high power > 16 MHz)
    ;    CONFIG FOSC = XT        ;XT oscillator
    ;    CONFIG FOSC = LP        ;LP oscillator
    ;
    ;  4X PLL Enable
    ;    CONFIG PLLCFG = OFF        ;Oscillator used directly
    ;    CONFIG PLLCFG = ON        ;Oscillator multiplied by 4
    ;
    ;  Primary clock enable bit
    ;    CONFIG PRICLKEN = OFF        ;Primary clock can be disabled by software
    ;    CONFIG PRICLKEN = ON        ;Primary clock is always enabled
    ;
    ;  Fail-Safe Clock Monitor Enable bit
    ;    CONFIG FCMEN = OFF        ;Fail-Safe Clock Monitor disabled
    ;    CONFIG FCMEN = ON        ;Fail-Safe Clock Monitor enabled
    ;
    ;  Internal/External Oscillator Switchover bit
    ;    CONFIG IESO = OFF        ;Oscillator Switchover mode disabled
    ;    CONFIG IESO = ON        ;Oscillator Switchover mode enabled
    ;
    ;  Power-up Timer Enable bit
    ;    CONFIG PWRTEN = OFF        ;Power up timer disabled
    ;    CONFIG PWRTEN = ON        ;Power up timer enabled
    ;
    ;  Brown-out Reset Enable bits
    ;    CONFIG BOREN = SBORDIS        ;Brown-out Reset enabled in hardware only (SBOREN is disabled)
    ;    CONFIG BOREN = NOSLP        ;Brown-out Reset enabled in hardware only and disabled in Sleep mode (SBOREN is disabled)
    ;    CONFIG BOREN = ON        ;Brown-out Reset enabled and controlled by software (SBOREN is enabled)
    ;    CONFIG BOREN = OFF        ;Brown-out Reset disabled in hardware and software
    ;
    ;  Brown Out Reset Voltage bits
    ;    CONFIG BORV = 190        ;VBOR set to 1.90 V nominal
    ;    CONFIG BORV = 220        ;VBOR set to 2.20 V nominal
    ;    CONFIG BORV = 250        ;VBOR set to 2.50 V nominal
    ;    CONFIG BORV = 285        ;VBOR set to 2.85 V nominal
    ;
    ;  Watchdog Timer Enable bits
    ;    CONFIG WDTEN = ON        ;WDT is always enabled. SWDTEN bit has no effect
    ;    CONFIG WDTEN = SWON        ;WDT is controlled by SWDTEN bit of the WDTCON register
    ;    CONFIG WDTEN = NOSLP        ;WDT is disabled in sleep, otherwise enabled. SWDTEN bit has no effect
    ;    CONFIG WDTEN = OFF        ;Watch dog timer is always disabled. SWDTEN has no effect.
    ;
    ;  Watchdog Timer Postscale Select bits
    ;    CONFIG WDTPS = 32768        ;1:32768
    ;    CONFIG WDTPS = 16384        ;1:16384
    ;    CONFIG WDTPS = 8192        ;1:8192
    ;    CONFIG WDTPS = 4096        ;1:4096
    ;    CONFIG WDTPS = 2048        ;1:2048
    ;    CONFIG WDTPS = 1024        ;1:1024
    ;    CONFIG WDTPS = 512        ;1:512
    ;    CONFIG WDTPS = 256        ;1:256
    ;    CONFIG WDTPS = 128        ;1:128
    ;    CONFIG WDTPS = 64        ;1:64
    ;    CONFIG WDTPS = 32        ;1:32
    ;    CONFIG WDTPS = 16        ;1:16
    ;    CONFIG WDTPS = 8        ;1:8
    ;    CONFIG WDTPS = 4        ;1:4
    ;    CONFIG WDTPS = 2        ;1:2
    ;    CONFIG WDTPS = 1        ;1:1
    ;
    ;  CCP2 MUX bit
    ;    CONFIG CCP2MX = PORTC1        ;CCP2 input/output is multiplexed with RC1
    ;    CONFIG CCP2MX = PORTB3        ;CCP2 input/output is multiplexed with RB3
    ;
    ;  PORTB A/D Enable bit
    ;    CONFIG PBADEN = ON        ;PORTB<5:0> pins are configured as analog input channels on Reset
    ;    CONFIG PBADEN = OFF        ;PORTB<5:0> pins are configured as digital I/O on Reset
    ;
    ;  P3A/CCP3 Mux bit
    ;    CONFIG CCP3MX = PORTB5        ;P3A/CCP3 input/output is multiplexed with RB5
    ;    CONFIG CCP3MX = PORTE0        ;P3A/CCP3 input/output is mulitplexed with RE0
    ;
    ;  HFINTOSC Fast Start-up
    ;    CONFIG HFOFST = ON        ;HFINTOSC output and ready status are not delayed by the oscillator stable status
    ;    CONFIG HFOFST = OFF        ;HFINTOSC output and ready status are delayed by the oscillator stable status
    ;
    ;  Timer3 Clock input mux bit
    ;    CONFIG T3CMX = PORTC0        ;T3CKI is on RC0
    ;    CONFIG T3CMX = PORTB5        ;T3CKI is on RB5
    ;
    ;  ECCP2 B output mux bit
    ;    CONFIG P2BMX = PORTD2        ;P2B is on RD2
    ;    CONFIG P2BMX = PORTC0        ;P2B is on RC0
    ;
    ;  MCLR Pin Enable bit
    ;    CONFIG MCLRE = EXTMCLR        ;MCLR pin enabled, RE3 input pin disabled
    ;    CONFIG MCLRE = INTMCLR        ;RE3 input pin enabled; MCLR disabled
    ;
    ;  Stack Full/Underflow Reset Enable bit
    ;    CONFIG STVREN = ON        ;Stack full/underflow will cause Reset
    ;    CONFIG STVREN = OFF        ;Stack full/underflow will not cause Reset
    ;
    ;  Single-Supply ICSP Enable bit
    ;    CONFIG LVP = ON        ;Single-Supply ICSP enabled if MCLRE is also 1
    ;    CONFIG LVP = OFF        ;Single-Supply ICSP disabled
    ;
    ;  Extended Instruction Set Enable bit
    ;    CONFIG XINST = ON        ;Instruction set extension and Indexed Addressing mode enabled
    ;    CONFIG XINST = OFF        ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
    ;
    ;  Background Debug
    ;    CONFIG DEBUG = OFF        ;Disabled
    ;    CONFIG DEBUG = ON        ;Enabled
    ;
    ;  Code Protection Block 0
    ;    CONFIG CP0 = OFF        ;Block 0 (000800-001FFFh) not code-protected
    ;    CONFIG CP0 = ON        ;Block 0 (000800-001FFFh) code-protected
    ;
    ;  Code Protection Block 1
    ;    CONFIG CP1 = OFF        ;Block 1 (002000-003FFFh) not code-protected
    ;    CONFIG CP1 = ON        ;Block 1 (002000-003FFFh) code-protected
    ;
    ;  Code Protection Block 2
    ;    CONFIG CP2 = OFF        ;Block 2 (004000-005FFFh) not code-protected
    ;    CONFIG CP2 = ON        ;Block 2 (004000-005FFFh) code-protected
    ;
    ;  Code Protection Block 3
    ;    CONFIG CP3 = OFF        ;Block 3 (006000-007FFFh) not code-protected
    ;    CONFIG CP3 = ON        ;Block 3 (006000-007FFFh) code-protected
    ;
    ;  Boot Block Code Protection bit
    ;    CONFIG CPB = OFF        ;Boot block (000000-0007FFh) not code-protected
    ;    CONFIG CPB = ON        ;Boot block (000000-0007FFh) code-protected
    ;
    ;  Data EEPROM Code Protection bit
    ;    CONFIG CPD = OFF        ;Data EEPROM not code-protected
    ;    CONFIG CPD = ON        ;Data EEPROM code-protected
    ;
    ;  Write Protection Block 0
    ;    CONFIG WRT0 = OFF        ;Block 0 (000800-001FFFh) not write-protected
    ;    CONFIG WRT0 = ON        ;Block 0 (000800-001FFFh) write-protected
    ;
    ;  Write Protection Block 1
    ;    CONFIG WRT1 = OFF        ;Block 1 (002000-003FFFh) not write-protected
    ;    CONFIG WRT1 = ON        ;Block 1 (002000-003FFFh) write-protected
    ;
    ;  Write Protection Block 2
    ;    CONFIG WRT2 = OFF        ;Block 2 (004000-005FFFh) not write-protected
    ;    CONFIG WRT2 = ON        ;Block 2 (004000-005FFFh) write-protected
    ;
    ;  Write Protection Block 3
    ;    CONFIG WRT3 = OFF        ;Block 3 (006000-007FFFh) not write-protected
    ;    CONFIG WRT3 = ON        ;Block 3 (006000-007FFFh) write-protected
    ;
    ;  Configuration Register Write Protection bit
    ;    CONFIG WRTC = OFF        ;Configuration registers (300000-3000FFh) not write-protected
    ;    CONFIG WRTC = ON        ;Configuration registers (300000-3000FFh) write-protected
    ;
    ;  Boot Block Write Protection bit
    ;    CONFIG WRTB = OFF        ;Boot Block (000000-0007FFh) not write-protected
    ;    CONFIG WRTB = ON        ;Boot Block (000000-0007FFh) write-protected
    ;
    ;  Data EEPROM Write Protection bit
    ;    CONFIG WRTD = OFF        ;Data EEPROM not write-protected
    ;    CONFIG WRTD = ON        ;Data EEPROM write-protected
    ;
    ;  Table Read Protection Block 0
    ;    CONFIG EBTR0 = OFF        ;Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
    ;    CONFIG EBTR0 = ON        ;Block 0 (000800-001FFFh) protected from table reads executed in other blocks
    ;
    ;  Table Read Protection Block 1
    ;    CONFIG EBTR1 = OFF        ;Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
    ;    CONFIG EBTR1 = ON        ;Block 1 (002000-003FFFh) protected from table reads executed in other blocks
    ;
    ;  Table Read Protection Block 2
    ;    CONFIG EBTR2 = OFF        ;Block 2 (004000-005FFFh) not protected from table reads executed in other blocks
    ;    CONFIG EBTR2 = ON        ;Block 2 (004000-005FFFh) protected from table reads executed in other blocks
    ;
    ;  Table Read Protection Block 3
    ;    CONFIG EBTR3 = OFF        ;Block 3 (006000-007FFFh) not protected from table reads executed in other blocks
    ;    CONFIG EBTR3 = ON        ;Block 3 (006000-007FFFh) protected from table reads executed in other blocks
    ;
    ;  Boot Block Table Read Protection bit
    ;    CONFIG EBTRB = OFF        ;Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
    ;    CONFIG EBTRB = ON        ;Boot Block (000000-0007FFh) protected from table reads executed in other blocks
    ;
    ;
    ;/MPASM
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    Here is an example of how to use the #CONFIG block:

    Code:
    ' PIC18F45K22 With Internal OSC set to 64 Mhz
    ' FLASH AN LED CONNECTED TO PORTB.0
     #CONFIG
        CONFIG DEBUG = OFF    
        CONFIG XINST = OFF     
        CONFIG STVREN = OFF     
        CONFIG WDTEN = OFF      
        CONFIG FCMEN = OFF      
        CONFIG FOSC = INTIO67  
        CONFIG PLLCFG = ON        
        CONFIG PRICLKEN = ON      
        CONFIG IESO = OFF       ; Two-Speed Start-up disabled
        CONFIG WDTPS = 128      ; 1:128 prescaller for watchdog
        CONFIG BOREN = OFF      ; Brown-out Reset disabled in hardware and software
        CONFIG BORV = 250       ; VBOR set to 2.5 V nominal
        CONFIG MCLRE = EXTMCLR  ; MCLR pin enabled, RE3 input pin disabled
        CONFIG HFOFST = OFF     ; The system clock is held off until the HF-INTOSC is stable.
        CONFIG PBADEN = OFF     ; PORTB<4:0> pins are configured as digital I/O on Reset
        CONFIG CCP2MX = PORTC1  ; CCP2 input/output is multiplexed with RC1
        CONFIG LVP = OFF        ; Single-Supply ICSP disabled
        CONFIG CP0 = OFF        ; Block 0 (000800-001FFFh) not code-protected
        CONFIG CP1 = OFF        ; Block 1 (002000-003FFFh) not code-protected
        CONFIG CPB = OFF        ; Boot block (000000-0007FFh) not code-protected
        CONFIG CPD = OFF        ; Data eeprom not code-protected
        CONFIG WRT0 = OFF       ; Block 0 (000800-001FFFh) not write-protected
        CONFIG WRT1 = OFF       ; Block 1 (002000-003FFFh) not write-protected
        CONFIG WRT2 = OFF       ; Block 2 (4000h-5FFFh) not write-protected
        CONFIG WRT3 = OFF       ; Block 3 (6000h-7FFFh) not write-protected
        CONFIG WRTB = OFF       ; Boot block (000000-0007FFh) not write-protected
        CONFIG WRTC = OFF       ; Configuration registers (300000-3000FFh) not write-protected
        CONFIG WRTD = OFF       ; Data eeprom not write-protected
        CONFIG EBTR0 = OFF      ; Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
        CONFIG EBTR1 = OFF      ; Block 1 (002000-003FFFh) 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
     #ENDCONFIG
    
        DEFINE OSC 64           'THE 16MHz IS PLL'ed TO 64 MHz
        OSCCON = %01110000    'Set internal osc to 16 Mhz
        OSCTUNE = %01000000   'Turn PLL ON to multiply osc by 4
        
        ANSELA = 0              'ALL ANALOG TO DIGITAL
        ANSELB = 0  
        ANSELC = 0
    If you get an error like:
    [ERROR] program.pbp fatal (34) : Block overflow for #ENCONFIG
    that means that there are too many comments in your configs to "fit". Erase some comments and try compiling again.

    Some new features in PBP3 make it possible to do conditional defines, and conditional PIC setup.

    (Some content plagiarized from here: http://support.melabs.com/threads/26...wfull=1#post38 ... Thanks Darrel!)

    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.

    Some things to remember:
    PBP can not use the XINST ,"Instuction set extension and indexed addressing mode", so make sure it is never turned on.
    LVP is another issue. Just leave this off as well.

    Some older chips like a slightly different context. Let's take a PIC16F628A for example:
    Here are the default configs:
    Code:
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;  The #CONFIG block is passed directly to the asm file, but PBP will replace it
    ;  automagically with the contents of a user-defined #CONFIG block if one is
    ;  found in the PBP source program.
    
    #CONFIG
        ifdef PM_USED
            device  pic16F628A, xt_osc, wdt_on, mclr_on, lvp_off, protect_off
        else
            __config _XT_OSC & _WDT_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
        endif
    #ENDCONFIG
    (The first part of this conditional config statment checks to see if the PM assembler is used. Since code for the newer chips can't be assembled with PM, I always chose MPASM.)
    You have to use a format like this for these older chips: __config _x & _y & _z
    Last edited by ScaleRobotics; - 8th March 2012 at 14:22.
    http://www.scalerobotics.com

Similar Threads

  1. pic program crashing
    By comwarrior in forum General
    Replies: 5
    Last Post: - 8th July 2009, 16:33
  2. HSERIN & Interupts (aka controlling PIC programs from a remote PC)
    By HankMcSpank in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 17th June 2009, 14:46
  3. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  4. size of program vs mem on pic
    By PICMAN in forum General
    Replies: 1
    Last Post: - 1st March 2005, 17:23
  5. Serial communication PIC to PIC help.
    By Rubicon in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 24th January 2005, 15:45

Members who have read this thread : 11

You do not have permission to view the list of names.

Posting Permissions

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