1
\$\begingroup\$

I can setup system configuration bits (fuses) in the MPLAB X project and/or in the code directly:

enter image description here

I understand that the ones on the Configutaion Bits tab are stored in the project somewhere. Is that right? If yes, my questions is:

How do they relate to each other as they can be easily different?

\$\endgroup\$
  • \$\begingroup\$ I understand that you are asking only if the IDE stores your sections from Configuration Bits tab. The IDE does not do this. As for my description of how to setup the configuration words using the dsPIC assembler. This was something that had me confused for weeks. My answer has the description I would have liked to have seen when I needed help. Perhaps this will help someone else. \$\endgroup\$ – Dan1138 Jan 12 at 2:23
  • \$\begingroup\$ NP. For me assembler is something super easy. \$\endgroup\$ – Kirill Kobelev Jan 12 at 3:32
1
\$\begingroup\$

I understand that the ones on the Configutaion Bits tab are stored in the project somewhere. Is that right?

As you stated it this is not correct.

The "Configuration Bits" tab is the way to describe how the configuration words for your PIC controller project need to be setup.

enter image description here

Once you have setup for configuration bits click on the "Generate Source Code to Output" button. Select the "Output - Config Bits Source" tab and cut and paste the content to just one your source code files.

The output is usually C language source code.

As you seem to be coding with PIC assembly for the dsPIC this gets a lot trickier.

This is an example for the dsPIC30F6015:

/*
 * File:   main.s
 * Author: dan1138
 * Target: DSPIC30F6015
 *
 * Created on Januay 11, 2019
 */

    .include "xc.inc"

;// FOSC
;#pragma config FOSFPR = FRC             // Oscillator (Internal Fast RC (No change to Primary Osc Mode bits))
;#pragma config FCKSMEN = CSW_FSCM_OFF   // Clock Switching and Monitor (Sw Disabled, Mon Disabled)
 config __FOSC, FRC & CSW_FSCM_OFF

;// FWDT
;#pragma config FWPSB = WDTPSB_16        // WDT Prescaler B (1:16)
;#pragma config FWPSA = WDTPSA_512       // WDT Prescaler A (1:512)
;#pragma config WDT = WDT_ON             // Watchdog Timer (Enabled)
 config __FWDT, WDTPSB_16 & WDTPSA_512 & WDT_ON

;// FBORPOR
;#pragma config FPWRT = PWRT_64          // POR Timer Value (64ms)
;#pragma config BODENV = BORV20          // Brown Out Voltage (Reserved)
;#pragma config BOREN = PBOR_ON          // PBOR Enable (Enabled)
;#pragma config LPOL = PWMxL_ACT_HI      // Low-side PWM Output Polarity (Active High)
;#pragma config HPOL = PWMxH_ACT_HI      // High-side PWM Output Polarity (Active High)
;#pragma config PWMPIN = RST_IOPIN       // PWM Output Pin Reset (Control with PORT/TRIS regs)
;#pragma config MCLRE = MCLR_EN          // Master Clear Enable (Enabled)
 config __FBORPOR, PWRT_64 & BORV20 & PBOR_ON & PWMxL_ACT_HI & PWMxH_ACT_HI & RST_IOPIN & MCLR_EN

;// FBS
;#pragma config BWRP = WR_PROTECT_BOOT_OFF// Boot Segment Program Memory Write Protect (Boot Segment Program Memory may be written)
;#pragma config BSS = NO_BOOT_CODE       // Boot Segment Program Flash Memory Code Protection (No Boot Segment)
;#pragma config EBS = NO_BOOT_EEPROM     // Boot Segment Data EEPROM Protection (No Boot EEPROM)
;#pragma config RBS = NO_BOOT_RAM        // Boot Segment Data RAM Protection (No Boot RAM)
 config __FBS, WR_PROTECT_BOOT_OFF & NO_BOOT_CODE & NO_BOOT_EEPROM & NO_BOOT_RAM

;// FSS
;#pragma config SWRP = WR_PROT_SEC_OFF   // Secure Segment Program Write Protect (Disabled)
;#pragma config SSS = NO_SEC_CODE        // Secure Segment Program Flash Memory Code Protection (No Secure Segment)
;#pragma config ESS = NO_SEC_EEPROM      // Secure Segment Data EEPROM Protection (No Segment Data EEPROM)
;#pragma config RSS = NO_SEC_RAM         // Secure Segment Data RAM Protection (No Secure RAM)
 config __FSS, WR_PROT_SEC_OFF & NO_SEC_CODE & NO_SEC_EEPROM & NO_SEC_RAM

;// FGS
;#pragma config GWRP = GWRP_OFF          // General Code Segment Write Protect (Disabled)
;#pragma config GCP = GSS_OFF            // General Segment Code Protection (Disabled)
 config __FGS, GWRP_OFF & GSS_OFF

;// FICD
;#pragma config ICS = ICS_PGD            // Comm Channel Select (Use PGC/EMUC and PGD/EMUD)
 config __FICD, ICS_PGD



;..............................................................................
;Program Specific Constants (literals used in code)
;..............................................................................

    .equ SAMPLES, 64         ;Number of samples



;..............................................................................
;Global Declarations:
;..............................................................................

    .global _wreg_init       ;Provide global scope to _wreg_init routine
                                 ;In order to call this routine from a C file,
                                 ;place "wreg_init" in an "extern" declaration
                                 ;in the C file.

    .global __reset          ;The label for the first line of code.

;..............................................................................
;Constants stored in Program space
;..............................................................................

    .section .myconstbuffer, code
    .palign 2                ;Align next word stored in Program space to an
                                 ;address that is a multiple of 2
ps_coeff:
    .hword   0x0002, 0x0003, 0x0005, 0x000A




;..............................................................................
;Uninitialized variables in X-space in data memory
;..............................................................................

    .section .xbss, bss, xmemory
x_input: .space 2*SAMPLES        ;Allocating space (in bytes) to variable.



;..............................................................................
;Uninitialized variables in Y-space in data memory
;..............................................................................

    .section .ybss, bss, ymemory
y_input:  .space 2*SAMPLES




;..............................................................................
;Uninitialized variables in Near data memory (Lower 8Kb of RAM)
;..............................................................................

    .section .nbss, bss, near
var1:     .space 2               ;Example of allocating 1 word of space for
                                 ;variable "var1".




;..............................................................................
;Code Section in Program Memory
;..............................................................................

.text                             ;Start of Code section
__reset:
    MOV #__SP_init, W15       ;Initalize the Stack Pointer
    MOV #__SPLIM_init, W0     ;Initialize the Stack Pointer Limit Register
    MOV W0, SPLIM
    NOP                       ;Add NOP to follow SPLIM initialization

    CALL _wreg_init           ;Call _wreg_init subroutine
                                  ;Optionally use RCALL instead of CALL




        ;<<insert more user code here>>





done:
    BRA     done              ;Place holder for last line of executed code



;..............................................................................
;Subroutine: Initialization of W registers to 0x0000
;..............................................................................

_wreg_init:
    CLR W0
    MOV W0, W14
    REPEAT #12
    MOV W0, [++W14]
    CLR W14
    RETURN




;--------End of All Code Sections ---------------------------------------------

.end                               ;End of program code in this file

Note: You will need to change the #include <xc.h> statement to .include "xc.inc" and change the C style #pragma config statements to ASM style config __REGISTER, SETTINGS statements. Be sure that the names of the configuration bit registers have two _ underscore characters as a prefix.

Important safety tip: The dsPIC assembler is invoked using the C compiler launcher. Your assembly files should use the .s file name extension. The IDE can be forced to use others but this will be the most convenient way to manage file names in your project.

WARNING: The names of the configuration register bit fields in the part specific include .inc assembly file are not always the same as those the IDE knows about for C files. You may need to look in the .inc file to see how they are defined.

\$\endgroup\$
  • \$\begingroup\$ Thanks for your explanation, although it would make sense to delete the part where you give tips on programming in assembler. It does not matter what language is used. There are plenty of different languages available. It can be any language. The question was where MPLAB IDE takes data to program fuses. So, as you are saying, if there is nothing in the code, IDE will not touch the fuses at all? Thanks again for your answer and support. \$\endgroup\$ – Kirill Kobelev Jan 12 at 1:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.