RuntimeConfig

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?

Attach:Run-Time_Config

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.


This program presents the following macros:

@ ReadConfig?CB _CONFIG3H, tempbyte 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

@ ReadConfig?BB AddrByte, tempbyte 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.

@ WriteConfig?CB _CONFIG1L, tempbyte Write a byte to the CONFIG register designated by a constant

@ WriteConfig?BB AddrByte, tempbyte Write a byte to the CONFIG register using an offset to the CONFIG adress space

@ WriteConfig?CC _CONFIG5L, 0Fh Write a byte sized constant to the CONFIG register designated by a constant


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 impedance 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.

Page last modified on February 08, 2018, at 06:22 PM