- 17. January 2012: Atypical Curiosity
- 4. January 2012: PIC32MX7 PIM, RB5 pin conflict (solved)
- 30. December 2011: MikroE Mini-32 Board
- 29. December 2011: Donate to Wikipedia
- 28. December 2011: PIC32 Interrupt Nesting (update)
- 20. December 2011: Graphics Library 3.02
- 2. December 2011: Home Brewed IDE for PIC32 assembly development
- 30. November 2011: Yoda Conditions, Egyptian brackets and more...
- 9. November 2011: AVI Player Project (for the uMMB)
- 21. March 2011: More Multimedia Boards
- January 2012
- December 2011
- November 2011
- March 2011
- February 2011
- January 2011
- March 2010
- January 2010
- December 2009
- November 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- January 2009
- December 2008
- November 2008
- October 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
Setting the configuration bits
Speaking of configuration bits, in the book I have made clear from the beginning that I would expect the reader to set them always in a specific configuration chosen for debugging with the Explorer16 board. In fact the checklists titled “Device Configuration for Explorer16 demonstration board” guides the reader through a few steps accessing the “Configure” menu and opening the Configuration Bits dialog box. This dialog box in particular has been enhanced in the latest versions of MPLAB to include one new checkbox at the top titled: “Configuration Bits set in Code“. In order to select the configuration manually, as suggested in the book, this checkbox must be unchecked!
On the other side, with the checkbox checked, we can take advantage of this new feature and make our configuration part of the source code. Before we delve into the details of the syntax to be used, we must consider the pros and cons that come with it, let’s start with the pros:
- Documentation: when publishing the code, the configuration is automatically included
- Permanent association: code and configuration are now permanently joined
On the other side the cons include:
- Device dependence: the configuration is strictly related to the device chosen
- Cryptic: the syntax as we well see shortly is far from readable or self explanatory
- Repetitive: we would need to include the same lines of code at the top of each project in the book or hide them in an include file ad hoc (hence voiding the number 1 pro: documentation)
My preference would be for the first chapters to maintain the use of the manual configuration, which is persistent in MPLAB as we create new projects and more readable. I ‘d suggest a transition to the configuration in code for the later chapters and the more advanced projects.
PIC24 Device Configuration in Code
The MPLAB C30 compiler does not offer any special extension to take care of the device configuration bits, but rather leaves the job to the linker. After all, it is a matter of setting a few bits (initializing) a couple of special locations in FLASH memory, a task easily accomplished by a few pre-processor macros (and the linker).
You will find them inside the device include file “p24fj128ga010.h” almost at the very end of the long long file, including examples of their use and some useful hints on where to place them:
/*
** Only one invocation of CONFIG1 should appear in a project,
** at the top of a C source file (outside of any function).
**
** The following constants can be used to set CONFIG1.
** Multiple options may be combined, as shown:
**
** _CONFIG1( OPT1_ON & OPT2_OFF & OPT3_PLL )
…
*/
To match the device configuration proposed in the book’s checklists, place the following two lines of code at the top of the main source code of each project (but after the #include <p24…> statement):
_CONFIG1( JTAGEN_OFF & GCP_OFF & GWRP_OFF & ICS_PGx2 & FWDTEN_OFF)
_CONFIG2( FNOSC_PRIPLL & FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_HS)
Now you understand what I meant above when I mentioned the code to be a bit cryptic…
2 Responses to “Setting the configuration bits”
Leave a Reply
You must be logged in to post a comment.
10. April 2008 at 19:47
from configuration chapter online…
” _CONFIG2( FNOSC_PRIPLl & FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_HS)”
.. maybe a typo but “PRIPLL” worked for me .. not “PRIPLL”
by the way .. nice book
Mike
10. April 2008 at 19:48
correction .. .. not “PRIPLl”