Configuration word register questions

Discussion in 'Embedded Systems and Microcontrollers' started by campeck, Feb 24, 2010.

  1. campeck

    Thread Starter Active Member

    Sep 5, 2009
    194
    3
    Hey
    The target device is a 12F683

    #include <p12F683.inc>
    __config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _IESO_OFF & _FCMEN_OFF)

    [​IMG]

    I am going through some tutorials and this is at the top of the program.
    What's going on here? Am I turning things off or on? Are these defaults?

    Also to set the internal oscillator to 8Mhz bit 4,5 and 6 of the OSCCON register need to be set to 1.

    so why does this tutorial tell me to use 0x70 which isn't that 112? Wouldn't I use 0x6F? and put that into OSCCON?

    Thankyou.
     
  2. campeck

    Thread Starter Active Member

    Sep 5, 2009
    194
    3
    Hmm. Is all I am doing is adding those presets to the config at the beginning of the program? So By adding the _WDT_OFF to the config I am just presetting the Watchdog to be off? What would happen If I left it out?
     
  3. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Have a look at this and see if answers your questions.
    http://forum.allaboutcircuits.com/showthread.php?t=32986
    As for OSCCON, 0x70 would be 01110000, 0x6F would be 01101111 so 0x70 would be the correct choice.
    I'm not sure what happens if you leave out parts of the config word. Probably best to define them.
     
  4. n9352527

    AAC Fanatic!

    Oct 14, 2005
    1,198
    4
    Notice that each config value are & (bitwise and-ed) together. So, a particular config value is defined as a mask with the corresponding bit set to zero. Leaving a config value will have no effect, if the default bit value of 1 is what you want (in other words, most of the configured peripherals will be on). Otherwise, the config value will have to be defined.
     
  5. campeck

    Thread Starter Active Member

    Sep 5, 2009
    194
    3
    So I can say this? I can label them on or off I mean...

    _WDT_ON & _MCLRE_ON ?
     
  6. n9352527

    AAC Fanatic!

    Oct 14, 2005
    1,198
    4
    I don't think all the _XXX_ON labels are defined, but you better check on the datasheet first (or see in the include file). To set the peripherals to on, you leave out the particular config label. Notice that the /CPD, /CP and /PWRTE are inverted (on when the bit value is 0). The default settings then would be OFF, there must be a _XXX_ON labels to set those settings on, otherwise including either one of them (like _CP_OFF) would mean setting all three of them off (notice that they have the same hex value settings).
     
    Last edited: Feb 26, 2010
  7. Tahmid

    Active Member

    Jul 2, 2008
    344
    25
    Don't leave WDT on, it'll pose problems unless you really intend to use them (which I assume you don't since you're just starting new). So keep _WDT_OFF. For MCLRE, that's Master Clear Enable. If this is on, you need to pull the pin "Master Clear" which I think is pin 1, high. When this pin is low, the microcontroller is in reset mode, where it goes to reset vector. Keeping this pin low means no execution of code. If you keep MCLRE off, then you won't have this feature and you won't need the external resistor.
    So it should be _WDT_OFF & _MCLRE_OFF (you could keep master clear on, but not WDT).

    Hope this helps.
    Tahmid.
     
  8. campeck

    Thread Starter Active Member

    Sep 5, 2009
    194
    3
    __config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _IESO_OFF & _FCMEN_OFF)

    So I could shorten that to...

    __config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _IESO_OFF & _FCMEN_OFF)

    no _CP_OFF?

    And they are high impedance when inputs right? So can I connect straight to Vss or Vdd?
     
    Last edited: Feb 26, 2010
Loading...