need help in CONFIG of PIC18f458

Discussion in 'Embedded Systems and Microcontrollers' started by ect_09, May 7, 2013.

  1. ect_09

    Thread Starter Member

    May 6, 2012
    180
    1
    can any one tell me how to config PIC18f458.
    i search but didnt get useful answer.

    __CONFIG(HS & WDTDIS & PWRTDIS & BORDIS & LVPDIS& DUNPROT & WRTEN & DEBUGDIS & UNPROTECT);

    my friend told me that its necessary that you use this.
    but it gives error when i write code for PIC18f458 in MPLAB.

    i think ,for pic18f458 its different.
    but i dont know how to select these parameter.
    kindly guide me in this way.
    THANKS...
     
  2. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Search for the header file for your device(pic18f458.h) in your compiler library directory. Then see what the names are for the bit masking(e.g. WDTDIS)...
     
  3. JohnInTX

    Moderator

    Jun 26, 2012
    2,347
    1,029
    Look at P18F458.inc in the MPLAB install directory C:\Program Files(x86)\Microchip\MPASM Suite for the various config switches available. Note that the __CONFIG directive has been superseded by the CONFIG directive i.e.
    CONFIG OSC=XT
    CONFIG PWRT=ON
    etc.
    Be sure to read the databook and configure all of the various parameters to fit YOUR application.

    This is from P18F458.h for MPLAB 8.63 and shows all of the values for the various CONFIG fields.

    Code ( (Unknown Language)):
    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. ;     OSC = LP             LP oscillator
    9. ;     OSC = XT             XT oscillator
    10. ;     OSC = HS             HS oscillator
    11. ;     OSC = RC             RC oscillator
    12. ;     OSC = EC             EC oscillator w/ OSC2 configured as divide-by-4 clock output
    13. ;     OSC = ECIO           EC oscillator w/ OSC2 configured as RA6
    14. ;     OSC = HSPLL          HS oscillator with PLL enabled/Clock frequency = (4 x FOSC)
    15. ;     OSC = RCIO           RC oscillator w/ OSC2 configured as RA6
    16. ;
    17. ;   Oscillator System Clock Switch Enable bit:
    18. ;     OSCS = ON            Oscillator system clock switch option is enabled (oscillator switching is enabled)
    19. ;     OSCS = OFF           Oscillator system clock switch option is disabled (main oscillator is source)
    20. ;
    21. ;   Power-up Timer Enable bit:
    22. ;     PWRT = ON            PWRT enabled
    23. ;     PWRT = OFF           PWRT disabled
    24. ;
    25. ;   Brown-out Reset Enable bit:
    26. ;     BOR = OFF            Brown-out Reset disabled
    27. ;     BOR = ON             Brown-out Reset enabled
    28. ;
    29. ;   Brown-out Reset Voltage bits:
    30. ;     BORV = 45            VBOR set to 4.5V
    31. ;     BORV = 42            VBOR set to 4.2V
    32. ;     BORV = 27            VBOR set to 2.7V
    33. ;     BORV = 25            VBOR set to 2.5V
    34. ;
    35. ;   Watchdog Timer Enable bit:
    36. ;     WDT = OFF            WDT disabled (control is placed on the SWDTEN bit)
    37. ;     WDT = ON             WDT enabled
    38. ;
    39. ;   Watchdog Timer Postscale Select bits:
    40. ;     WDTPS = 1            1:1
    41. ;     WDTPS = 2            1:2
    42. ;     WDTPS = 4            1:4
    43. ;     WDTPS = 8            1:8
    44. ;     WDTPS = 16           1:16
    45. ;     WDTPS = 32           1:32
    46. ;     WDTPS = 64           1:64
    47. ;     WDTPS = 128          1:128
    48. ;
    49. ;   Stack Full/Underflow Reset Enable bit:
    50. ;     STVR = OFF           Stack Full/Underflow will not cause Reset
    51. ;     STVR = ON            Stack Full/Underflow will cause Reset
    52. ;
    53. ;   Low-Voltage ICSP Enable bit:
    54. ;     LVP = OFF            Low-Voltage ICSP disabled
    55. ;     LVP = ON             Low-Voltage ICSP enabled
    56. ;
    57. ;   Background Debugger Enable bit:
    58. ;     DEBUG = ON           Background Debugger enabled. RB6 and RB7 are dedicated to In-Circuit Debug.
    59. ;     DEBUG = OFF          Background Debugger disabled. RB6 and RB7 configured as general purpose I/O pins.
    60. ;
    61. ;   Code Protection bit:
    62. ;     CP0 = ON             Block 0 (000200-001FFFh) code protected
    63. ;     CP0 = OFF            Block 0 (000200-001FFFh) not code protected
    64. ;
    65. ;   Code Protection bit:
    66. ;     CP1 = ON             Block 1 (002000-003FFFh) code protected
    67. ;     CP1 = OFF            Block 1 (002000-003FFFh) not code protected
    68. ;
    69. ;   Code Protection bit:
    70. ;     CP2 = ON             Block 2 (004000-005FFFh) code protected
    71. ;     CP2 = OFF            Block 2 (004000-005FFFh) not code protected
    72. ;
    73. ;   Code Protection bit:
    74. ;     CP3 = ON             Block 3 (006000-007FFFh) code protected
    75. ;     CP3 = OFF            Block 3 (006000-007FFFh) not code protected
    76. ;
    77. ;   Boot Block Code Protection bit:
    78. ;     CPB = ON             Boot Block (000000-0001FFh) code protected
    79. ;     CPB = OFF            Boot Block (000000-0001FFh) not code protected
    80. ;
    81. ;   Data EEPROM Code Protection bit:
    82. ;     CPD = ON             Data EEPROM code protected
    83. ;     CPD = OFF            Data EEPROM not code protected
    84. ;
    85. ;   Write Protection bit:
    86. ;     WRT0 = ON            Block 0 (000200-001FFFh) write protected
    87. ;     WRT0 = OFF           Block 0 (000200-001FFFh) not write protected
    88. ;
    89. ;   Write Protection bit:
    90. ;     WRT1 = ON            Block 1 (002000-003FFFh) write protected
    91. ;     WRT1 = OFF           Block 1 (002000-003FFFh) not write protected
    92. ;
    93. ;   Write Protection bit:
    94. ;     WRT2 = ON            Block 2 (004000-005FFFh) write protected
    95. ;     WRT2 = OFF           Block 2 (004000-005FFFh) not write protected
    96. ;
    97. ;   Write Protection bit:
    98. ;     WRT3 = ON            Block 3 (006000-007FFFh) write protected
    99. ;     WRT3 = OFF           Block 3 (006000-007FFFh) not write protected
    100. ;
    101. ;   Configuration Register Write Protection bit:
    102. ;     WRTC = ON            Configuration registers (300000-3000FFh) write protected
    103. ;     WRTC = OFF           Configuration registers (300000-3000FFh) not write protected
    104. ;
    105. ;   Boot Block Write Protection bit:
    106. ;     WRTB = ON            Boot Block (000000-0001FFh) write protected
    107. ;     WRTB = OFF           Boot Block (000000-0001FFh) not write protected
    108. ;
    109. ;   Data EEPROM Write Protection bit:
    110. ;     WRTD = ON            Data EEPROM write protected
    111. ;     WRTD = OFF           Data EEPROM not write protected
    112. ;
    113. ;   Table Read Protection bit:
    114. ;     EBTR0 = ON           Block 0 (000200-001FFFh) protected from Table Reads executed in other blocks
    115. ;     EBTR0 = OFF          Block 0 (000200-001FFFh) not protected from Table Reads executed in other blocks
    116. ;
    117. ;   Table Read Protection bit:
    118. ;     EBTR1 = ON           Block 1 (002000-003FFFh) protected from Table Reads executed in other blocks
    119. ;     EBTR1 = OFF          Block 1 (002000-003FFFh) not protected from Table Reads executed in other blocks
    120. ;
    121. ;   Table Read Protection bit:
    122. ;     EBTR2 = ON           Block 2 (004000-005FFFh) protected from Table Reads executed in other blocks
    123. ;     EBTR2 = OFF          Block 2 (004000-005FFFh) not protected from Table Reads executed in other blocks
    124. ;
    125. ;   Table Read Protection bit:
    126. ;     EBTR3 = ON           Block 3 (006000-007FFFh) protected from Table Reads executed in other blocks
    127. ;     EBTR3 = OFF          Block 3 (006000-007FFFh) not protected from Table Reads executed in other blocks
    128. ;
    129. ;   Boot Block Table Read Protection bit:
    130. ;     EBTRB = ON           Boot Block (000000-0001FFh) protected from Table Reads executed in other blocks
    131. ;     EBTRB = OFF          Boot Block (000000-0001FFh) not protected from Table Reads executed in other blocks
    132. ;
    For MPLABx, click Window->PIC Memory Views->Configuration Bits. Select each field and specify its value for your application then click Generate Source Code to Output. The Config Bits Source window will open with the assembly source to use. Copy and paste it into your source.

    Always FULLY SPECIFY the config bits.

    Have fun!
     
    absf likes this.
  4. ect_09

    Thread Starter Member

    May 6, 2012
    180
    1
    Code ( (Unknown Language)):
    1.  
    2. ;==========================================================================
    3. ;
    4. ;   IMPORTANT: For the PIC18 devices, the __CONFIG directive has been
    5. ;              superseded by the CONFIG directive.  The following settings
    6. ;              are available for this device.
    7. ;
    8. ;   Oscillator Selection bits:
    9. ;     OSC = LP             LP oscillator
    10. ;     OSC = XT             XT oscillator
    11. ;     OSC = HS             HS oscillator
    12. ;     OSC = RC             RC oscillator
    13. ;     OSC = EC             EC oscillator w/ OSC2 configured as divide-by-4 clock output
    14. ;     OSC = ECIO           EC oscillator w/ OSC2 configured as RA6
    15. ;     OSC = HSPLL          HS oscillator with PLL enabled/Clock frequency = (4 x FOSC)
    16. ;     OSC = RCIO           RC oscillator w/ OSC2 configured as RA6
    17. ;
    18. ;   Oscillator System Clock Switch Enable bit:
    19. ;     OSCS = ON            Oscillator system clock switch option is enabled (oscillator switching is enabled)
    20. ;     OSCS = OFF           Oscillator system clock switch option is disabled (main oscillator is source)
    21. ;
    22. ;   Power-up Timer Enable bit:
    23. ;     PWRT = ON            PWRT enabled
    24. ;     PWRT = OFF           PWRT disabled
    25. ;
    26. ;   Brown-out Reset Enable bit:
    27. ;     BOR = OFF            Brown-out Reset disabled
    28. ;     BOR = ON             Brown-out Reset enabled
    29. ;
    30. ;   Brown-out Reset Voltage bits:
    31. ;     BORV = 45            VBOR set to 4.5V
    32. ;     BORV = 42            VBOR set to 4.2V
    33. ;     BORV = 27            VBOR set to 2.7V
    34. ;     BORV = 25            VBOR set to 2.5V
    35. ;
    36. ;   Watchdog Timer Enable bit:
    37. ;     WDT = OFF            WDT disabled (control is placed on the SWDTEN bit)
    38. ;     WDT = ON             WDT enabled
    39. ;
    40. ;   Watchdog Timer Postscale Select bits:
    41. ;     WDTPS = 1            1:1
    42. ;     WDTPS = 2            1:2
    43. ;     WDTPS = 4            1:4
    44. ;     WDTPS = 8            1:8
    45. ;     WDTPS = 16           1:16
    46. ;     WDTPS = 32           1:32
    47. ;     WDTPS = 64           1:64
    48. ;     WDTPS = 128          1:128
    49. ;
    50. ;   Stack Full/Underflow Reset Enable bit:
    51. ;     STVR = OFF           Stack Full/Underflow will not cause Reset
    52. ;     STVR = ON            Stack Full/Underflow will cause Reset
    53. ;
    54. ;   Low-Voltage ICSP Enable bit:
    55. ;     LVP = OFF            Low-Voltage ICSP disabled
    56. ;     LVP = ON             Low-Voltage ICSP enabled
    57. ;
    58. ;   Background Debugger Enable bit:
    59. ;     DEBUG = ON           Background Debugger enabled. RB6 and RB7 are dedicated to In-Circuit Debug.
    60. ;     DEBUG = OFF          Background Debugger disabled. RB6 and RB7 configured as general purpose I/O pins.
    61. ;
    62. ;   Code Protection bit:
    63. ;     CP0 = ON             Block 0 (000200-001FFFh) code protected
    64. ;     CP0 = OFF            Block 0 (000200-001FFFh) not code protected
    65. ;
    66. ;   Code Protection bit:
    67. ;     CP1 = ON             Block 1 (002000-003FFFh) code protected
    68. ;     CP1 = OFF            Block 1 (002000-003FFFh) not code protected
    69. ;
    70. ;   Code Protection bit:
    71. ;     CP2 = ON             Block 2 (004000-005FFFh) code protected
    72. ;     CP2 = OFF            Block 2 (004000-005FFFh) not code protected
    73. ;
    74. ;   Code Protection bit:
    75. ;     CP3 = ON             Block 3 (006000-007FFFh) code protected
    76. ;     CP3 = OFF            Block 3 (006000-007FFFh) not code protected
    77. ;
    78. ;   Boot Block Code Protection bit:
    79. ;     CPB = ON             Boot Block (000000-0001FFh) code protected
    80. ;     CPB = OFF            Boot Block (000000-0001FFh) not code protected
    81. ;
    82. ;   Data EEPROM Code Protection bit:
    83. ;     CPD = ON             Data EEPROM code protected
    84. ;     CPD = OFF            Data EEPROM not code protected
    85. ;
    86. ;   Write Protection bit:
    87. ;     WRT0 = ON            Block 0 (000200-001FFFh) write protected
    88. ;     WRT0 = OFF           Block 0 (000200-001FFFh) not write protected
    89. ;
    90. ;   Write Protection bit:
    91. ;     WRT1 = ON            Block 1 (002000-003FFFh) write protected
    92. ;     WRT1 = OFF           Block 1 (002000-003FFFh) not write protected
    93. ;
    94. ;   Write Protection bit:
    95. ;     WRT2 = ON            Block 2 (004000-005FFFh) write protected
    96. ;     WRT2 = OFF           Block 2 (004000-005FFFh) not write protected
    97. ;
    98. ;   Write Protection bit:
    99. ;     WRT3 = ON            Block 3 (006000-007FFFh) write protected
    100. ;     WRT3 = OFF           Block 3 (006000-007FFFh) not write protected
    101. ;
    102. ;   Configuration Register Write Protection bit:
    103. ;     WRTC = ON            Configuration registers (300000-3000FFh) write protected
    104. ;     WRTC = OFF           Configuration registers (300000-3000FFh) not write protected
    105. ;
    106. ;   Boot Block Write Protection bit:
    107. ;     WRTB = ON            Boot Block (000000-0001FFh) write protected
    108. ;     WRTB = OFF           Boot Block (000000-0001FFh) not write protected
    109. ;
    110. ;   Data EEPROM Write Protection bit:
    111. ;     WRTD = ON            Data EEPROM write protected
    112. ;     WRTD = OFF           Data EEPROM not write protected
    113. ;
    114. ;   Table Read Protection bit:
    115. ;     EBTR0 = ON           Block 0 (000200-001FFFh) protected from Table Reads executed in other blocks
    116. ;     EBTR0 = OFF          Block 0 (000200-001FFFh) not protected from Table Reads executed in other blocks
    117. ;
    118. ;   Table Read Protection bit:
    119. ;     EBTR1 = ON           Block 1 (002000-003FFFh) protected from Table Reads executed in other blocks
    120. ;     EBTR1 = OFF          Block 1 (002000-003FFFh) not protected from Table Reads executed in other blocks
    121. ;
    122. ;   Table Read Protection bit:
    123. ;     EBTR2 = ON           Block 2 (004000-005FFFh) protected from Table Reads executed in other blocks
    124. ;     EBTR2 = OFF          Block 2 (004000-005FFFh) not protected from Table Reads executed in other blocks
    125. ;
    126. ;   Table Read Protection bit:
    127. ;     EBTR3 = ON           Block 3 (006000-007FFFh) protected from Table Reads executed in other blocks
    128. ;     EBTR3 = OFF          Block 3 (006000-007FFFh) not protected from Table Reads executed in other blocks
    129. ;
    130. ;   Boot Block Table Read Protection bit:
    131. ;     EBTRB = ON           Boot Block (000000-0001FFh) protected from Table Reads executed in other blocks
    132. ;     EBTRB = OFF          Boot Block (000000-0001FFh) not protected from Table Reads executed in other blocks
    133. ;
    134.  
    can i write this in a single line..????
    if yes then how we write this in a single line.
    because it seems to be too long..it will be awkward in looking when writing code..
    in datasheet its available these thing are available..

    i wish that i write that in a single LINE
     
  5. ect_09

    Thread Starter Member

    May 6, 2012
    180
    1
    and i am using MPLAB 8.89.
    HI TECH compiler.

    Thanks..
     
  6. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Which version of the Hi-Tech C compiler do you use? It could be that you should use this notation insted
    Code ( (Unknown Language)):
    1.  #pragma config OSCS = 0x1
    Take a look at the "C:\Program Files\HI-TECH Software\PICC-18\9.80\docs\18f458.html"
    I prefer copying the full list then comment out what I do not need like this
    Code ( (Unknown Language)):
    1.  
    2. //#pragma config Settings
    3. //Register: CONFIG1H @ 0x300001
    4. //OSCS = Oscillator System Clock Switch Enable bit
    5. //OFF Oscillator system clock switch option is disabled (main oscillator is source)
    6. //ON Oscillator system clock switch option is enabled (oscillator switching is enabled)
    7. //OSC = Oscillator Selection bits
    8. //RC RC oscillator
    9. //RCIO RC oscillator w/ OSC2 configured as RA6
    10. #pragma config XT// XT oscillator
    11. //LP LP oscillator
    12. //HSPLL HS oscillator with PLL enabled/Clock frequency = (4 x FOSC)
    13. //ECIO EC oscillator w/ OSC2 configured as RA6
    14. EC EC oscillator w/ OSC2 configured as divide-by-4 clock output
    15. //HS HS oscillator
    16. //Register: CONFIG2L @ 0x300002
    17. //BOR = Brown-out Reset Enable bit
    18. #pragma config OFF //Brown-out Reset disabled
    19. //ON Brown-out Reset enabled
    20.  
    21.  
     
  7. JohnInTX

    Moderator

    Jun 26, 2012
    2,347
    1,029
    As t06afre says, you should use pragmas to set config bits. Earlier HTC used something like:
    Code ( (Unknown Language)):
    1.     // Power up timer ON, Brownout volts = 4.5, WDT prescaler = 128, WDT enabled                    
    2.     __CONFIG(2, PWRTEN & BORV45 & WDTPS128 & WDTEN);
    but Microchip/HTC recommends using pragmas for compatibility with the newer compilers.

    You can't do that here because the chip has multiple configuration registers. You have to indicate which register to load with the computed value. The pragma does it automatically using info in the .h file. __CONFIG must specify the config register (the 2 in the example above) to put the computed value into. (NOTE: this example is not for a 458 so the register numbering is different, another reason to use pragma).

    If you don't want to clutter up your source, put the config info in a separate .C file in the project. It will be included in the .HEX
     
    Last edited: May 7, 2013
  8. nigelwright7557

    Senior Member

    May 10, 2008
    487
    71
    I always copy these names into the head of my program in case I need to make changes.
     
  9. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,392
    1,606
    These work to configure the first register:
    Code ( (Unknown Language)):
    1. #pragma config OSC = RCIO
    2. #pragma config OSCS = ON
     
  10. ect_09

    Thread Starter Member

    May 6, 2012
    180
    1
    these are enougj to config......?
     
  11. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,392
    1,606
    No, it is just the beginning, it is one register out of ten. That is the format (I got it to compile in HTC) for config statements. You can fill out the rest.

    Inside MPLAB, in the Help menu there is a Topics choice, and in that box I have "PIC18 Config Settings." See if you have that (if not I'll have to send it as I don't know what installed it). The format of that file seems to be used in the HTC compiler so you can just copy and paste what you need.

    What runs your clock? Crystal, RC, high or low frequency?
     
  12. ect_09

    Thread Starter Member

    May 6, 2012
    180
    1
    i selected 20MHz in mplab>debug>setting.
    i checked freq settings there...

    secondly,i didnt find library from the link you give me..
    i download nd installed...but not yet found delayms() ..etc... kindly guide me in this way..
    you are right that if am i want to go advance i have to use libraries ..i agree with you..i just need help to sort out from these problem....

    now a days i just waiting for replies here..nd trying to understand compiler nd other things.
    i think thinking is good before using anything in good manners...
    thank you....
     
  13. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Again it would be very helpful to know which version of the HI-Tech C compiler you are using. Also your CPU clock speed will depend on other settings than the 20MHz setting in the debugger menu. Will you be using a crystal or the internal oscillator. As a start I recommend using the internal oscillator.
     
  14. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,392
    1,606
    I would strongly recommend you do NOT use the internal oscillator in your PIC18f458, as it does not have one. ;)

    Your choices are:
    1. LP Low-Power Crystal
    2. XT Crystal/Resonator
    3. HS High-Speed Crystal/Resonator
    4. HS4 High-Speed Crystal/Resonator with PLL enabled
    5. RC External Resistor/Capacitor
    6. RCIO External Resistor/Capacitor with I/O pin enabled
    7. EC External Clock
    8. ECIO External Clock with I/O pin enabled
     
    ect_09 likes this.
  15. ect_09

    Thread Starter Member

    May 6, 2012
    180
    1
    i dont know which version of HI Tech..i download latest version..internal or external osscillator selection depends on selection internally e.g T0 register has selection i.e 1 for external 0 for internal
     
  16. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Which version you use will show up every time you compile:rolleyes:
     
  17. ect_09

    Thread Starter Member

    May 6, 2012
    180
    1
    its HI Tech compiler 9.80..
    sorry for late reply....bad internet here..
     
  18. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Ok that is good. In the compiler install folder ...\HI-TECH Software\PICC-18\9.80\docs you will find the manual and also a template for setting the config words(18f458.html). The first thing you can try is to write a very simple program blinking a LED. Feel free to post it here for audit. But remember to tell us what kind system clock source you use
     
    ect_09 likes this.
  19. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,392
    1,606
    Great, that is the one I just got. So the config pragma statements work with it.

    Also,I just tried the Microchip TimeDelay.c file withHTC, and it compiled just fine. It was a bit of work to get the paths and such defined but it worked.
     
Loading...