need help in CONFIG of PIC18f458

Thread Starter

ect_09

Joined May 6, 2012
180
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...
 

tshuck

Joined Oct 18, 2012
3,534
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...
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)...
 

JohnInTX

Joined Jun 26, 2012
4,787
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.

Rich (BB 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:
;     OSC = LP             LP oscillator
;     OSC = XT             XT oscillator
;     OSC = HS             HS oscillator
;     OSC = RC             RC oscillator
;     OSC = EC             EC oscillator w/ OSC2 configured as divide-by-4 clock output
;     OSC = ECIO           EC oscillator w/ OSC2 configured as RA6
;     OSC = HSPLL          HS oscillator with PLL enabled/Clock frequency = (4 x FOSC)
;     OSC = RCIO           RC oscillator w/ OSC2 configured as RA6
;
;   Oscillator System Clock Switch Enable bit:
;     OSCS = ON            Oscillator system clock switch option is enabled (oscillator switching is enabled)
;     OSCS = OFF           Oscillator system clock switch option is disabled (main oscillator is source)
;
;   Power-up Timer Enable bit:
;     PWRT = ON            PWRT enabled
;     PWRT = OFF           PWRT disabled
;
;   Brown-out Reset Enable bit:
;     BOR = OFF            Brown-out Reset disabled
;     BOR = ON             Brown-out Reset enabled
;
;   Brown-out Reset Voltage bits:
;     BORV = 45            VBOR set to 4.5V
;     BORV = 42            VBOR set to 4.2V
;     BORV = 27            VBOR set to 2.7V
;     BORV = 25            VBOR set to 2.5V
;
;   Watchdog Timer Enable bit:
;     WDT = OFF            WDT disabled (control is placed on the SWDTEN bit)
;     WDT = ON             WDT enabled
;
;   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
;
;   Stack Full/Underflow Reset Enable bit:
;     STVR = OFF           Stack Full/Underflow will not cause Reset
;     STVR = ON            Stack Full/Underflow will cause Reset
;
;   Low-Voltage ICSP Enable bit:
;     LVP = OFF            Low-Voltage ICSP disabled
;     LVP = ON             Low-Voltage ICSP enabled
;
;   Background Debugger Enable bit:
;     DEBUG = ON           Background Debugger enabled. RB6 and RB7 are dedicated to In-Circuit Debug.
;     DEBUG = OFF          Background Debugger disabled. RB6 and RB7 configured as general purpose I/O pins.
;
;   Code Protection bit:
;     CP0 = ON             Block 0 (000200-001FFFh) code protected
;     CP0 = OFF            Block 0 (000200-001FFFh) not code protected
;
;   Code Protection bit:
;     CP1 = ON             Block 1 (002000-003FFFh) code protected
;     CP1 = OFF            Block 1 (002000-003FFFh) not code protected
;
;   Code Protection bit:
;     CP2 = ON             Block 2 (004000-005FFFh) code protected
;     CP2 = OFF            Block 2 (004000-005FFFh) not code protected
;
;   Code Protection bit:
;     CP3 = ON             Block 3 (006000-007FFFh) code protected
;     CP3 = OFF            Block 3 (006000-007FFFh) not code protected
;
;   Boot Block Code Protection bit:
;     CPB = ON             Boot Block (000000-0001FFh) code protected
;     CPB = OFF            Boot Block (000000-0001FFh) not code protected
;
;   Data EEPROM Code Protection bit:
;     CPD = ON             Data EEPROM code protected
;     CPD = OFF            Data EEPROM not code protected
;
;   Write Protection bit:
;     WRT0 = ON            Block 0 (000200-001FFFh) write protected
;     WRT0 = OFF           Block 0 (000200-001FFFh) not write protected
;
;   Write Protection bit:
;     WRT1 = ON            Block 1 (002000-003FFFh) write protected
;     WRT1 = OFF           Block 1 (002000-003FFFh) not write protected
;
;   Write Protection bit:
;     WRT2 = ON            Block 2 (004000-005FFFh) write protected
;     WRT2 = OFF           Block 2 (004000-005FFFh) not write protected
;
;   Write Protection bit:
;     WRT3 = ON            Block 3 (006000-007FFFh) write protected
;     WRT3 = OFF           Block 3 (006000-007FFFh) not write protected
;
;   Configuration Register Write Protection bit:
;     WRTC = ON            Configuration registers (300000-3000FFh) write protected
;     WRTC = OFF           Configuration registers (300000-3000FFh) not write protected
;
;   Boot Block Write Protection bit:
;     WRTB = ON            Boot Block (000000-0001FFh) write protected
;     WRTB = OFF           Boot Block (000000-0001FFh) not write protected
;
;   Data EEPROM Write Protection bit:
;     WRTD = ON            Data EEPROM write protected
;     WRTD = OFF           Data EEPROM not write protected
;
;   Table Read Protection bit:
;     EBTR0 = ON           Block 0 (000200-001FFFh) protected from Table Reads executed in other blocks
;     EBTR0 = OFF          Block 0 (000200-001FFFh) not protected from Table Reads executed in other blocks
;
;   Table Read Protection bit:
;     EBTR1 = ON           Block 1 (002000-003FFFh) protected from Table Reads executed in other blocks
;     EBTR1 = OFF          Block 1 (002000-003FFFh) not protected from Table Reads executed in other blocks
;
;   Table Read Protection bit:
;     EBTR2 = ON           Block 2 (004000-005FFFh) protected from Table Reads executed in other blocks
;     EBTR2 = OFF          Block 2 (004000-005FFFh) not protected from Table Reads executed in other blocks
;
;   Table Read Protection bit:
;     EBTR3 = ON           Block 3 (006000-007FFFh) protected from Table Reads executed in other blocks
;     EBTR3 = OFF          Block 3 (006000-007FFFh) not protected from Table Reads executed in other blocks
;
;   Boot Block Table Read Protection bit:
;     EBTRB = ON           Boot Block (000000-0001FFh) protected from Table Reads executed in other blocks
;     EBTRB = OFF          Boot Block (000000-0001FFh) not protected from Table Reads executed in other blocks
;
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!
 

Thread Starter

ect_09

Joined May 6, 2012
180
Rich (BB 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:
;     OSC = LP             LP oscillator
;     OSC = XT             XT oscillator
;     OSC = HS             HS oscillator
;     OSC = RC             RC oscillator
;     OSC = EC             EC oscillator w/ OSC2 configured as divide-by-4 clock output
;     OSC = ECIO           EC oscillator w/ OSC2 configured as RA6
;     OSC = HSPLL          HS oscillator with PLL enabled/Clock frequency = (4 x FOSC)
;     OSC = RCIO           RC oscillator w/ OSC2 configured as RA6
;
;   Oscillator System Clock Switch Enable bit:
;     OSCS = ON            Oscillator system clock switch option is enabled (oscillator switching is enabled)
;     OSCS = OFF           Oscillator system clock switch option is disabled (main oscillator is source)
;
;   Power-up Timer Enable bit:
;     PWRT = ON            PWRT enabled
;     PWRT = OFF           PWRT disabled
;
;   Brown-out Reset Enable bit:
;     BOR = OFF            Brown-out Reset disabled
;     BOR = ON             Brown-out Reset enabled
;
;   Brown-out Reset Voltage bits:
;     BORV = 45            VBOR set to 4.5V
;     BORV = 42            VBOR set to 4.2V
;     BORV = 27            VBOR set to 2.7V
;     BORV = 25            VBOR set to 2.5V
;
;   Watchdog Timer Enable bit:
;     WDT = OFF            WDT disabled (control is placed on the SWDTEN bit)
;     WDT = ON             WDT enabled
;
;   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
;
;   Stack Full/Underflow Reset Enable bit:
;     STVR = OFF           Stack Full/Underflow will not cause Reset
;     STVR = ON            Stack Full/Underflow will cause Reset
;
;   Low-Voltage ICSP Enable bit:
;     LVP = OFF            Low-Voltage ICSP disabled
;     LVP = ON             Low-Voltage ICSP enabled
;
;   Background Debugger Enable bit:
;     DEBUG = ON           Background Debugger enabled. RB6 and RB7 are dedicated to In-Circuit Debug.
;     DEBUG = OFF          Background Debugger disabled. RB6 and RB7 configured as general purpose I/O pins.
;
;   Code Protection bit:
;     CP0 = ON             Block 0 (000200-001FFFh) code protected
;     CP0 = OFF            Block 0 (000200-001FFFh) not code protected
;
;   Code Protection bit:
;     CP1 = ON             Block 1 (002000-003FFFh) code protected
;     CP1 = OFF            Block 1 (002000-003FFFh) not code protected
;
;   Code Protection bit:
;     CP2 = ON             Block 2 (004000-005FFFh) code protected
;     CP2 = OFF            Block 2 (004000-005FFFh) not code protected
;
;   Code Protection bit:
;     CP3 = ON             Block 3 (006000-007FFFh) code protected
;     CP3 = OFF            Block 3 (006000-007FFFh) not code protected
;
;   Boot Block Code Protection bit:
;     CPB = ON             Boot Block (000000-0001FFh) code protected
;     CPB = OFF            Boot Block (000000-0001FFh) not code protected
;
;   Data EEPROM Code Protection bit:
;     CPD = ON             Data EEPROM code protected
;     CPD = OFF            Data EEPROM not code protected
;
;   Write Protection bit:
;     WRT0 = ON            Block 0 (000200-001FFFh) write protected
;     WRT0 = OFF           Block 0 (000200-001FFFh) not write protected
;
;   Write Protection bit:
;     WRT1 = ON            Block 1 (002000-003FFFh) write protected
;     WRT1 = OFF           Block 1 (002000-003FFFh) not write protected
;
;   Write Protection bit:
;     WRT2 = ON            Block 2 (004000-005FFFh) write protected
;     WRT2 = OFF           Block 2 (004000-005FFFh) not write protected
;
;   Write Protection bit:
;     WRT3 = ON            Block 3 (006000-007FFFh) write protected
;     WRT3 = OFF           Block 3 (006000-007FFFh) not write protected
;
;   Configuration Register Write Protection bit:
;     WRTC = ON            Configuration registers (300000-3000FFh) write protected
;     WRTC = OFF           Configuration registers (300000-3000FFh) not write protected
;
;   Boot Block Write Protection bit:
;     WRTB = ON            Boot Block (000000-0001FFh) write protected
;     WRTB = OFF           Boot Block (000000-0001FFh) not write protected
;
;   Data EEPROM Write Protection bit:
;     WRTD = ON            Data EEPROM write protected
;     WRTD = OFF           Data EEPROM not write protected
;
;   Table Read Protection bit:
;     EBTR0 = ON           Block 0 (000200-001FFFh) protected from Table Reads executed in other blocks
;     EBTR0 = OFF          Block 0 (000200-001FFFh) not protected from Table Reads executed in other blocks
;
;   Table Read Protection bit:
;     EBTR1 = ON           Block 1 (002000-003FFFh) protected from Table Reads executed in other blocks
;     EBTR1 = OFF          Block 1 (002000-003FFFh) not protected from Table Reads executed in other blocks
;
;   Table Read Protection bit:
;     EBTR2 = ON           Block 2 (004000-005FFFh) protected from Table Reads executed in other blocks
;     EBTR2 = OFF          Block 2 (004000-005FFFh) not protected from Table Reads executed in other blocks
;
;   Table Read Protection bit:
;     EBTR3 = ON           Block 3 (006000-007FFFh) protected from Table Reads executed in other blocks
;     EBTR3 = OFF          Block 3 (006000-007FFFh) not protected from Table Reads executed in other blocks
;
;   Boot Block Table Read Protection bit:
;     EBTRB = ON           Boot Block (000000-0001FFh) protected from Table Reads executed in other blocks
;     EBTRB = OFF          Boot Block (000000-0001FFh) not protected from Table Reads executed in other blocks
;
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
 

t06afre

Joined May 11, 2009
5,934
Which version of the Hi-Tech C compiler do you use? It could be that you should use this notation insted
Rich (BB code):
 #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
Rich (BB code):
//#pragma config Settings
//Register: CONFIG1H @ 0x300001
//OSCS = Oscillator System Clock Switch Enable bit 
//OFF Oscillator system clock switch option is disabled (main oscillator is source) 
//ON Oscillator system clock switch option is enabled (oscillator switching is enabled) 
//OSC = Oscillator Selection bits 
//RC RC oscillator 
//RCIO RC oscillator w/ OSC2 configured as RA6 
#pragma config XT// XT oscillator 
//LP LP oscillator 
//HSPLL HS oscillator with PLL enabled/Clock frequency = (4 x FOSC) 
//ECIO EC oscillator w/ OSC2 configured as RA6 
EC EC oscillator w/ OSC2 configured as divide-by-4 clock output 
//HS HS oscillator 
//Register: CONFIG2L @ 0x300002
//BOR = Brown-out Reset Enable bit 
#pragma config OFF //Brown-out Reset disabled 
//ON Brown-out Reset enabled
 

JohnInTX

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

i wish that i write that in a single LINE
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:

ErnieM

Joined Apr 24, 2011
8,377
These work to configure the first register:
Rich (BB code):
#pragma config OSC = RCIO
#pragma config OSCS = ON
 

ErnieM

Joined Apr 24, 2011
8,377
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?
 

Thread Starter

ect_09

Joined May 6, 2012
180
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....
 

t06afre

Joined May 11, 2009
5,934
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....
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.
 

ErnieM

Joined Apr 24, 2011
8,377
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
 

Thread Starter

ect_09

Joined May 6, 2012
180
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
 

t06afre

Joined May 11, 2009
5,934
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
Which version you use will show up every time you compile:rolleyes:
 

t06afre

Joined May 11, 2009
5,934
its HI Tech compiler 9.80..
sorry for late reply....bad internet here..
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
 

ErnieM

Joined Apr 24, 2011
8,377
its HI Tech compiler 9.80..
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.
 
Top