Newbie with this compiler, need to config PIC18F67K40

Started by Ecoli-557, Dec 13, 2024, 08:52 PM

Previous topic - Next topic

Ecoli-557

Hello All-
I am moving from PBP3 to this compiler and I want to configure my 67K40 for internal oscillator and at 64MHz.
I have used:
#Config
CONFIG FEXTOSC = OFF       ;External Oscillator not enabled
CONFIG RSTOSC = HFINTOSC_64MHZ       ;HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1
#Enconfig
which works under PBP3
I have tried this:
Config_Start
    Config FEXTOSC = OFF       ;External Oscillator not enabled
    Config RSTOSC = HFINTOSC_64MHZ       ;HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1
Config_End
However, the compiler barks at this and gives an error:
CONFIG Directive Error: (setting 'CONFIGFEXTOSC

Advice is needed

Just found the fuse configurator - will try that

Works Like a CHAMP!  Stanks!!

John Lawton

Quote from: Ecoli-557 on Dec 13, 2024, 08:52 PMJust found the fuse configurator - will try that

Good. It's a fantastic plugin, saves a lot of hair-tearing in my experience.

John

top204

The fuse configurator is an excellent plugin, created by Johnb.

A standard program listing layout is shown below for a PIC18F67K40 device operating at 64MHz with its internal oscillator, and the OSC pins set as standard I/O pins. The same fuses can be used with all the 18FxxK40 devices:

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' A standard program setup for a PIC18F67K40 device operating at 64MHz with its internal oscillator.
' Written for the Positron8 compiler by Les Johnson.
'
    Device = 18F67K40                                       ' Tell the compiler what device to compile for
    Declare Xtal = 64                                       ' Tell the compiler what frequency the device will be operating at (in MHz)
    Declare Auto_Heap_Strings = On                          ' Set so all String variables will be created after standard variables in RAM
    Declare Auto_Variable_Bank_Cross = On                   ' Set so that all multi-byte variable types will be within the same RAM bank
'
' Setup USART1
'
    Declare Hserial_Baud = 9600
    Declare HRSOut1_Pin  = PORTC.6
    Declare HRSIn1_Pin   = PORTC.7
'
' Create any global variables and constants here
'

'------------------------------------------------------------------------------
' The Main program starts here
'
Main:
    Setup()                                                 ' Setup the program and any peripherals
'
' The main code loop can start here
'
    Do
    '
    ' Code within, if required...
    '
    Loop

'------------------------------------------------------------------------------
' Setup the program and any peripherals
' Input     : None
' Output    : None
' Notes     : None
'
Proc Setup()
'
' Code within this procedure to setup variables and peripherals
'
EndProc

'------------------------------------------------------------------------------
' Setup the config fuses to use the internal oscillator at 64MHz on PIC18FxxK40 devices.
' With pins RA6 and RA7 as general purpose I/O.
'
Config_Start
    RSTOSC = HFINTOSC_64MHZ         ' HFINTOSC with HFFRQ = 64MHz and CDIV = 1:1
    FEXTOSC = Off                   ' External Oscillator not enabled
    WDTE = Off                      ' Watchdog Timer disabled
    CLKOUTEN = Off                  ' CLKOUT function is disabled
    CSWEN = On                      ' Writing to NOSC and NDIV is allowed
    FCMEN = Off                     ' Fail-Safe Clock Monitor disabled
    MCLRE = EXTMCLR                 ' If LVP = 0, MCLR pin is MCLR. If LVP = 1. RE3 pin function is MCLR
    PWRTE = On                      ' Power up timer enabled
    LPBOREN = Off                   ' ULPBOR disabled
    BOREN = Off                     ' Brown-out disabled
    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 (After 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                       ' Low Voltage programming disabled
    WDTCPS = WDTCPS_2               ' Watchdog Divider Ratio 1:128 (4 milliseconds)
    WDTCWS = WDTCWS_7               ' Window always open (100%). Software control. Keyed access not required
    WDTCCS = LFINTOSC               ' WDT reference clock is the 31.2kHz HFINTOSC output
    WRT0 = Off                      ' Block 0 (000800-001FFF) not write-protected
    WRT1 = Off                      ' Block 1 (002000-003FFF) not write-protected
    WRTC = Off                      ' Configuration registers (300000-30000B) not write-protected
    WRTB = Off                      ' Boot Block (000000-0007FF) write-protected
    WRTD = Off                      ' Data EEPROM not write-protected
    CP = Off                        ' User NVM code protection disabled
    CPD = Off                       ' Data NVM code protection disabled
    EBTR0 = Off                     ' Block 0 (000800-001FFF) not protected from table reads executed in other blocks
    EBTR1 = Off                     ' Block 1 (002000-003FFF) not protected from table reads executed in other blocks
    EBTRB = Off                     ' Boot Block (000000-0007FF) not protected from table reads executed in other blocks
Config_End

A device's ".ppi" file contains all the valid fuses for the device, so it is also a good idea to look into that file. The compilers ".ppi" files can be found on the drive here: "C:\Program Files (x86)\ProtonIDE\PDS\Includes\PPI\", and the config fuses are located at the end of the file.

So for a PIC18F67K40 device. The default config fuses in the ppi file are:

Default Configuration Definitions
[DEFCONFIGSTART]
ifndef _CONFIG_REQ
ifdef WATCHDOG_REQ
    CONFIG WDTE = ON           ; WDT enabled regardless of sleep
else
    CONFIG WDTE = OFF          ; WDT Disabled
endif
ifdef PLL@REQ
    CONFIG RSTOSC = EXTOSC_4PLL ; EXTOSC with 4x PLL, with EXTOSC operating per FEXTOSC Bits
else
    CONFIG RSTOSC = EXTOSC     ; EXTOSC operating per FEXTOSC Bits (device manufacturing default)
endif
CONFIG FEXTOSC = HS        ; HS (crystal oscillator) above 8 MHz; PFM set to high power
CONFIG CLKOUTEN = OFF      ; CLKOUT function is disabled
CONFIG CSWEN = ON          ; Writing to NOSC and NDIV is allowed
CONFIG FCMEN = OFF         ; Fail-Safe Clock Monitor disabled
CONFIG MCLRE = EXTMCLR     ; If LVP = 0, MCLR pin is MCLR; If LVP = 1, RE3 pin function is MCLR
CONFIG PWRTE = ON          ; Power up timer enabled
CONFIG LPBOREN = ON        ; ULPBOR enabled
CONFIG BOREN = SBORDIS     ; Brown-out Reset enabled , SBOREN bit is ignored
CONFIG BORV = VBOR_245     ; Brown-out Reset Voltage (VBOR) set to 2.45V
CONFIG ZCD = OFF           ; ZCD disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON
CONFIG PPS1WAY = OFF       ; PPSLOCK bit can be set and cleared repeatedly (subject to the unlock sequence)
CONFIG STVREN = OFF        ; Stack full/underflow will not cause Reset
CONFIG DEBUG = OFF         ; Background debugger disabled
CONFIG XINST = OFF         ; Extended Instruction Set and Indexed Addressing Mode disabled
CONFIG WDTCPS = WDTCPS_2   ; WDT Period Select Bits: Divider ratio 1:128
CONFIG WDTCWS = WDTCWS_7   ; window always open (100%); software control; keyed access not required
CONFIG WDTCCS = LFINTOSC   ; WDT reference clock is the 31.0 kHz LFINTOSC
CONFIG WRT0 = OFF          ; Block 0 (000800-001FFFh) not write-protected
CONFIG WRT1 = OFF          ; Block 1 (002000-003FFFh) not write-protected
CONFIG WRTC = OFF          ; Configuration registers (300000-30000Bh) not write-protected
CONFIG WRTB = OFF          ; Boot Block (000000-0007FFh) not write-protected
CONFIG WRTD = OFF          ; Data EEPROM not write-protected
CONFIG SCANE = OFF         ; Scanner module is NOT available for use, SCANMD bit is ignored
CONFIG LVP = OFF           ; HV on MCLR/VPP must be used for programming
CONFIG CP = OFF            ; UserNVM code protection disabled
CONFIG CPD = OFF           ; DataNVM code protection disabled
CONFIG EBTR0 = OFF         ; Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
CONFIG EBTR1 = OFF         ; Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
CONFIG EBTRB = OFF         ; Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
endif
[DEFCONFIGEND]