pic programming configuration

Discussion in 'Programmer's Corner' started by ugeshkumar, Jul 16, 2016.

  1. ugeshkumar

    Thread Starter New Member

    Nov 27, 2015
    16
    0
    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 ?
     
  2. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,542
    2,369
    0x3fba intended to indicate the 3fba is an hexadecimal value, in this case 16 bit.
    0x Used by Picmicro etc.
    Max.
     
    Last edited: Jul 16, 2016
  3. JohnInTX

    Moderator

    Jun 26, 2012
    2,345
    1,028
    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 (Microchip Assembler):
    1. ;==========================================================================
    2. ;
    3. ;       Configuration Bits
    4. ;
    5. ;   NAME            Address
    6. ;   CONFIG            2007h
    7. ;
    8. ;==========================================================================
    9.  
    10. ; The following is an assignment of address values for all of the
    11. ; configuration registers for the purpose of table reads
    12. _CONFIG          EQU  H'2007'
    13.  
    14. ;----- CONFIG Options --------------------------------------------------
    15. _LP_OSC              EQU  H'3FFC'    ; LP oscillator
    16. _XT_OSC              EQU  H'3FFD'    ; XT oscillator
    17. _HS_OSC              EQU  H'3FFE'    ; HS oscillator
    18. _RC_OSC              EQU  H'3FFF'    ; RC oscillator
    19.  
    20. _WDT_OFF             EQU  H'3FFB'    ; WDT disabled
    21. _WDT_ON              EQU  H'3FFF'    ; WDT enabled
    22.  
    23. _PWRTE_ON            EQU  H'3FF7'    ; PWRT enabled
    24. _PWRTE_OFF           EQU  H'3FFF'    ; PWRT disabled
    25.  
    26. _CP_ALL              EQU  H'3FEF'    ; All Memory locations code protected
    27. _CP_OFF              EQU  H'3FFF'    ; Code protection off
    28.  
    29. _BODEN_OFF           EQU  H'3FBF'    ; BOR disabled
    30. _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 (Microchip Assembler):
    1.           ; Configuration bits for programming the chip
    2. ; Use this:
    3.           __CONFIG _BODEN_ON & _CP_OFF & _HS_OSC & _PWRTE_ON & WDT_ON
    4. ;  Not this:
    5.           __CONFIG 0x3ff6
    6.  
    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: Jul 16, 2016
  4. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,542
    2,369
    As to different versions take note Pic has changed CONFIG method now.
    as per the INC file:
    Code (Text):
    1.  
    2. ;
    3. ;  IMPORTANT: For the PIC18 devices, the __CONFIG directive has been
    4. ;  superseded by the CONFIG directive.  The following settings
    5. ;  are available for this device.
    6. ;
    7. ;  Oscillator Selection bits:
    8. ;  FOSC = LP  LP oscillator
    9. ;  FOSC = XT  XT oscillator
    10. ;  FOSC = HS  HS oscillator
    11. ;  FOSC = RC  External RC oscillator, CLKOUT function on RA6
    12. ;  FOSC = EC  EC oscillator, CLKOUT function on RA6
    13. ;  FOSC = ECIO6  EC oscillator, port function on RA6
    14. ;  FOSC = HSPLL  HS oscillator, PLL enabled (Clock Frequency = 4 x FOSC1)
    15. ;  FOSC = RCIO6  External RC oscillator, port function on RA6
    16. ;  FOSC = INTIO67  Internal oscillator block, port function on RA6 and RA7
    17. ;  FOSC = INTIO7  Internal oscillator block, CLKOUT function on RA6, port function on RA7
    18. ;
    19. ;  Fail-Safe Clock Monitor Enable bit:
    20. ;  FCMEN = OFF  Fail-Safe Clock Monitor disabled
    21. ;  FCMEN = ON  Fail-Safe Clock Monitor enabled
    22. ;
    23. ;  Internal/External Oscillator Switchover bit:
    24. ;  IESO = OFF  Oscillator Switchover mode disabled
    25. ;  IESO = ON  Oscillator Switchover mode enabled
    26. ;
    27. ;  Power-up Timer Enable bit:
    28. ;  PWRT = ON  PWRT enabled
    29. ;  PWRT = OFF  PWRT disabled
    30. ;
    31. ;  Brown-out Reset Enable bits:
    32. ;  BOREN = OFF  Brown-out Reset disabled in hardware and software
    33. ;  BOREN = ON  Brown-out Reset enabled and controlled by software (SBOREN is enabled)
    34. ;  BOREN = NOSLP  Brown-out Reset enabled in hardware only and disabled in Sleep mode (SBOREN is disabled)
    35. ;  BOREN = SBORDIS  Brown-out Reset enabled in hardware only (SBOREN is disabled)
    36. ;
    37. ;  Brown Out Reset Voltage bits:
    38. ;  BORV = 30  VBOR set to 3.0 V nominal
    39. ;  BORV = 27  VBOR set to 2.7 V nominal
    40. ;  BORV = 22  VBOR set to 2.2 V nominal
    41. ;  BORV = 18  VBOR set to 1.8 V nominal
    42. ;
    43. ;  Watchdog Timer Enable bit:
    44. ;  WDTEN = OFF  WDT is controlled by SWDTEN bit of the WDTCON register
    45. ;  WDTEN = ON  WDT is always enabled. SWDTEN bit has no effect
    46. ;
    47. ;  Watchdog Timer Postscale Select bits:
    48. ;  WDTPS = 1  1:1
    49. ;  WDTPS = 2  1:2
    50. ;  WDTPS = 4  1:4
    51. ;  WDTPS = 8  1:8
    52. ;  WDTPS = 16  1:16
    53. ;  WDTPS = 32  1:32
    54. ;  WDTPS = 64  1:64
    55. ;  WDTPS = 128  1:128
    56. ;  WDTPS = 256  1:256
    57. ;  WDTPS = 512  1:512
    58. ;  WDTPS = 1024  1:1024
    59. ;  WDTPS = 2048  1:2048
    60. ;  WDTPS = 4096  1:4096
    61. ;  WDTPS = 8192  1:8192
    62. ;  WDTPS = 16384  1:16384
    63. ;  WDTPS = 32768  1:32768
    64. ;
    65. ;  CCP2 MUX bit:
    66. ;  CCP2MX = PORTBE  CCP2 input/output is multiplexed with RB3
    67. ;  CCP2MX = PORTC  CCP2 input/output is multiplexed with RC1
    68. ;
    69. ;  PORTB A/D Enable bit:
    70. ;  PBADEN = OFF  PORTB<4:0> pins are configured as digital I/O on Reset
    71. ;  PBADEN = ON  PORTB<4:0> pins are configured as analog input channels on Reset
    72. ;
    73. ;  Low-Power Timer1 Oscillator Enable bit:
    74. ;  LPT1OSC = OFF  Timer1 configured for higher power operation
    75. ;  LPT1OSC = ON  Timer1 configured for low-power operation
    76. ;
    77. ;  HFINTOSC Fast Start-up:
    78. ;  HFOFST = OFF  The system clock is held off until the HFINTOSC is stable.
    79. ;  HFOFST = ON  HFINTOSC starts clocking the CPU without waiting for the oscillator to stablize.
    80. ;
    81. etc, etc.
    82.  
    Max.

    Moderators note: used code tags
     
    JohnInTX likes this.
Loading...