For the fuses, take a lookin teh device's PPI file. They are at the end of it, and all the available fuese are also listed.
The fuse setting can depend on how the device is being used, for example, the fuses below set for the internal oscillator:
Code:
Config_Start
'
' Setup the fuses to use the internal oscillator on a PIC18F26K40 or PIC18F27K40.
'
RSTOSC = HFINTOSC_1MHZ ' With HFFRQ = 4MHz and CDIV = 4:1
FEXTOSC = Off ' External Oscillator not enabled
MCLRE = EXTMCLR ' If LVP = 0, MCLR pin is MCLR. If LVP = 1, RE3 pin function is MCLR
WDTE = Off ' WDT disabled
CLKOUTEN = Off ' CLKOUT function is disabled
CSWEN = On ' Writing to NOSC and NDIV is allowed
FCMEN = Off ' Fail-Safe Clock Monitor disabled
PWRTE = On ' Power up timer enabled
LPBOREN = Off ' LPBOREN disabled
BOREN = Off ' Brown-out turned off
BORV = VBOR_245 ' Brown-out Reset Voltage (VBOR) set to 2.45V
ZCD = Off ' ZCD disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON
PPS1WAY = Off ' PPSLOCK bit can be set and cleared repeatedly (subject to the unlock sequence)
STVREN = Off ' Stack full/underflow will not cause Reset
Debug = Off ' Background debugger disabled
XINST = Off ' Extended Instruction Set and Indexed Addressing Mode disabled
SCANE = Off ' Scanner module is Not available for use. SCANMD bit is ignored
LVP = Off ' HV On MCLR/VPP must be used for programming
WDTCPS = WDTCPS_15 ' Watchdog Divider ratio 1:1048576 (32 seconds)
WDTCWS = WDTCWS_7 ' Window always open (100%). Software control. Keyed access not required
WDTCCS = LFINTOSC ' WDT input clock selector->WDT reference clock is the 31.2kHz HFINTOSC output
WRT0 = Off ' Block 0 (000800-001FFFh) not write-protected
WRT1 = Off ' Block 1 (002000-003FFFh) not write-protected
WRTC = On ' Configuration registers (300000-30000Bh) write-protected
WRTB = Off ' Boot Block (000000-0007FFh) not write-protected
WRTD = Off ' Data EEPROM not write-protected
Cp = Off ' UserNVM code protection disabled
CPD = Off ' DataNVM code protection disabled
EBTR0 = Off ' Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
EBTR1 = Off ' Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
EBTRB = Off ' Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
Config_End
With the internal oscillator, several SFRs need to be manipuated to set the oscillator's frequency, and these are easily placed into procedures to make them extremely easy to use, and very easy to read in a program, and remember, unless a procedure is called in a program it will not be included in the program, so only the procedures that are called from the list below will be added to the final BASIC program, so they will not fill up the code memory space:
Code:
'--------------------------------------------------------------------
' Set the microcontroller to internal 4MHz operation with a HFINTOSC_1MHZ fuse
' Input : None
' Output : None
' Notes : Waits for the oscillator to become stable
'
Proc Oscillator_4MHz()
OSCCON1 = $60
OSCCON3 = 0
OSCEN = 0
OSCFRQ = 2
OSCTUNE = 0
Repeat: Until OSCSTATbits_HFOR = 1
EndProc
'--------------------------------------------------------------------
' Set the microcontroller to internal 8MHz operation with an HFINTOSC_1MHZ fuse
' Input : None
' Output : None
' Notes : Waits for the oscillator to become stable
'
Proc Oscillator_8MHz()
OSCCON1 = $60
OSCCON3 = 0
OSCEN = 0
OSCFRQ = 3
OSCTUNE = 0
Repeat: Until OSCSTATbits_HFOR = 1
EndProc
'--------------------------------------------------------------------
' Set the microcontroller to internal 16MHz operation with an HFINTOSC_1MHZ fuse
' Input : None
' Output : None
' Notes : Waits for the oscillator to become stable
'
Proc Oscillator_16MHz()
OSCCON1 = $60
OSCCON3 = 0
OSCEN = 0
OSCFRQ = 5
OSCTUNE = 0
Repeat: Until OSCSTATbits_HFOR = 1
EndProc
'--------------------------------------------------------------------
' Set the microcontroller to internal 32MHz operation with an HFINTOSC_1MHZ fuse
' Input : None
' Output : None
' Notes : Waits for the oscillator to become stable
'
Proc Oscillator_32MHz()
OSCCON1 = $60
OSCCON3 = 0
OSCEN = 0
OSCFRQ = 6
OSCTUNE = 0
Repeat: Until OSCSTATbits_HFOR = 1
EndProc
'--------------------------------------------------------------------
' Set the microcontroller to internal 64MHz operation with an HFINTOSC_1MHZ fuse
' Input : None
' Output : None
' Notes : Waits for the oscillator to become stable
'
Proc Oscillator_64MHz()
OSCCON1 = $60
OSCCON3 = 0
OSCEN = 0
OSCFRQ = 8
OSCTUNE = 0
Repeat: Until OSCSTATbits_HFOR = 1
EndProc
The fuses below setup for an external oscillator, which does not need any FSR manipulation:
Code:
Config_Start
'
' Setup the fuses to use the external oscillator on a PIC18F26K40 or PIC18F27K40.
'
RSTOSC = EXTOSC ' EXTOSC operating per FEXTOSC Bits
FEXTOSC = HS ' HS (crystal oscillator) above 8 MHz. PFM set to high power
MCLRE = EXTMCLR ' If LVP = 0, MCLR pin is MCLR. If LVP = 1, RE3 pin function is MCLR
WDTE = Off ' WDT disabled
CLKOUTEN = Off ' CLKOUT function is disabled
CSWEN = On ' Writing to NOSC and NDIV is allowed
FCMEN = Off ' Fail-Safe Clock Monitor disabled
PWRTE = On ' Power up timer enabled
LPBOREN = Off ' LPBOREN disabled
BOREN = Off ' Brown-out turned off
BORV = VBOR_245 ' Brown-out Reset Voltage (VBOR) set to 2.45V
ZCD = Off ' ZCD disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON
PPS1WAY = Off ' PPSLOCK bit can be set and cleared repeatedly (subject to the unlock sequence)
STVREN = Off ' Stack full/underflow will not cause Reset
Debug = Off ' Background debugger disabled
XINST = Off ' Extended Instruction Set and Indexed Addressing Mode disabled
SCANE = Off ' Scanner module is Not available for use. SCANMD bit is ignored
LVP = Off ' HV On MCLR/VPP must be used for programming
WDTCPS = WDTCPS_15 ' Watchdog Divider ratio 1:1048576 (32 seconds)
WDTCWS = WDTCWS_7 ' Window always open (100%). Software control. Keyed access not required
WDTCCS = LFINTOSC ' WDT input clock selector->WDT reference clock is the 31.2kHz HFINTOSC output
WRT0 = Off ' Block 0 (000800-001FFFh) not write-protected
WRT1 = Off ' Block 1 (002000-003FFFh) not write-protected
WRTC = On ' Configuration registers (300000-30000Bh) write-protected
WRTB = Off ' Boot Block (000000-0007FFh) not write-protected
WRTD = Off ' Data EEPROM not write-protected
Cp = Off ' UserNVM code protection disabled
CPD = Off ' DataNVM code protection disabled
EBTR0 = Off ' Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
EBTR1 = Off ' Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
EBTRB = Off ' Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
Config_End