Run-Time Config


Closed Thread
Results 1 to 2 of 2

Thread: Run-Time Config

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default Run-Time Config

    How many times have you been told that CONFIG settings can only be changed by an ICSP programmer while downloading the program's code?    And how many times did you believe them?   Well, for me, it was every time, until I ran across a BIT that I didn't recognize in the datasheets.

    CFGS: Flash Program/Data EEPROM or Configuration Select bit
        1 = Access Configuration registers
        0 = Access Flash program or data EEPROM memory

    Once I saw that, I knew it could be done, it was just a matter of figuring out how.   The datasheet was really vague, and it simply said that it was similar to writing to Flash Memory. After a little trial and error, I found that it really is just that easy.   So maybe, you want to add a routine to verify that the chip has been programmed with the proper config settings for the program. Or maybe you need to change the settings according to the users input from a menu. Now you can.

    This option is available on every 18F that I've looked at so far, so that means it's been around for years. And, no, it's not available on any 16F's that I've seen.<HR>
    This program presents the following macros:
    <b><pre>@ ReadConfig?CB _CONFIG3H, tempbyte</pre></b>
    Read the contents of a CONFIG register and place the results in a PBP byte variable. The constant for the CONFIG location can be either, one of the pre-defined names from the MPASM .inc file such as _CONFIG1H or _CONFIG3H, or the address of the location like 300001h
    <b><pre>@ ReadConfig?BB AddrByte, tempbyte</pre></b>
    Read the contents of a CONFIG register using a byte offset from the start of the CONFIG address space. For instance, to read register 300001h, the AddrByte variable will have the value 1. The result will be placed in a PBP byte variable.
    <b><pre>@ WriteConfig?CB _CONFIG1L, tempbyte</pre></b>
    Write a byte to the CONFIG register designated by a constant
    <b><pre>@ WriteConfig?BB AddrByte, tempbyte</pre></b>
    Write a byte to the CONFIG register using an offset to the CONFIG adress space
    <b><pre>@ WriteConfig?CC _CONFIG5L, 0Fh</pre></b>
    Write a byte sized constant to the CONFIG register designated by a constant
    <HR>
    Obviously there are some issues to think about before using these macro's. Such as, an oscillator must be running to be able to execute code. So trying to set the oscillator config at run-time will only work if you start off with a configuration that allows a system clock. Other changes in mid stream might put the CCP output on a pin that has a low impeadance signal on the input, causing damage. It's up to you to make sure these things don't happen. Which I guess is no different than if you're using ICSP.
    <br>
    http://www.darreltaylor.com/RTconfig/RTconfig.inc.txt
    http://www.darreltaylor.com/RTconfig/TestConfig.pbp.txt
    DT

  2. #2
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Run-Time Config

    Such as, an oscillator must be running to be able to execute code
    LoL! Or trying to ignore MCLR while the chip is in reset!
    Nice

Similar Threads

  1. A/D conversion with PIC18F67J50
    By ScaleRobotics in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 8th May 2009, 02:48
  2. 18F4550 Bootloader enter via eeprom setting
    By bradb in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 23rd November 2008, 00:51
  3. Error 0X0000008E when connecting a 18F2550 USB HID
    By FranciscoMartin in forum USB
    Replies: 8
    Last Post: - 16th October 2008, 18:20
  4. PortE problems (PIC18F4455)
    By RubenR in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 12th July 2006, 16:26
  5. Installation sequence
    By Demon in forum General
    Replies: 23
    Last Post: - 11th July 2006, 04:56

Members who have read this thread : 1

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