Presetting Configuration Fuses (PIC Defines) into your Program


+ Reply to Thread
Results 1 to 40 of 83

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,358

    Default Presetting Configuration Fuses (PIC Defines) into your Program

    1. What are the Configuration Fuses?
    2. How can I preset them in my Program?
    2.a. When using MeLabs default (PM) Assembler
    2.b. When using Microchip's (MPASM) Assembler
    3. Where can I find a List of the Configuration Definitions?
    3.a. When using MeLabs default (PM) Assembler
    3.b. When using Microchip's (MPASM) Assembler



    1. What are the Configuration Fuses?

    The Configuration Fuses (Configuration Bits) are the settings that configure the PIC for the external environment it is expecting to find... typical settings include Oscillator Type, MCLR pin usage, Code Protection, Brown-Out and Watchdog Timer usage, Low Voltage Programming etc. Different families of PICs have different settings, so the list of settings for a 12F675, will not be the same as the list for a 16F877. When you LOAD a program into your programmer, these settings appropriately configure it without you having to make any additional changes. This saves you a lot of time messing with minor settings before you hit the 'Program' Button. Remember though, you are still able to over-ride these setting manually prior to programming your chip. Most programmers will only configure the settings to your compiled defaults when you LOAD the program, so if you change them manually, you will need to RELOAD your program for them to revert to the default (compiled) settings.


    2. How can I preset them in my Program?

    This very much depends on if you are using MeLabs default (PM) Assembler, or Microchips (MPASM) alternative.


    2.a. When using MeLabs default (PM) Assembler

    Example: To set the PIC for XT Oscillator...

    @ DEVICE XT_OSC

    or

    @ DEVICE PIC16F628,XT_OSC

    The PIC type is optional, if it is included and you accidentally compile for a chip other than that specified (a 16F628 in this example), the compiler will report an error as a reminder you're potentially doing something wrong.

    Multiple definitions are entered on separate lines, one line per definition and can be interspersed with comments…

    Example: Typical Settings for a 16F628…

    @ DEVICE pic16F628, INTRC_OSC_NOCLKOUT
    ' System Clock Options
    @ DEVICE pic16F628, WDT_ON
    ' Watchdog Timer
    @ DEVICE pic16F628, PWRT_ON
    ' Power-On Timer
    @ DEVICE pic16F628, MCLR_OFF
    ' Master Clear Options (Internal)
    @ DEVICE pic16F628, BOD_ON
    ' Brown-Out Detect
    @ DEVICE pic16F628, LVP_OFF
    ' Low-Voltage Programming
    @ DEVICE pic16F628, CPD_ON
    ' Data Memory Code Protect
    ' Set to CPD_OFF for Development Copy
    ' Set to CPD_ON for Release Copy
    @ DEVICE pic16F628, PROTECT_ON
    ' Program Code Protection
    ' Set to PROTECT_OFF for Development Copy
    ' Set to PROTECT_ON for Release Copy


    2.b. When using Microchip's (MPASM) Assembler

    Example: To set the PIC for Internal Oscillator allowing use of the OSC pins as I/O...

    @ __config _INTRC_OSC_NOCLKOUT

    Only one config statement is allowed when using MPASM, so multiple definitions follow-on from each other each connected to it’s previous buddy with an &.

    Example: Typical Settings for a 16F628…

    @ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON & _LVP_OFF & _CP_ALL & _DATA_CP_ON


    3. Where can I find a List of the Configuration Definitions?

    Now you’ll have noticed that my multiple example for PM and MPASM above are for the same configuration settings (they are now, they weren't when first posted!) - you’ll notice however that there are differences… MCLR_OFF in PM becomes MCLRE_OFF when using MPASM… Here’s how you find the list of possible options available to you… whether you chose to use the default PM or the option of the MPASM Assembler, cross-reference your choices with your chosen PICs Datasheet, look in the section entitled “Special Features of the CPU”. Some configurations may be listed under multiple names, the little extra being provided for your convenience.


    3.a. When using MeLabs default (PM) Assembler

    Open up the PBP directory, and in it you will find an INC subdirectory. Opening that up and you'll see a heap of files. Find the Mxxxx.INC file for the PIC you're interested in... (example M12F675.INC). If you can’t locate your exact PIC, it might be listed under a family of PICs that share the same settings (example chose M16F62X.INC if you need the settings for a 16F628). Open the file up with something like Notepad – (don’t make any changes to it) and have a look what the file contains…It reveals the internal sex life of the PIC. All the Configuration Fuse Defines that you can use from within PBP are listed here at the top, and lower down all the Registers are Listed. If it's not in the list, you can't use it - but trust me, it's usually all there. Remember, this list is for use with the PM (default assembler).


    3.b. When using Microchip's (MPASM) Assembler

    If you're going to use MPASM, look for the appropriate file (example for a 16F628 look for P16F628.INC) located in something like the MCHIP_Tools subdirectory of your MPLAB installation. Here you’ll find the Configuration Bits located near the bottom of the list. Simply just use the ones you want. Hey presto your PIC is all defined and ready to run.

    Melanie

    Edit from Moderator:
    A Wiki for this thread has been created, making a somewhat condensed version of this thread. It is located here: http://www.picbasic.co.uk/forum/cont...o-your-Program
    Last edited by ScaleRobotics; - 8th June 2010 at 15:49.

  2. #2
    Join Date
    May 2004
    Posts
    81


    Did you find this post helpful? Yes | No

    Default

    O.K., Now is there a way to set the device in the hex file?

    Here is what I am using for a "system"

    - Picbasic Pro ver 2.44 to compile ....
    - Microcode Studio 2.0.1.6
    - For programming: ICPROG 1.05C

    ... The docs for ICPROG 1.05 C says:

    IC-Prog also stores the chip name in the saved HEX file. You can use this option to automaticly set the device by openening its file. Use option "Select device from file" on Misc. page.


    And actually... After reading the more closly I guess it means ICPROG stores it there.... (?)


    They ARE stored in the HEX file, because that's what you load your programmer with and those definitions are embedded in your compiled file. I have not had the urge to tear apart a HEX file so can't answer your question on where exactly that information is located within it. - Melanie

  3. #3
    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

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


    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

  5. #5
    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 19:04.
    Steve

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

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    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

  7. #7
    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!!!

  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 16:47.

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


    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,611


    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
    Jun 2011
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: Presetting Configuration Fuses (PIC Defines) into your Program

    Melanie,
    Can you help me with this?
    I cannot get the protection to work. My devices are a 18F2680 and a 18F2620.
    Here is my code;
    __CONFIG _CONFIG5L, _CP_ALL & _DATA_CP_ON
    __CONFIG _CONFIG5H, _CP_ALL & _DATA_CP_ON

    As you can see I tried it in bothe high and low registers. This is what I get when I try to compile;
    Symbol not previously defined (_CP_ALL)
    Symbol not previously defined (_DATA_CP_ON)
    Thanks for any help!
    Ray

  13. #13
    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 your Program

    Sorry, I wish I was Melanie, but I have not seen her around lately, or even not so lately.
    The 18F2680 needs different syntax for those options. Check out post # 42 of this thread.

    Here is the syntax to use for the 18F2680:
    Code:
    ;----- CONFIG5L Options --------------------------------------------------
    _CP0_ON_5L           EQU  H'FE'    ; Block 0 (000800-003FFFh) code-protected
    _CP0_OFF_5L          EQU  H'FF'    ; Block 0 (000800-003FFFh) not code-protected
    
    _CP1_ON_5L           EQU  H'FD'    ; Block 1 (004000-007FFFh) code-protected
    _CP1_OFF_5L          EQU  H'FF'    ; Block 1 (004000-007FFFh) not code-protected
    
    _CP2_ON_5L           EQU  H'FB'    ; Block 2 (008000-00BFFFh) code-protected
    _CP2_OFF_5L          EQU  H'FF'    ; Block 2 (008000-00BFFFh) not code-protected
    
    _CP3_ON_5L           EQU  H'F7'    ; Block 3 (00C000-00FFFFh) code-protected
    _CP3_OFF_5L          EQU  H'FF'    ; Block 3 (00C000-00FFFFh) not code-protected
    
    ;----- CONFIG5H Options --------------------------------------------------
    _CPB_ON_5H           EQU  H'BF'    ; Boot block (000000-0007FFh) code-protected
    _CPB_OFF_5H          EQU  H'FF'    ; Boot block (000000-0007FFh) not code-protected
    
    _CPD_ON_5H           EQU  H'7F'    ; Data EEPROM code-protected
    _CPD_OFF_5H          EQU  H'FF'    ; Data EEPROM not code-protected
    http://www.scalerobotics.com

  14. #14
    Join Date
    Jun 2011
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: Presetting Configuration Fuses (PIC Defines) into your Program

    That worked perfectly!
    Thanks a bunch!
    Ray

    Quote Originally Posted by ScaleRobotics View Post
    Sorry, I wish I was Melanie, but I have not seen her around lately, or even not so lately.
    The 18F2680 needs different syntax for those options. Check out post # 42 of this thread.

    Here is the syntax to use for the 18F2680:
    Code:
    ;----- CONFIG5L Options --------------------------------------------------
    _CP0_ON_5L           EQU  H'FE'    ; Block 0 (000800-003FFFh) code-protected
    _CP0_OFF_5L          EQU  H'FF'    ; Block 0 (000800-003FFFh) not code-protected
    
    _CP1_ON_5L           EQU  H'FD'    ; Block 1 (004000-007FFFh) code-protected
    _CP1_OFF_5L          EQU  H'FF'    ; Block 1 (004000-007FFFh) not code-protected
    
    _CP2_ON_5L           EQU  H'FB'    ; Block 2 (008000-00BFFFh) code-protected
    _CP2_OFF_5L          EQU  H'FF'    ; Block 2 (008000-00BFFFh) not code-protected
    
    _CP3_ON_5L           EQU  H'F7'    ; Block 3 (00C000-00FFFFh) code-protected
    _CP3_OFF_5L          EQU  H'FF'    ; Block 3 (00C000-00FFFFh) not code-protected
    
    ;----- CONFIG5H Options --------------------------------------------------
    _CPB_ON_5H           EQU  H'BF'    ; Boot block (000000-0007FFh) code-protected
    _CPB_OFF_5H          EQU  H'FF'    ; Boot block (000000-0007FFh) not code-protected
    
    _CPD_ON_5H           EQU  H'7F'    ; Data EEPROM code-protected
    _CPD_OFF_5H          EQU  H'FF'    ; Data EEPROM not code-protected

  15. #15
    Join Date
    Dec 2013
    Posts
    3


    Did you find this post helpful? Yes | No

    Default Re: Presetting Configuration Fuses (PIC Defines) into your Program

    Hi, i have this problem when i try to use a external oscillator
    when compile an error that like this appear

    Overwritting previous adress contens (2007)

    How i can fix that?

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


    Did you find this post helpful? Yes | No

    Default Re: Presetting Configuration Fuses (PIC Defines) into your Program

    The answer is in the first five post of this thread.
    Maybe you did not read the thread you posted to ?
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. pic program crashing
    By comwarrior in forum General
    Replies: 5
    Last Post: - 8th July 2009, 17: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, 15:46
  3. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 09:26
  4. size of program vs mem on pic
    By PICMAN in forum General
    Replies: 1
    Last Post: - 1st March 2005, 18:23
  5. Serial communication PIC to PIC help.
    By Rubicon in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 24th January 2005, 16:45

Members who have read this thread : 5

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