Author Topic: PIC24fv32ka302 & XC16 Compiler - How to set config bits  (Read 11166 times)

0 Members and 1 Guest are viewing this topic.

Offline kolbepTopic starter

  • Frequent Contributor
  • **
  • Posts: 600
  • Country: za
    • ShoutingElectronics.com
PIC24fv32ka302 & XC16 Compiler - How to set config bits
« on: June 05, 2014, 08:13:21 pm »
Good Day.
Based on a discussion in one of my other threads, I have decided to upgrade from an 8 bit PIC18lf2420.

I have ordered some samples of the PIC24FV32KA302 microcontroller.
So I decided while I wait for the pics, that I would try coding on the IDE, just to get a hang of the new chip.

I have set up a new project, and have linked in the header file. But now  |O  I am trying to set config bits the way I used to on C18 with the PIC18lf2420 Processor, but it doesn't like that. I cannot figure out how to format the config bits section

Perhaps somebody could help me out, with setting the basic config bits (just till I get the hang of it). Basically I need the WDT Disabled, Internal Oscillator and any thing else, just so that I can flash an LED.

Please could you help me, either with the Config Bit setting portion, or if you are generous, and have time on your hands, a small program to blink the LED on a pin.

Here is what I have so far
(it gives me 'unable to resolve identifier' when it gets to the _config1 section)
Code: [Select]
/*
 * File:   newmain.c
 * Author: Peter
 *
 * Created on 05 June 2014, 21:49
 */

#include <stdio.h>
#include <stdlib.h>
#include <p24FV32KA302.h>


_CONFIG1(FWDTEN_OFF) [];


/*
 *
 */
int main(int argc, char** argv) {

    return (EXIT_SUCCESS);
}

Thanks
P
====================================
www.ShoutingElectronics.com Don't just talk about Electronics, SHOUT ABOUT IT! Electronics Blog Site and Youtube Channel
 

Offline jlmoon

  • Supporter
  • ****
  • Posts: 609
  • Country: us
  • If you fail the first time, keep trying!
Re: PIC24fv32ka302 & XC16 Compiler - How to set config bits
« Reply #1 on: June 05, 2014, 08:47:20 pm »
/* How about something like this? */
/* This is a configuration for a 24FJ128GA010 part.. but should be the same */


#include <stdio.h>
#include <stdlib.h>
#include <p24Fxxxx.h>

_CONFIG1( JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2)
_CONFIG2( FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_XT & FNOSC_PRI)


void delay(void)
{
    long i = 65535;
    while(i--)
        ;
}

int main(int argc, char** argv)
{
    int counter;
    TRISA = 0;
   
    // Setup PortA IOs as digital
    AD1PCFG = 0xffff;

    while(1)
   {
        LATA = 0x00;
        delay();

        LATA = 0xFF;
        delay();
    }
    return (EXIT_SUCCESS);
}
Recharged Volt-Nut
 

Online mariush

  • Super Contributor
  • ***
  • Posts: 5141
  • Country: ro
  • .
Re: PIC24fv32ka302 & XC16 Compiler - How to set config bits
« Reply #2 on: June 05, 2014, 08:51:10 pm »
If you're using MPLAB X and XC16, you should just use #include <xc.h> at the top.  As you selected the microcontroller in the Project Properties window (or the wizard when creating the project), just saying xc.h will be enough.

From there, go in menu Window > PIC Memory Views > Configuration bits ... set the options from combo boxes, click on generate source code to output.  There you have all the parameters. Copy and paste after the #include <xc.h> line.

The difference is you just have to enter each one separately, #pragma config parameter = value but the tool generates the code for you.

ps. If you can't select XC16 in mplab x, go to Tools > Options >  Embedded and click on Add button, then go to the BIN folder of you XC16 install. If you select the right folder, under the path mplab x should show XC16. Then, you can go in project properties and select the XC16 compiler or create new project and select the XC16 compiler there.
 

Offline 22swg

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: gb
Re: PIC24fv32ka302 & XC16 Compiler - How to set config bits
« Reply #3 on: June 05, 2014, 08:58:39 pm »
I have been impressed by the PIC24FV32KAxxx family ,  don't remember where this code came from might have been the MC microstick5v web site.

I skipped the PIC18's and  jumped into the deep 'C' end  of the pool .


// Configuration Bits to make the part run from the Internal FRCDIV Oscillator.

_FBS
(
    BWRP_OFF &      // Boot Segment Write Protect (Disabled)
    BSS_OFF         // Boot segment Protect (No boot flash segment)
)

_FGS
(
    GWRP_OFF &      // General Segment Flash Write Protect (General segment may be written)
    GSS0_OFF        // General Segment Code Protect (No Protection)
)

_FOSCSEL
(
    FNOSC_FRC &  // Oscillator Select (8MHz FRC )
    SOSCSRC_ANA &   // SOSC Source Type (Analog Mode for use with crystal)
    LPRCSEL_HP &    // LPRC Power and Accuracy (High Power/High Accuracy)
    IESO_ON         // Internal External Switch Over bit (Internal External Switchover mode enabled (Two-speed Start-up enabled))
)

_FOSC
(
    POSCMOD_NONE &   // Primary Oscillator Mode (Primary oscillator disabled)
    OSCIOFNC_OFF &   // CLKO Enable Configuration bit (CLKO output signal enabled)
    POSCFREQ_MS &   // Primary Oscillator Frequency Range Configuration bits (Primary oscillator/external clock frequency between 100kHz to 8MHz)
    SOSCSEL_SOSCHP &// SOSC Power Selection Configuration bits (Secondary Oscillator configured for high-power operation)
    FCKSM_CSECME    // Clock Switching and Monitor Selection (Clock Switching and Fail-safe Clock Monitor Enabled)
)

_FWDT
(
    WDTPS_PS32768 & // Watchdog Timer Postscale Select bits (1:32768)
    FWPSA_PR128 &   // WDT Prescaler bit (WDT prescaler ratio of 1:128)
    FWDTEN_OFF &    // Watchdog Timer Enable bits (WDT disabled in hardware; SWDTEN bit disabled)
    WINDIS_OFF      // Windowed Watchdog Timer Disable bit (Standard WDT selected (windowed WDT disabled))
)

// Warning:
// Always enable MCLRE_ON config bit setting so that the MCLR pin function will
// work for low-voltage In-Circuit Serial Programming (ICSP). The Microstick
// programming circuitry only supports low-voltage ICSP. If you disable MCLR pin
// functionality, a high-voltage ICSP tool will be required to re-program the
// part in the future.
_FPOR
(
    BOREN_BOR3 &    // Brown-out Reset Enable bits (Enabled in hardware; SBOREN bit disabled)
    PWRTEN_ON &     // Power-up Timer Enable (PWRT enabled)
    I2C1SEL_PRI &   // Alternate I2C1 Pin Mapping bit (Default SCL1/SDA1 Pins for I2C1)
    BORV_V30 &      // Brown-out Reset Voltage bits (Brown-out Reset at 1.8V)
    MCLRE_ON        // MCLR Pin Enable bit (RA5 input disabled; MCLR enabled)
)

_FICD
(
    ICS_PGx3        // ICD Pin Placement Select (EMUC/EMUD share PGC3/PGD3)
Check your tongue, your belly and your lust. Better to enjoy someone else’s madness.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: PIC24fv32ka302 & XC16 Compiler - How to set config bits
« Reply #4 on: June 05, 2014, 09:12:35 pm »
Use #pragma config directive, as stated in the  manual.
================================
https://dannyelectronics.wordpress.com/
 

Offline Rufus

  • Super Contributor
  • ***
  • Posts: 2095
Re: PIC24fv32ka302 & XC16 Compiler - How to set config bits
« Reply #5 on: June 05, 2014, 10:48:13 pm »
We have https://www.eevblog.com/forum/microcontrollers/ where you should have posted this.

_CONFIG and other macros are depreciated.

Include the following (PIC24FV32KA302 specific) file in the project and uncomment lines with the options you want
Code: [Select]
//  Microchip Configuration pragmas

//  Boot Segment Write Protect
//  #pragma config BWRP=ON              // Enabled
//  #pragma config BWRP=OFF             // Disabled

//  Boot segment Protect
//  #pragma config BSS=HI5K             // High Security Boot Protect 000200h - 002BFEh
//  #pragma config BSS=HI2K             // High Security Boot Protect 000200h - 0015FEh
//  #pragma config BSS=HI1K             // High Security Boot Protect 000200h - 000AFEh
//  #pragma config BSS=STD5K            // Standard Security Boot Protect 000200h - 002BFEh
//  #pragma config BSS=STD2K            // Standard Security Boot Protect 000200h - 0015FEh
//  #pragma config BSS=STD1K            // Standard Security Boot Protect 000200h - 000AFEh
//  #pragma config BSS=OFF              // No boot program flash segment

//  General Segment Write Protect
//  #pragma config GWRP=ON              // General segment is write-protected
//  #pragma config GWRP=OFF             // General segment may be written

//  General Segment Code Protect
//  #pragma config GSS0=ON              // Standard security enabled
//  #pragma config GSS0=OFF             // No Protection

//  Oscillator Select
//  #pragma config FNOSC=FRC            // Fast RC Oscillator (FRC)
//  #pragma config FNOSC=FRCPLL         // Fast RC Oscillator with Postscaler and PLL Module (FRCDIV+PLL)
//  #pragma config FNOSC=PRI            // Primary Oscillator (XT, HS, EC)
//  #pragma config FNOSC=PRIPLL         // Primary oscillator with PLL Module (HS+PLL, EC+PLL)
//  #pragma config FNOSC=SOSC           // Secondary oscillator (SOSC)
//  #pragma config FNOSC=LPRC           // Low Power RC oscillator (LPRC)
//  #pragma config FNOSC=LPFRC          // 500kHz Low-Power FRC oscillator with Postscaler(LPFRCDIV)
//  #pragma config FNOSC=FRCDIV         // 8MHz FRC oscillator With Postscaler (FRCDIV)

//  SOSC Source Type
//  #pragma config SOSCSRC=DIG          // Digital Mode for use with external source
//  #pragma config SOSCSRC=ANA          // Analog Mode for use with crystal

//  LPRC Oscillator Power and Accuracy
//  #pragma config LPRCSEL=LP           // Low Power, Low Accuracy Mode
//  #pragma config LPRCSEL=HP           // High Power, High Accuracy Mode

//  Internal External Switch Over bit
//  #pragma config IESO=OFF             // Internal External Switchover mode disabled (Two-speed Start-up disabled)
//  #pragma config IESO=ON              // Internal External Switchover mode enabled (Two-speed Start-up enabled)

//  Primary Oscillator Configuration bits
//  #pragma config POSCMOD=EC           // External clock mode selected
//  #pragma config POSCMOD=XT           // XT oscillator mode selected
//  #pragma config POSCMOD=HS           // HS oscillator mode selected
//  #pragma config POSCMOD=NONE         // Primary oscillator disabled

//  CLKO Enable Configuration bit
//  #pragma config OSCIOFNC=OFF         // CLKO output disabled
//  #pragma config OSCIOFNC=ON          // CLKO output signal is active on the OSCO pin

//  Primary Oscillator Frequency Range Configuration bits
//  #pragma config POSCFREQ=LS          // Primary oscillator/external clock input frequency less than 100kHz
//  #pragma config POSCFREQ=MS          // Primary oscillator/external clock input frequency between 100kHz and 8MHz
//  #pragma config POSCFREQ=HS          // Primary oscillator/external clock input frequency greater than 8MHz

//  SOSC Power Selection Configuration bits
//  #pragma config SOSCSEL=SOSCLP       // Secondary Oscillator configured for low-power operation
//  #pragma config SOSCSEL=SOSCHP       // Secondary Oscillator configured for high-power operation

//  Clock Switching and Monitor Selection
//  #pragma config FCKSM=CSECME         // Both Clock Switching and Fail-safe Clock Monitor are enabled
//  #pragma config FCKSM=CSECMD         // Clock Switching is enabled, Fail-safe Clock Monitor is disabled
//  #pragma config FCKSM=CSDCMD         // Both Clock Switching and Fail-safe Clock Monitor are disabled

//  Watchdog Timer Postscale Select bits
//  #pragma config WDTPS=PS1            // 1:1
//  #pragma config WDTPS=PS2            // 1:2
//  #pragma config WDTPS=PS4            // 1:4
//  #pragma config WDTPS=PS8            // 1:8
//  #pragma config WDTPS=PS16           // 1:16
//  #pragma config WDTPS=PS32           // 1:32
//  #pragma config WDTPS=PS64           // 1:64
//  #pragma config WDTPS=PS128          // 1:128
//  #pragma config WDTPS=PS256          // 1:256
//  #pragma config WDTPS=PS512          // 1:512
//  #pragma config WDTPS=PS1024         // 1:1024
//  #pragma config WDTPS=PS2048         // 1:2048
//  #pragma config WDTPS=PS4096         // 1:4096
//  #pragma config WDTPS=PS8192         // 1:8192
//  #pragma config WDTPS=PS16384        // 1:16384
//  #pragma config WDTPS=PS32768        // 1:32768

//  WDT Prescaler bit
//  #pragma config FWPSA=PR32           // WDT prescaler ratio of 1:32
//  #pragma config FWPSA=PR128          // WDT prescaler ratio of 1:128

//  Watchdog Timer Enable bits
//  #pragma config FWDTEN=OFF           // WDT disabled in hardware; SWDTEN bit disabled
//  #pragma config FWDTEN=NOSLP         // WDT enabled while device is active and disabled in Sleep; SWDTEN bit disabled
//  #pragma config FWDTEN=SWON          // WDT controlled with the SWDTEN bit setting
//  #pragma config FWDTEN=ON            // WDT enabled in hardware

//  Windowed Watchdog Timer Disable bit
//  #pragma config WINDIS=ON            // Windowed WDT enabled
//  #pragma config WINDIS=OFF           // Standard WDT selected(windowed WDT disabled)

//  Brown-out Reset Enable bits
//  #pragma config BOREN=BOR0           // Brown-out Reset disabled in hardware, SBOREN bit disabled
//  #pragma config BOREN=BOR1           // Brown-out Rest controlled by SBOREN bit
//  #pragma config BOREN=BOR2           // Brown-out Reset enabled only while device is active and disabled in SLEEP, SBOREN bit disabled
//  #pragma config BOREN=BOR3           // Brown-out Reset enabled in hardware, SBOREN bit disabled

// 
//  #pragma config LVRCFG=ON            // Low Voltage regulator is available and controlled by LVREN bit
//  #pragma config LVRCFG=OFF           // Low Voltage regulator is not available

//  Power-up Timer Enable bit
//  #pragma config PWRTEN=OFF           // PWRT disabled
//  #pragma config PWRTEN=ON            // PWRT enabled

//  Alternate I2C1 Pin Mapping bit
//  #pragma config I2C1SEL=SEC          // Use  Alternate SCL1/ASDA1 Pins For I2C1
//  #pragma config I2C1SEL=PRI          // Use Default SCL1/SDA1 Pins For I2C1

//  Brown-out Reset Voltage bits
//  #pragma config BORV=LPBOR           // Low-power Brown-Out Reset occurs around 2.0V
//  #pragma config BORV=V30             // Brown-out Reset set to Highest Voltage (3.0V)
//  #pragma config BORV=V27             // Brown-out Reset set at 2.7V
//  #pragma config BORV=V20             // Brown-out Reset set to lowest voltage (2.0V)

//  MCLR Pin Enable bit
//  #pragma config MCLRE=OFF            // RA5 input pin enabled,MCLR disabled
//  #pragma config MCLRE=ON             // RA5 input pin disabled,MCLR pin enabled

//  ICD Pin Placement Select bits
//  #pragma config ICS=PGx3             // EMUC/EMUD share PGC3/PGD3
//  #pragma config ICS=PGx2             // EMUC/EMUD share PGC2/PGD2
//  #pragma config ICS=PGx1             // EMUC/EMUD share PGC1/PGD1

//  Deep Sleep Watchdog Timer Postscale Select bits
//  #pragma config DSWDTPS=DSWDTPS0     // 1:2 (2.1 ms)
//  #pragma config DSWDTPS=DSWDTPS1     // 1:8 (8.3 ms)
//  #pragma config DSWDTPS=DSWDTPS2     // 1:32 (33 ms)
//  #pragma config DSWDTPS=DSWDTPS3     // 1:128 (132 ms)
//  #pragma config DSWDTPS=DSWDTPS4     // 1:512 (528 ms)
//  #pragma config DSWDTPS=DSWDTPS5     // 1:2048 (2.1 Seconds)
//  #pragma config DSWDTPS=DSWDTPS6     // 1:8192 (8.5 Seconds)
//  #pragma config DSWDTPS=DSWDTPS7     // 1:32,768 (34 Seconds)
//  #pragma config DSWDTPS=DSWDTPS8     // 1:131,072 (135 Seconds)
//  #pragma config DSWDTPS=DSWDTPS9     // 1:524,288 (9 Minutes)
//  #pragma config DSWDTPS=DSWDTPSA     // 1:2,097,152 (36 Minutes)
//  #pragma config DSWDTPS=DSWDTPSB     // 1:8,388,608 (2.4 Hours)
//  #pragma config DSWDTPS=DSWDTPSC     // 1:33,554,432 (9.6 Hours)
//  #pragma config DSWDTPS=DSWDTPSD     // 1:134,217,728 (38.5 Hours)
//  #pragma config DSWDTPS=DSWDTPSE     // 1:536,870,912 (6.4 Days)
//  #pragma config DSWDTPS=DSWDTPSF     // 1:2,147,483,648 (25.7 Days)

//  DSWDT Reference Clock Select bit
//  #pragma config DSWDTOSC=SOSC        // DSWDT uses Secondary Oscillator (SOSC)
//  #pragma config DSWDTOSC=LPRC        // DSWDT uses Low Power RC Oscillator (LPRC)

//  Deep Sleep Zero-Power BOR Enable bit
//  #pragma config DSBOREN=OFF          // Deep Sleep BOR disabled in Deep Sleep
//  #pragma config DSBOREN=ON           // Deep Sleep BOR enabled in Deep Sleep

//  Deep Sleep Watchdog Timer Enable bit
//  #pragma config DSWDTEN=OFF          // DSWDT disabled
//  #pragma config DSWDTEN=ON           // DSWDT enabled

Oh and make sure it doesn't see any #defines for ON or OFF etc which will screw up the pragmas
 

Offline kolbepTopic starter

  • Frequent Contributor
  • **
  • Posts: 600
  • Country: za
    • ShoutingElectronics.com
Re: PIC24fv32ka302 & XC16 Compiler - How to set config bits
« Reply #6 on: June 06, 2014, 05:59:58 am »
Wow, Thanks for all the replies. That is awesome.
When I knock off from work (in about 8 hours time or so), I will start playing...

I apologise for putting this in the wrong topic group, Admin, please can you move it to the Microcontrollers Section.

Thanks
P
====================================
www.ShoutingElectronics.com Don't just talk about Electronics, SHOUT ABOUT IT! Electronics Blog Site and Youtube Channel
 

Offline 22swg

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: gb
Re: PIC24fv32ka302 & XC16 Compiler - How to set config bits
« Reply #7 on: June 06, 2014, 07:02:25 am »
I started with the 28 pin KM series but now find the KA easier , my C is that of a 4 year old ! I found 28 pin constraining on IO so moved to 44 QTFP , and PICkit3 + MPLABX  all works very well .
Check your tongue, your belly and your lust. Better to enjoy someone else’s madness.
 

Offline AlfBaz

  • Super Contributor
  • ***
  • Posts: 2187
  • Country: au
Re: PIC24fv32ka302 & XC16 Compiler - How to set config bits
« Reply #8 on: June 06, 2014, 07:08:32 am »
We have https://www.eevblog.com/forum/microcontrollers/ where you should have posted this.

_CONFIG and other macros are depreciated.

Include the following (PIC24FV32KA302 specific) file in the project and uncomment lines with the options you want
Code: [Select]
//  Microchip Configuration pragmas

//  Boot Segment Write Protect
//  #pragma config BWRP=ON              // Enabled
//  #pragma config BWRP=OFF             // Disabled

//  Boot segment Protect
//  #pragma config BSS=HI5K             // High Security Boot Protect 000200h - 002BFEh
//  #pragma config BSS=HI2K             // High Security Boot Protect 000200h - 0015FEh
//  #pragma config BSS=HI1K             // High Security Boot Protect 000200h - 000AFEh
//  #pragma config BSS=STD5K            // Standard Security Boot Protect 000200h - 002BFEh
//  #pragma config BSS=STD2K            // Standard Security Boot Protect 000200h - 0015FEh
//  #pragma config BSS=STD1K            // Standard Security Boot Protect 000200h - 000AFEh
//  #pragma config BSS=OFF              // No boot program flash segment

//  General Segment Write Protect
//  #pragma config GWRP=ON              // General segment is write-protected
//  #pragma config GWRP=OFF             // General segment may be written

//  General Segment Code Protect
//  #pragma config GSS0=ON              // Standard security enabled
//  #pragma config GSS0=OFF             // No Protection

//  Oscillator Select
//  #pragma config FNOSC=FRC            // Fast RC Oscillator (FRC)
//  #pragma config FNOSC=FRCPLL         // Fast RC Oscillator with Postscaler and PLL Module (FRCDIV+PLL)
//  #pragma config FNOSC=PRI            // Primary Oscillator (XT, HS, EC)
//  #pragma config FNOSC=PRIPLL         // Primary oscillator with PLL Module (HS+PLL, EC+PLL)
//  #pragma config FNOSC=SOSC           // Secondary oscillator (SOSC)
//  #pragma config FNOSC=LPRC           // Low Power RC oscillator (LPRC)
//  #pragma config FNOSC=LPFRC          // 500kHz Low-Power FRC oscillator with Postscaler(LPFRCDIV)
//  #pragma config FNOSC=FRCDIV         // 8MHz FRC oscillator With Postscaler (FRCDIV)

//  SOSC Source Type
//  #pragma config SOSCSRC=DIG          // Digital Mode for use with external source
//  #pragma config SOSCSRC=ANA          // Analog Mode for use with crystal

//  LPRC Oscillator Power and Accuracy
//  #pragma config LPRCSEL=LP           // Low Power, Low Accuracy Mode
//  #pragma config LPRCSEL=HP           // High Power, High Accuracy Mode

//  Internal External Switch Over bit
//  #pragma config IESO=OFF             // Internal External Switchover mode disabled (Two-speed Start-up disabled)
//  #pragma config IESO=ON              // Internal External Switchover mode enabled (Two-speed Start-up enabled)

//  Primary Oscillator Configuration bits
//  #pragma config POSCMOD=EC           // External clock mode selected
//  #pragma config POSCMOD=XT           // XT oscillator mode selected
//  #pragma config POSCMOD=HS           // HS oscillator mode selected
//  #pragma config POSCMOD=NONE         // Primary oscillator disabled

//  CLKO Enable Configuration bit
//  #pragma config OSCIOFNC=OFF         // CLKO output disabled
//  #pragma config OSCIOFNC=ON          // CLKO output signal is active on the OSCO pin

//  Primary Oscillator Frequency Range Configuration bits
//  #pragma config POSCFREQ=LS          // Primary oscillator/external clock input frequency less than 100kHz
//  #pragma config POSCFREQ=MS          // Primary oscillator/external clock input frequency between 100kHz and 8MHz
//  #pragma config POSCFREQ=HS          // Primary oscillator/external clock input frequency greater than 8MHz

//  SOSC Power Selection Configuration bits
//  #pragma config SOSCSEL=SOSCLP       // Secondary Oscillator configured for low-power operation
//  #pragma config SOSCSEL=SOSCHP       // Secondary Oscillator configured for high-power operation

//  Clock Switching and Monitor Selection
//  #pragma config FCKSM=CSECME         // Both Clock Switching and Fail-safe Clock Monitor are enabled
//  #pragma config FCKSM=CSECMD         // Clock Switching is enabled, Fail-safe Clock Monitor is disabled
//  #pragma config FCKSM=CSDCMD         // Both Clock Switching and Fail-safe Clock Monitor are disabled

//  Watchdog Timer Postscale Select bits
//  #pragma config WDTPS=PS1            // 1:1
//  #pragma config WDTPS=PS2            // 1:2
//  #pragma config WDTPS=PS4            // 1:4
//  #pragma config WDTPS=PS8            // 1:8
//  #pragma config WDTPS=PS16           // 1:16
//  #pragma config WDTPS=PS32           // 1:32
//  #pragma config WDTPS=PS64           // 1:64
//  #pragma config WDTPS=PS128          // 1:128
//  #pragma config WDTPS=PS256          // 1:256
//  #pragma config WDTPS=PS512          // 1:512
//  #pragma config WDTPS=PS1024         // 1:1024
//  #pragma config WDTPS=PS2048         // 1:2048
//  #pragma config WDTPS=PS4096         // 1:4096
//  #pragma config WDTPS=PS8192         // 1:8192
//  #pragma config WDTPS=PS16384        // 1:16384
//  #pragma config WDTPS=PS32768        // 1:32768

//  WDT Prescaler bit
//  #pragma config FWPSA=PR32           // WDT prescaler ratio of 1:32
//  #pragma config FWPSA=PR128          // WDT prescaler ratio of 1:128

//  Watchdog Timer Enable bits
//  #pragma config FWDTEN=OFF           // WDT disabled in hardware; SWDTEN bit disabled
//  #pragma config FWDTEN=NOSLP         // WDT enabled while device is active and disabled in Sleep; SWDTEN bit disabled
//  #pragma config FWDTEN=SWON          // WDT controlled with the SWDTEN bit setting
//  #pragma config FWDTEN=ON            // WDT enabled in hardware

//  Windowed Watchdog Timer Disable bit
//  #pragma config WINDIS=ON            // Windowed WDT enabled
//  #pragma config WINDIS=OFF           // Standard WDT selected(windowed WDT disabled)

//  Brown-out Reset Enable bits
//  #pragma config BOREN=BOR0           // Brown-out Reset disabled in hardware, SBOREN bit disabled
//  #pragma config BOREN=BOR1           // Brown-out Rest controlled by SBOREN bit
//  #pragma config BOREN=BOR2           // Brown-out Reset enabled only while device is active and disabled in SLEEP, SBOREN bit disabled
//  #pragma config BOREN=BOR3           // Brown-out Reset enabled in hardware, SBOREN bit disabled

// 
//  #pragma config LVRCFG=ON            // Low Voltage regulator is available and controlled by LVREN bit
//  #pragma config LVRCFG=OFF           // Low Voltage regulator is not available

//  Power-up Timer Enable bit
//  #pragma config PWRTEN=OFF           // PWRT disabled
//  #pragma config PWRTEN=ON            // PWRT enabled

//  Alternate I2C1 Pin Mapping bit
//  #pragma config I2C1SEL=SEC          // Use  Alternate SCL1/ASDA1 Pins For I2C1
//  #pragma config I2C1SEL=PRI          // Use Default SCL1/SDA1 Pins For I2C1

//  Brown-out Reset Voltage bits
//  #pragma config BORV=LPBOR           // Low-power Brown-Out Reset occurs around 2.0V
//  #pragma config BORV=V30             // Brown-out Reset set to Highest Voltage (3.0V)
//  #pragma config BORV=V27             // Brown-out Reset set at 2.7V
//  #pragma config BORV=V20             // Brown-out Reset set to lowest voltage (2.0V)

//  MCLR Pin Enable bit
//  #pragma config MCLRE=OFF            // RA5 input pin enabled,MCLR disabled
//  #pragma config MCLRE=ON             // RA5 input pin disabled,MCLR pin enabled

//  ICD Pin Placement Select bits
//  #pragma config ICS=PGx3             // EMUC/EMUD share PGC3/PGD3
//  #pragma config ICS=PGx2             // EMUC/EMUD share PGC2/PGD2
//  #pragma config ICS=PGx1             // EMUC/EMUD share PGC1/PGD1

//  Deep Sleep Watchdog Timer Postscale Select bits
//  #pragma config DSWDTPS=DSWDTPS0     // 1:2 (2.1 ms)
//  #pragma config DSWDTPS=DSWDTPS1     // 1:8 (8.3 ms)
//  #pragma config DSWDTPS=DSWDTPS2     // 1:32 (33 ms)
//  #pragma config DSWDTPS=DSWDTPS3     // 1:128 (132 ms)
//  #pragma config DSWDTPS=DSWDTPS4     // 1:512 (528 ms)
//  #pragma config DSWDTPS=DSWDTPS5     // 1:2048 (2.1 Seconds)
//  #pragma config DSWDTPS=DSWDTPS6     // 1:8192 (8.5 Seconds)
//  #pragma config DSWDTPS=DSWDTPS7     // 1:32,768 (34 Seconds)
//  #pragma config DSWDTPS=DSWDTPS8     // 1:131,072 (135 Seconds)
//  #pragma config DSWDTPS=DSWDTPS9     // 1:524,288 (9 Minutes)
//  #pragma config DSWDTPS=DSWDTPSA     // 1:2,097,152 (36 Minutes)
//  #pragma config DSWDTPS=DSWDTPSB     // 1:8,388,608 (2.4 Hours)
//  #pragma config DSWDTPS=DSWDTPSC     // 1:33,554,432 (9.6 Hours)
//  #pragma config DSWDTPS=DSWDTPSD     // 1:134,217,728 (38.5 Hours)
//  #pragma config DSWDTPS=DSWDTPSE     // 1:536,870,912 (6.4 Days)
//  #pragma config DSWDTPS=DSWDTPSF     // 1:2,147,483,648 (25.7 Days)

//  DSWDT Reference Clock Select bit
//  #pragma config DSWDTOSC=SOSC        // DSWDT uses Secondary Oscillator (SOSC)
//  #pragma config DSWDTOSC=LPRC        // DSWDT uses Low Power RC Oscillator (LPRC)

//  Deep Sleep Zero-Power BOR Enable bit
//  #pragma config DSBOREN=OFF          // Deep Sleep BOR disabled in Deep Sleep
//  #pragma config DSBOREN=ON           // Deep Sleep BOR enabled in Deep Sleep

//  Deep Sleep Watchdog Timer Enable bit
//  #pragma config DSWDTEN=OFF          // DSWDT disabled
//  #pragma config DSWDTEN=ON           // DSWDT enabled

Oh and make sure it doesn't see any #defines for ON or OFF etc which will screw up the pragmas
LOL... are they including these sorts of "config" files with the compiler distro now?
I got not one encouraging word when I suggested it way back when...
Instead entering into some bizarre parallel universe argument with a numbnut :palm:
http://www.microchip.com/forums/m264733.aspx
 
 

Offline Rufus

  • Super Contributor
  • ***
  • Posts: 2095
Re: PIC24fv32ka302 & XC16 Compiler - How to set config bits
« Reply #9 on: June 06, 2014, 01:41:36 pm »
LOL... are they including these sorts of "config" files with the compiler distro now?
I got not one encouraging word when I suggested it way back when...

Lol at that thread. Some (including some at Microchip) just don't get what programming is about.

No they are not distributed with the compiler. I generate them from configuration files which are distributed. The same way Microchip generates 400+ HTML files to document the processor configuration options. The commented source files contain exactly the same information as the HTML files but in a format which you can use directly in a program to select options and document them and importantly document the options you haven't selected.

IMO they are much more useful and usable than the HTML files and the stupid one shot option code generator built into MPLAB X.

I think I posted a set for XC8 here before. I attach a set for XC16 1.20 (7zip file because the compression is vastly better than zip).
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: PIC24fv32ka302 & XC16 Compiler - How to set config bits
« Reply #10 on: June 06, 2014, 02:34:04 pm »
Quote
I got not one encouraging word when I suggested it way back when...

there are some merits on both sides of the argument. I think a config generation utility would prove to be quite helpful.

I also think that most of the times, you don't play with config words - you just want to use a set that's tailored to that processor and you may play it on the margin. So you need a default set of config that's 90% there for you and that is easily customizable.

What I do I think fits the bill.

I use a file that contains default config words for many of the processors I use: they are accumulated over the years and whenever I use a new chip, I put its config words in that file. Now, it is over 100KB for 8-bit PICs.

The file takes the basic format:

Code: [Select]
#if defined(CHIP1) || defined(CHIP2)
#pragma config ...
...
#elif defined(CHIP5) || definedCHIP6) ...
#pragma config ...
#else
#warning "no config words set for this chip!"
#endif

The settings and comments are extracted from the header files so if one chooses to customize, it can be done easily.

In the user code, you simply include this file (config.h).

It has served me well over the years.
================================
https://dannyelectronics.wordpress.com/
 

Offline Rufus

  • Super Contributor
  • ***
  • Posts: 2095
Re: PIC24fv32ka302 & XC16 Compiler - How to set config bits
« Reply #11 on: June 06, 2014, 06:46:04 pm »
What I do I think fits the bill.

Hiding them in 99k of completely irrelevant crap and having to cross reference #defines in another file is a good way of setting and documenting processor options?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf