1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

__Config function in Assembly Coding

Discussion in 'Microcontrollers' started by Jules_Theone, Apr 20, 2009.

  1. Jules_Theone

    Jules_Theone Member

    Joined:
    Jan 22, 2009
    Messages:
    167
    Likes:
    3
    Location:
    Exeter, England
    I'm still a beginner to writing in assembly, but I was just wondering about the __config [hex number] or __config [_CP_OFF & _CPD_OFF & _BOD_OFF] etc. part.

    Specifically, why some programs I've seen list each function to turn on or off, and others just a hex number. Basically is there a way to turn my program with __config _CP_OFF & _CPD_OFF & _BOD_OFF etc into a __config 3FFF type one?

    Code (text):

        list      p=16F688              ; list directive to define processor
        #include <p16F688.inc>          ; processor specific variable definitions

        errorlevel  -302                ; suppress message 302 from list file

    ; '__CONFIG' directive is used to embed configuration word within .asm file.
    ; The lables following the directive are located in the respective .inc file.
    ; See data sheet for additional information on configuration word settings.

        __CONFIG    _CP_OFF & _CPD_OFF & _BOD_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _FCMEN_OFF & _IESO_OFF


     
     
  2. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,324
    Likes:
    653
    Location:
    Derbyshire, UK
    Yes, each of those 'words' (such as _BOD_OFF) is simply replaced by a number during assembly, these values are listed in the .INC file, you can pick the ones you want and simply AND them together.

    Or you can look at the datasheet for the PIC and pickout the binary value for the settings you want, and then convert to HEX.

    Or, you can use WinPicProg, which displays the HEX value for the options you select with the tickboxes.
     
  3. gramo

    gramo New Member

    Joined:
    Oct 2, 2006
    Messages:
    1,221
    Likes:
    23
    Location:
    Newcastle, Australia
    Thread hijacking!

    Some things I have always taken for granted without actually knowing why/how!


    Love learning something new everyday :)
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Jules_Theone

    Jules_Theone Member

    Joined:
    Jan 22, 2009
    Messages:
    167
    Likes:
    3
    Location:
    Exeter, England

    That's what I thought, I've looked up the equ codes in the inc file and added them together, but it comes out at 0x230BC, does that sound right? I wasn't sure, because it looks different on the winpicprog tutorials, I didn't want to accidently code protect or lock the pic somehow.

    So it's simply __config 0x230BC ?
     
  6. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,324
    Likes:
    653
    Location:
    Derbyshire, UK
    You don't ADD them, you logically AND them.
     
  7. bobledoux

    bobledoux Member

    Joined:
    Jul 16, 2006
    Messages:
    259
    Likes:
    3
    Location:
    Near Salem, OR, USA
    If you use MPLAB you can use the pull down menu to set the configuration bits. Once all are set the config value is shown in the display. You can then enter this value in your program. The pull down menu also sets the bits for your processor. If the number you enter in the program does not match the number set in the pull down menu the complier will let you know.
     
  8. Jules_Theone

    Jules_Theone Member

    Joined:
    Jan 22, 2009
    Messages:
    167
    Likes:
    3
    Location:
    Exeter, England
    Ok. ANDed them, and it comes out as 30C4, took a while to find the pull down menu thingy, but yeah that comes out as 30C4 too. So thats great. Thanks.
     
  9. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,161
    Likes:
    340
    Location:
    Brisbane Australia
    I hate it when people post code on here and it has a hex value for the config. I have no idea if the internal oscillator is being used, if the WDT is on etc. In my mind it's as bad as writing bsf 3,0 instead of bsf STATUS,C.

    Also, if you use the supplied names then when you switch to a different chip it will work most of the time and if it doesn't the assembler will give you an error.

    Mike.
     

Share This Page