I've be pondering the implications of: static __code char __at(__CONFIG1H)
(A sample extract). I've never really used __config while writing code with Mplab
although I'm aware that the type exists. I can compile/assemble code even without
this definition and still get the code to work. What is the difference it will create when
used in the program ? Do I gain any significant advantage ?
Also, what would be the default micro response when these bits are not configured ?
Awaiting your response.
I think I understand your question, but if this isn't the answer then please ask again…
There are 2 ways to define the configuration bits. The way that you are referring to (using __config) is included in your code (usually at the top of some main.c file). This a hard coded value in your executable and it means that if you change to a different chip, you'll need to change your config (or use #ifdef for your chip type with the configuration for each chip you support).
The second way, is to use the development environment. You can set the configuration for your project(s). So that if you change chip types, you can can set the configuration (or have a default for each chip type) and you can re-compile the same code (assuming the code is valid for both chip types).
Since you haven't been using it, I would guess that you're using the default configuration file (which is typically all 0's for the configuration) - don't quote me on this.
If you need a certain configuration on (in other words setting some of the configuration bits to 1's) then you HAVE to have them set in your project OR in a __config(). For example (I'll use pic18f4455), an external oscillator is usually set in config1h - bits 3-0 set the oscillator source. If you're using an external oscillator then these bits would be all 0 (so you would be ok if you used the default configuration that sets these to all 0). However, if you wanted to use the internal oscillator, you would need to set these bits to one of these values depending on your needs (1011, 1010, 1001, 1000). If you didn't set these, then the pic would be waiting for the next oscillation from an external source and it would never get it from a non-existant external oscillator - I did this by accident and it would never do anything until my hand got close to the chip and some magnetic field would transfer to the oscillator pins and it would start doing instructions until I pulled my hand away and it would stop - very annoying and frustrating to think that some "magical" touch by me would make it work.
If you're just coding for yourself, then do whichever method suits you. If you're gonna post some code for others, I would use the __config() so that people can see what you did.
You can verify this by looking at the ".hex" file. The configuration bytes/words/bits are visible at their specified memory location and you can check these values against what you think they should be.
Thanks a lot. That answered my question. Sorry for the late response.
Log in to post a comment.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.