Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Hi-Tech C Config statement ?

Status
Not open for further replies.

Z.K.

New Member
I am really new to programming PIC microcontrollers. I was wondering how do I know what to put in the __CONFIG(); statement. I looked at the datasheet, but it is not really clear. I have a book, but it is not all that clear either. Since I am a bit confused, I thought I would ask some experts. I am using a PIC16F877A microcontroller and I just want to do something really simple like make an LED blink.

:confused:
 
If I'm for example using a PIC16F628a I do the following to figure them all out (probably the wrong method, but it's the way I do it)
I open the file:
C:\Program Files (x86)\HI-TECH Software\PICC\std\9.60\include\pic.h
(may be a slightly different path on your system, eg. if you use a 32-bit system you wouldn't have the (x86) in the path, or maybe PICC18 if programming with a PIC18 device)

In this file I see that the pic16f628a uses the file pic16f62xa.h (searched for 16F628A), so I open the file:
C:\Program Files (x86)\HI-TECH Software\PICC\std\9.60\include\pic16f62xa.h

At the bottom of this file, I see all the Configuration Mask Definitions:
// Configuration Mask Definitions
#define CONFIG_ADDR 0x2007
// Protection of flash memory
#define PROTECT 0x1FFF
#define UNPROTECT 0x3FFF
// Protection of EEPROM data memory
#define CPD 0x3EFF
#define UNPROTECT 0x3FFF
// Low voltage programming enable
#define LVPEN 0x3FFF
#define LVPDIS 0x3F7F
// Brown out detection enable
#define BOREN 0x3FFF
#define BORDIS 0x3FBF
// Master clear reset pin function
#define MCLREN 0x3FFF
#define MCLRDIS 0x3FDF
// Power up timer enable
#define PWRTEN 0x3FF7
#define PWRTDIS 0x3FFF
// Watchdog timer enable
#define WDTEN 0x3FFF
#define WDTDIS 0x3FFB
// Oscillator configurations
#define RCCLK 0x3FFF
#define RCIO 0x3FFE
#define INTCLK 0x3FFD
#define INTIO 0x3FFC
#define EC 0x3FEF
#define HS 0x3FEE
#define XT 0x3FED
#define LP 0x3FEC

Each selection is basically separated by a commend line, so I would make my config word as follows (just an example, select what you'd use for your particular application):
__CONFIG(HS & WDTDIS & MCLREN & PWRTDIS & BORDIS & LVPDIS & UNPROTECT & UNPROTECT);

Now whether putting UNPROTECT in there twice actually does anything, I don't know, but it shows up twice in the include file, so I put it in there for "completeness". Here I've configure it to have an external high-speed oscillator, disabled the watchdog timer, enabled the Master clear reset pin function, disabled the power up timer, disabled the brown out detection, disabled low voltage programming, unprotected EEPROM data memory and unprotected the flash memory.

Hope this helps!
 
If I'm for example using a PIC16F628a I do the following to figure them all out (probably the wrong method, but it's the way I do it)
I open the file:
C:\Program Files (x86)\HI-TECH Software\PICC\std\9.60\include\pic.h
(may be a slightly different path on your system, eg. if you use a 32-bit system you wouldn't have the (x86) in the path, or maybe PICC18 if programming with a PIC18 device)

In this file I see that the pic16f628a uses the file pic16f62xa.h (searched for 16F628A), so I open the file:
C:\Program Files (x86)\HI-TECH Software\PICC\std\9.60\include\pic16f62xa.h

At the bottom of this file, I see all the Configuration Mask Definitions:
// Configuration Mask Definitions
#define CONFIG_ADDR 0x2007
// Protection of flash memory
#define PROTECT 0x1FFF
#define UNPROTECT 0x3FFF
// Protection of EEPROM data memory
#define CPD 0x3EFF
#define UNPROTECT 0x3FFF
// Low voltage programming enable
#define LVPEN 0x3FFF
#define LVPDIS 0x3F7F
// Brown out detection enable
#define BOREN 0x3FFF
#define BORDIS 0x3FBF
// Master clear reset pin function
#define MCLREN 0x3FFF
#define MCLRDIS 0x3FDF
// Power up timer enable
#define PWRTEN 0x3FF7
#define PWRTDIS 0x3FFF
// Watchdog timer enable
#define WDTEN 0x3FFF
#define WDTDIS 0x3FFB
// Oscillator configurations
#define RCCLK 0x3FFF
#define RCIO 0x3FFE
#define INTCLK 0x3FFD
#define INTIO 0x3FFC
#define EC 0x3FEF
#define HS 0x3FEE
#define XT 0x3FED
#define LP 0x3FEC

Each selection is basically separated by a commend line, so I would make my config word as follows (just an example, select what you'd use for your particular application):
__CONFIG(HS & WDTDIS & MCLREN & PWRTDIS & BORDIS & LVPDIS & UNPROTECT & UNPROTECT);

Now whether putting UNPROTECT in there twice actually does anything, I don't know, but it shows up twice in the include file, so I put it in there for "completeness". Here I've configure it to have an external high-speed oscillator, disabled the watchdog timer, enabled the Master clear reset pin function, disabled the power up timer, disabled the brown out detection, disabled low voltage programming, unprotected EEPROM data memory and unprotected the flash memory.

Hope this helps!

Thanks for the explanation. It helps some though hopefully I will get better at understanding this stuff as I am planning on taking an embedded programming course. In any case, I finally managed to figure out how to use my QL200 development board which came with a 16F877A. I did find some examples on the CD which did help also. So, at least I can get the examples to work even if I don't quite understand that CONFIG line. I guess will have to study the datasheet some more.

Thanks again.

:)
 
What don't you understand about your CONFIG word? Perhaps show us the one you're using? For your particular PIC you'd use the pic168xa.h include file, which has the following:
/*osc configurations*/
#define RC 0x3FFF // resistor/capacitor
#define HS 0x3FFE // high speed crystal/resonator
#define XT 0x3FFD // crystal/resonator
#define LP 0x3FFC // low power crystal/resonator

/*watchdog*/
#define WDTEN 0x3FFF // enable watchdog timer
#define WDTDIS 0x3FFB // disable watchdog timer

/*power up timer*/
#define PWRTEN 0x3FF7 // enable power up timer
#define PWRTDIS 0x3FFF // disable power up timer

/*brown out reset*/
#define BOREN 0x3FFF // enable brown out reset
#define BORDIS 0x3FBF // disable brown out reset

/*Low Voltage Programmable*/
#define LVPEN 0x3FFF // low voltage programming enabled
#define LVPDIS 0x3F7F // low voltage programming disabled

/*data code protected*/
#define DP 0x3EFF // protect data code
// alternately
#define DPROT 0x3EFF // use DP
#define DUNPROT 0x3FFF // use UNPROTECT

/* Flash memory write enable/protect */
#define WRTEN 0x3FFF /* flash memory write enabled */
#define WP1 0x3DFF /* protect 0000 - 00FF */
#define WP2 0x3BFF /* protect 0000 - 07FF(76A/77A) / 03FF(73A/74A) */
#define WP3 0x39FF /* protect 0000 - 1FFF(76A/77A) / 0FFF(73A/74A) */

/*debug option*/
#define DEBUGEN 0x37FF // debugger enabled
#define DEBUGDIS 0x3FFF // debugger disabled

/*code protection*/
#define PROTECT 0x1FFF /* protect program code */
#define UNPROTECT 0x3FFF /* do not protect the code */



For this I might use the following CONFIG:
__CONFIG(DEBUGDIS & HS & WDTDIS & PWRTEN & BORDIS & LVPDIS & WRTEN & DUNPROT & UNPROTECT);
 
What don't you understand about your CONFIG word? Perhaps show us the one you're using? For your particular PIC you'd use the pic168xa.h include file, which has the following:
/*osc configurations*/
#define RC 0x3FFF // resistor/capacitor
#define HS 0x3FFE // high speed crystal/resonator
#define XT 0x3FFD // crystal/resonator
#define LP 0x3FFC // low power crystal/resonator

/*watchdog*/
#define WDTEN 0x3FFF // enable watchdog timer
#define WDTDIS 0x3FFB // disable watchdog timer

/*power up timer*/
#define PWRTEN 0x3FF7 // enable power up timer
#define PWRTDIS 0x3FFF // disable power up timer

/*brown out reset*/
#define BOREN 0x3FFF // enable brown out reset
#define BORDIS 0x3FBF // disable brown out reset

/*Low Voltage Programmable*/
#define LVPEN 0x3FFF // low voltage programming enabled
#define LVPDIS 0x3F7F // low voltage programming disabled

/*data code protected*/
#define DP 0x3EFF // protect data code
// alternately
#define DPROT 0x3EFF // use DP
#define DUNPROT 0x3FFF // use UNPROTECT

/* Flash memory write enable/protect */
#define WRTEN 0x3FFF /* flash memory write enabled */
#define WP1 0x3DFF /* protect 0000 - 00FF */
#define WP2 0x3BFF /* protect 0000 - 07FF(76A/77A) / 03FF(73A/74A) */
#define WP3 0x39FF /* protect 0000 - 1FFF(76A/77A) / 0FFF(73A/74A) */

/*debug option*/
#define DEBUGEN 0x37FF // debugger enabled
#define DEBUGDIS 0x3FFF // debugger disabled

/*code protection*/
#define PROTECT 0x1FFF /* protect program code */
#define UNPROTECT 0x3FFF /* do not protect the code */



For this I might use the following CONFIG:
__CONFIG(DEBUGDIS & HS & WDTDIS & PWRTEN & BORDIS & LVPDIS & WRTEN & DUNPROT & UNPROTECT);

I guess I was just a bit confused because I have never used that statement before. I have done very little embedded programming before and the the program I was looking at was
the decimal equivalent in the __CONFIG statement. I understand a bit more now except I am not sure when to enable certain switches in the CONFIG statement. I have the program
working now so I guess I won't worry about it for now. The more I work with PIC I will probably understand more when I get to more complicated circuits. Right now I am just using
very simple circuits so it is probably is not an issue at the moment. Thanks anyway though.
 
Last edited:
After setting the CONFIG reg, then what?

I am quite new to this two. I had tirelessly trying to get the correct frequency out of my pic16f88. Well, the PICC accepted my __CONFIG(0x3F51) which indicates that I am using the INTRC mode. How do I set the pre-scaler from here? How do I write to the OSCCON and other registers to change or tune the register?
Appreciate any help.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top