The configuration bits specify some of the operating modes of the microcontroller and are written to a register in the PICMicro® as part of the device programming process. The PC software which controls your device programmer may display a dialog box as part of the programming procedure which lets you make mode selections by clicking on buttons. The PC software then assembles the configuration bit pattern and programs it into the device for you. The PICSTART Plus works this way.

As an alternative for the PICSTART Plus and as a necessity for some of the simple programmers, the configuration bit pattern can be called out in the assembly language program listing using the CONFIG assembler directive.

From the PIC16F84 data sheet, the part has a 14-bit configuration word.

	           PIC16F84 Configuration Bits
	13 ___________ 4  3  2  1  0
	  Code protect    |  |  |__|____ Osc type  11 = RC
	     0 = on       |  |                     10 = HS
	     1 = off      |  |__ WDT               01 = XT
	                  |        0 = disabled    00 = LP
	                  |        1 = enabled
	                  |	                  |__ Power-up timer
	                        0 = enabled
	                        1 = disabled
For the program pict1.asm and the other examples in Easy PIC’n, we want the following selections:
	XT oscillator
	WDT disabled
	Power-up timer enabled
	Code protect off
The bit pattern used to accomplish this is: 11111111110001 The hexadecimal equivalent is: 3FF1

The hex version has two extra 0’s on the left, but don’t let that worry you.

To incorporate this in pict1.asm, the “__config” directive is added right below the list directive.

	list		p=16f84
	__config  	h'3ff1'
	radix	  	hex
Notice that the underbar which precedes “config” is a DOUBLE underbar (2 underbars).

The __config directive must come after the list directive in your code.

Including the __config statement in the listing means you won’t have to use the dialog box every time you program a device if your programmer software has one. For the PICSTART Plus, with a project open and assembled file open, enabling the programmer will bring up the dialog box with the modes displayed as determined by the __config directive in your listing. The configuration bits specified by the __config directive take precedence over anything you select using the dialog box, so any changes you may wish to make must be done by changing the configuration “word”.

You may have seen program listings which use the __config directive in the following way:

	__config   _XT_OSC & _WDT_OFF & _PWRTE _ON & _CP_OFF
This format is used in conjunction with Microchip’s Device Header File for the PIC16F84 which is called “p16F84.inc” and may be found in the files which come with MPLAB (under “File” on the menu bar). Using this file requires you to use Microchip’s naming conventions for the devices registers, etc. I prefer to use my own so I can refer to things any way I want instead of looking up how Microchip did it.

Looking at the list of equates for the configuration bits in Microchip’s Device Header File reveals the following:

			_CP_ON     EQU   H'000F'
			_CP_OFF    EQU   H'3FFF'
			_PWRTE_ON  EQU   H'3FF7'
			_WDT_ON    EQU   H'3FFF'
			_WDT_OFF   EQU   H'3FFB'
			_LP_OSC    EQU   H'3FFC'
			_Xt_OSC    EQU   H'3FFD'
			_HS_OSC    EQU   H'3FFE'
			_RC_OSC    EQU   H'3FFF'
Notice that Microchip uses upper case.

The default configuration bit pattern is all 1’s or H’3FFF’. Programming involves changing the 1’s that need changing to 0’s.

The configuration bit equates are repeated with the bit patterns for the least significant for bits along side to make a point.

			_CP_ON     EQU   H'000F'   1111
			_CP_OFF    EQU   H'3FFF'   1111
			_PWRTE_ON  EQU   H'3FF7'   0111
			_PWRTE_OFF EQU   H'3FFF'   1111
			_WDT_ON    EQU   H'3FFF'   1111
			_WDT_OFF   EQU   H'3FFB'   1011
			_LP_OSC    EQU   H'3FFC'   1100
			_Xt_OSC    EQU   H'3FFD'   1101
			_HS_OSC    EQU   H'3FFE'   1110
			_RC_OSC    EQU   H'3FFF'   1111
To program a device using the right combination of options from the above table involves logically ANDing the least significant 4 bits of the selected options to create the final configuration bit pattern. This is done by the assembler.

For our PIC16F84 example above, visualize the following:

			CP off   3FFF   1111
			XT osc   3FFD   1101
			WDT off  3FFB   1011
			PWRTE on 3FF7   0111
			                0001  Result of AND operation.
	__config   _XT_OSC & _WDT_OFF & _PWRTE _ON & _CP_OFF
Notice the “&” symbols.

To incorporate this method in pict1.asm:

	list		p=16f84
	__config   _XT_OSC & _WDT_OFF & _PWRTE _ON & _CP_OFF
	radix		hex
Again, the “__config” directive is added right below the list directive. Microchip’s Device Header File must be used as an include file or you can add the configuration bit equates to your own assembly source file if you wish.

All these methods work. If you are using a bare bones programmer, you may not have a choice. Beyond that, choosing a method is a matter of personal preference.

 ©Square 1 Electronics 1996-2001

| Home | Back to Updates Page | Contact Us