pic programming configuration

Thread Starter

ugeshkumar

Joined Nov 27, 2015
16
hi

I am learning pic programming
In MPLAB __config(0x3fba) we given ,in that 3fba mean address value get from config_bit option ,what is that "0x" please give the answer ?
 

MaxHeadRoom

Joined Jul 18, 2013
28,698
0x3fba intended to indicate the 3fba is an hexadecimal value, in this case 16 bit.
0x Used by Picmicro etc.
Max.
 
Last edited:

JohnInTX

Joined Jun 26, 2012
4,787
What Max said plus it is not an address value, it is the value to be stored in the PICs configuration register. MPASM knows where it is so you don't have to. In most cases, it isn't normally accessible for reading by the PIC's program.

The CONFIG is better understood if you use the declarations in the header file. For example, the following snippet is from P16F77.inc - the header file for a PIC16F77. All CONFIG options are named and their bit values in the config register assigned:
Code:
;==========================================================================
;
;       Configuration Bits
;
;   NAME            Address
;   CONFIG            2007h
;
;==========================================================================

; The following is an assignment of address values for all of the
; configuration registers for the purpose of table reads
_CONFIG          EQU  H'2007'

;----- CONFIG Options --------------------------------------------------
_LP_OSC              EQU  H'3FFC'    ; LP oscillator
_XT_OSC              EQU  H'3FFD'    ; XT oscillator
_HS_OSC              EQU  H'3FFE'    ; HS oscillator
_RC_OSC              EQU  H'3FFF'    ; RC oscillator

_WDT_OFF             EQU  H'3FFB'    ; WDT disabled
_WDT_ON              EQU  H'3FFF'    ; WDT enabled

_PWRTE_ON            EQU  H'3FF7'    ; PWRT enabled
_PWRTE_OFF           EQU  H'3FFF'    ; PWRT disabled

_CP_ALL              EQU  H'3FEF'    ; All Memory locations code protected
_CP_OFF              EQU  H'3FFF'    ; Code protection off

_BODEN_OFF           EQU  H'3FBF'    ; BOR disabled
_BODEN_ON            EQU  H'3FFF'    ; BOR enabled
You include the header file in your build then use the CONFIG directive to combine all of your settings into the 16bit value:
Code:
          ; Configuration bits for programming the chip
; Use this:
          __CONFIG _BODEN_ON & _CP_OFF & _HS_OSC & _PWRTE_ON & WDT_ON
;  Not this:
          __CONFIG 0x3ff6
This version of the CONFIG directive ANDs the values for each setting together, generating a 16bit value that gets programmed in the PICs config register. In this case, the value is 0x3FF6. You can specify it as a hard number like your example but that's to be highly discouraged for a couple of reasons. First, nobody knows what 0x3fba means to a 16F77 - you'd have to hit the datasheet and do the math yourself. That makes it hard for people to try to help you. Second, if you ever change chips, even in the same family, the settings may be different or move. If you use a construct like WDT_ON along with the header file for the new PIC, it will make the changes automatic. In those cases where a setting isn't implemented on a chip or is implemented differently, those declarations will change and MPASM will likely flag an error that you can investigate. Using a hard-coded number won't do that.

Keep in mind that there are a couple of different versions of the CONFIG directive. Use the one recommended for your chip and language. The one you show is an older construct. See the help files for MPASM or your compiler for more info.

Good luck.
 
Last edited:

MaxHeadRoom

Joined Jul 18, 2013
28,698
As to different versions take note Pic has changed CONFIG method now.
as per the INC file:
Code:
;
;  IMPORTANT: For the PIC18 devices, the __CONFIG directive has been
;  superseded by the CONFIG directive.  The following settings
;  are available for this device.
;
;  Oscillator Selection bits:
;  FOSC = LP  LP oscillator
;  FOSC = XT  XT oscillator
;  FOSC = HS  HS oscillator
;  FOSC = RC  External RC oscillator, CLKOUT function on RA6
;  FOSC = EC  EC oscillator, CLKOUT function on RA6
;  FOSC = ECIO6  EC oscillator, port function on RA6
;  FOSC = HSPLL  HS oscillator, PLL enabled (Clock Frequency = 4 x FOSC1)
;  FOSC = RCIO6  External RC oscillator, port function on RA6
;  FOSC = INTIO67  Internal oscillator block, port function on RA6 and RA7
;  FOSC = INTIO7  Internal oscillator block, CLKOUT function on RA6, port function on RA7
;
;  Fail-Safe Clock Monitor Enable bit:
;  FCMEN = OFF  Fail-Safe Clock Monitor disabled
;  FCMEN = ON  Fail-Safe Clock Monitor enabled
;
;  Internal/External Oscillator Switchover bit:
;  IESO = OFF  Oscillator Switchover mode disabled
;  IESO = ON  Oscillator Switchover mode enabled
;
;  Power-up Timer Enable bit:
;  PWRT = ON  PWRT enabled
;  PWRT = OFF  PWRT disabled
;
;  Brown-out Reset Enable bits:
;  BOREN = OFF  Brown-out Reset disabled in hardware and software
;  BOREN = ON  Brown-out Reset enabled and controlled by software (SBOREN is enabled)
;  BOREN = NOSLP  Brown-out Reset enabled in hardware only and disabled in Sleep mode (SBOREN is disabled)
;  BOREN = SBORDIS  Brown-out Reset enabled in hardware only (SBOREN is disabled)
;
;  Brown Out Reset Voltage bits:
;  BORV = 30  VBOR set to 3.0 V nominal
;  BORV = 27  VBOR set to 2.7 V nominal
;  BORV = 22  VBOR set to 2.2 V nominal
;  BORV = 18  VBOR set to 1.8 V nominal
;
;  Watchdog Timer Enable bit:
;  WDTEN = OFF  WDT is controlled by SWDTEN bit of the WDTCON register
;  WDTEN = ON  WDT is always enabled. SWDTEN bit has no effect
;
;  Watchdog Timer Postscale Select bits:
;  WDTPS = 1  1:1
;  WDTPS = 2  1:2
;  WDTPS = 4  1:4
;  WDTPS = 8  1:8
;  WDTPS = 16  1:16
;  WDTPS = 32  1:32
;  WDTPS = 64  1:64
;  WDTPS = 128  1:128
;  WDTPS = 256  1:256
;  WDTPS = 512  1:512
;  WDTPS = 1024  1:1024
;  WDTPS = 2048  1:2048
;  WDTPS = 4096  1:4096
;  WDTPS = 8192  1:8192
;  WDTPS = 16384  1:16384
;  WDTPS = 32768  1:32768
;
;  CCP2 MUX bit:
;  CCP2MX = PORTBE  CCP2 input/output is multiplexed with RB3
;  CCP2MX = PORTC  CCP2 input/output is multiplexed with RC1
;
;  PORTB A/D Enable bit:
;  PBADEN = OFF  PORTB<4:0> pins are configured as digital I/O on Reset
;  PBADEN = ON  PORTB<4:0> pins are configured as analog input channels on Reset
;
;  Low-Power Timer1 Oscillator Enable bit:
;  LPT1OSC = OFF  Timer1 configured for higher power operation
;  LPT1OSC = ON  Timer1 configured for low-power operation
;
;  HFINTOSC Fast Start-up:
;  HFOFST = OFF  The system clock is held off until the HFINTOSC is stable.
;  HFOFST = ON  HFINTOSC starts clocking the CPU without waiting for the oscillator to stablize.
;
etc, etc.
Max.

Moderators note: used code tags
 
Top