Configuration Words for the PIC16F690

13 August, 2008 (16:35) | PIC, Tutorials | By: Joshua

So, do you remember, long ago, when I mentioned that I didn’t know why the PICkit 2 would have that warning about configuration words when importing the hex file? No? Well, I did. Anyway, I figured it out and wanted to share with you exactly what I’ve learned. And, as always, now that I know what it means and how to change configuration words, I feel pretty dumb. This tutorial is again specifically oriented for the PIC16F690 but I believe the concepts are universal.

My issue: In a board design, I was planning on using pin 3 for my A/D conversions. However, with the default configuration, pin 3 is setup as the Oscillator Clock Out. This does not jive well with having any form of input. So, I start poking around the data sheet, trying to figure out how to change that. I find it on page 195 of the PIC16F690 datasheet. It tells me what to change, and life is good. I setup my program to change those bits and when I save it, Hi-Tide tells me it doesn’t know what FOSC means. Or any of the other bits from the CONFIG register. Jumping up to page 194 was my answer. In a nice little blue box, it says:

“Address 2007h is beyond the user program memory space. It belongs to the special configuration memory space (2000h-3FFFh), which can be accessed only during programming. See ‘PIC12F6XX/16F6XX Memory Programming Specification’ (DS41204) for more information.”

Roughly translated: “Haha! You can’t change me with your current pool of knowledge! Or should I say puddle?” Insulted by a data sheet. Harsh.

But, eventually, the answer was made known to me.

Configuration words can only be changed when you’re programming it (even I understood that from the mean-spirited data sheet) but they’re still decided on in the C program. Near the beginning of your program, you should start a line with a double underscore (remember: 2 underscores) followed by CONFIG, like this: __CONFIG. Have I stressed the double underscore enough?

Open a parentheses directly after CONFIG and then simply type in the number you want for your configuration, close the parentheses, and tack on a semicolon. Using the information in the data sheet about the configuration word, you can set each bit as you need. Example of a default configuration would be:

__CONFIG(0b111111111111); or __CONFIG(0×0FFF);

HI-TIDE has an easier way of doing this. In the include file, it has defined names for the different configurations. In the left hand panel, you can find your include files, and they’ll be defined with more intelligible names in that file. For me, they were located near the very bottom of the file.

Header File for PIC16F690

And then you simply put what you want together like this:

__CONFIG(WDTEN & PWRTEN & MCLREN & BOREN & UNPROTECT & INTIO);

Which is much more intelligible. I can look at that and say, “Hmmm… I’m enabling the Watch Dog Timer, the Power Up Timer, the Master Clear Reset, Brown Out Reset, I’m leaving my code unprotected for anybody to steal, and changing the oscillator so that pin 3 is now a regular I/O pin.” Convenient, huh?

With this configuration line, you won’t get the warning message as you import your hex file into the PICkit 2. You also have greater control over your PIC and much more flexibility.

As always, this may seem crystal clear to me, but if it’s not to you, let me know and I’ll try and clear up as much confusion as I can.

Comments

Comment from Leblanc Meneses
Time October 14, 2008 at 11:30 pm

I’ve finally sat down to learn the pic.

Great blog by the way. Very useful information. I’ll be checking here often!

-lm

Pingback from if else question – Electronic Circuits Projects Diagrams Free
Time November 30, 2009 at 7:21 pm

[...] Is that why they make you disable it? to allow you to use it as i/o as well? After looking on this page I discovered that if I put #include <htc.h> instead of pic.h it works too, without the [...]

Write a comment