Hi,
in the past I have manually set register bits by bit shifting in a C code component.
for example,
PIR1 = PIR1 & ~(1<<2); // Clear CCP1IF
PIE1 = PIE1 | 0x04; // Set CCP1IE
When robbing, bodging and checking against with C code examples from Microchip application notes, I see they use an easier to read method.
PIR1bits.CCP1IF = 0; // Clear CCP1 interrupt flag
PIE1bits.CCP1IE = 1; // Enable the CCP1 int
Can this method be used without issue in Flowcode C code components?
Obviously your register names have to be correct to avoid throwing a compile error!
Setting Register Value in C Code
-
- Posts: 215
- http://meble-kuchenne.info.pl
- Joined: Sun Dec 20, 2020 6:06 pm
- Has thanked: 81 times
- Been thanked: 56 times
Re: Setting Register Value in C Code
In another project I also See, they use something similar in IF statements.
if (SSPSTATbits.D_nA) // If D_nA = 1 then TRUE
if (!SSPSTATbits.R_nW) //If R_nW = 0 then TRUE
Can something similar be used in a Normal FC IF Statement? Would it need just need FCV_ adding to it?
FlowCode IF componet = "FCV_SSPSTATbits.D_nA" // If D_nA = 1 then TRUE
or is there a similar method that works?
thanks, J.
if (SSPSTATbits.D_nA) // If D_nA = 1 then TRUE
if (!SSPSTATbits.R_nW) //If R_nW = 0 then TRUE
Can something similar be used in a Normal FC IF Statement? Would it need just need FCV_ adding to it?
FlowCode IF componet = "FCV_SSPSTATbits.D_nA" // If D_nA = 1 then TRUE
or is there a similar method that works?
thanks, J.
-
- Matrix Staff
- Posts: 1476
- Joined: Sat Dec 05, 2020 10:32 am
- Has thanked: 207 times
- Been thanked: 349 times
Re: Setting Register Value in C Code
Yes, that should work fine. It will obviously not simulate though.jay_dee wrote: ↑Mon Mar 31, 2025 9:26 amWhen robbing, bodging and checking against with C code examples from Microchip application notes, I see they use an easier to read method.
PIR1bits.CCP1IF = 0; // Clear CCP1 interrupt flag
PIE1bits.CCP1IE = 1; // Enable the CCP1 int
Can this method be used without issue in Flowcode C code components?
jay_dee wrote: ↑Mon Mar 31, 2025 9:32 amIn another project I also See, they use something similar in IF statements.
if (SSPSTATbits.D_nA) // If D_nA = 1 then TRUE
if (!SSPSTATbits.R_nW) //If R_nW = 0 then TRUE
Can something similar be used in a Normal FC IF Statement? Would it need just need FCV_ adding to it?
No, not directly. You could first read the bit into a Flowcode variable in a C code icon and then use a decision icon on that variable:
FCV_MYVAR = SSPSTATbits.D_nA;
...then "if MyVar" in the decision.
Or you could customise the code of the decision icon and use C there directly.
Re: Setting Register Value in C Code
Hi Steve,
If I have a FC LOCAL variable, inside a user macro. How would I reference this in C ?
Assuming "MyMacro" and Local Variable ".MyVar"
would something like FCV_MYVAR = SSPSTATbits.D_nA;
become
FCV_MYMACRO.MYVAR = SSPSTATbits.D_nA;
?? thanks, John.
If I have a FC LOCAL variable, inside a user macro. How would I reference this in C ?
Assuming "MyMacro" and Local Variable ".MyVar"
would something like FCV_MYVAR = SSPSTATbits.D_nA;
become
FCV_MYMACRO.MYVAR = SSPSTATbits.D_nA;
?? thanks, John.
-
- Matrix Staff
- Posts: 1476
- Joined: Sat Dec 05, 2020 10:32 am
- Has thanked: 207 times
- Been thanked: 349 times
Re: Setting Register Value in C Code
The short answer is FCL_MYVAR. The suffix for globals is "FCV_" and the suffix for locals is "FCL_".
In the C-code icons (which includes any other icons that have been customised), you can drag variables from the lists on the right onto the C code. When dropped, they will be added to the C code text with the appropriate C reference.
In the C-code icons (which includes any other icons that have been customised), you can drag variables from the lists on the right onto the C code. When dropped, they will be added to the C code text with the appropriate C reference.