How does Flowcode handle PIC SFR's in a branch or decision?

For general Flowcode discussion that does not belong in the other sections.
Post Reply
TimN-MK
Posts: 6
http://meble-kuchenne.info.pl
Joined: Fri Jun 04, 2021 5:12 pm

How does Flowcode handle PIC SFR's in a branch or decision?

Post by TimN-MK »

E.g. I want to branch on a Comparator change, CM1CON0 but Flowcode will call it FCV_CM1CON0
- how does this get translated, do I have to create my own memory map tables? E.g 990h FCV_CM1CON0

BenR
Matrix Staff
Posts: 1926
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 501 times
Been thanked: 686 times

Re: How does Flowcode handle PIC SFR's in a branch or decision?

Post by BenR »

Hello,

You can read a register into a flowcode variable like this. Lets say the variable is called reg, the C code woulld look like this.

Code: Select all

FCV_REG = CM1CON0;

TimN-MK
Posts: 6
Joined: Fri Jun 04, 2021 5:12 pm

Re: How does Flowcode handle PIC SFR's in a branch or decision?

Post by TimN-MK »

Hi Ben,
That seems a bit messy, adding extra line before what sould be a simple "if" or "do while" statement?

Steve-Matrix
Matrix Staff
Posts: 1465
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 204 times
Been thanked: 347 times

Re: How does Flowcode handle PIC SFR's in a branch or decision?

Post by Steve-Matrix »

If you are not concerned with simulation, then there is an approach that is not 'messy'. You could add a decision icon and then simply customise the C code generated by it by right-clicking the icon and selecting the appropriate menu item. For example, you could change it to:

Code: Select all

if (CM1CON0 & 0x02)
{
Flowcode does not simulate all peripheral registers and so you if you wanted to also simulate your project before downloading to the target, you would need to do a bit more work.

For example, create a variable to hold the register value and then use this in your decision icons. You can manipulate the value of this register variable using simulation-only functionality (e.g. create a property and read the value of it using the "GetValue" Built-in Function), but also add C code to set the value when running on the target. The attached is a very basic example.
Attachments
CM1CON0_sim.fcfx
(7.56 KiB) Downloaded 441 times

TimN-MK
Posts: 6
Joined: Fri Jun 04, 2021 5:12 pm

Re: How does Flowcode handle PIC SFR's in a branch or decision?

Post by TimN-MK »

Steve, thanks for the extra detail on this.
Will addressing the union bitfield definitions in the pic16F18854.h also work in Flowcode?
eg:
if (CMOUTbits.MC1OUT) // Comparator out TRUE
or
if (!CMOUTbits.MC1OUT) // Comparator out FALSE

Steve-Matrix
Matrix Staff
Posts: 1465
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 204 times
Been thanked: 347 times

Re: How does Flowcode handle PIC SFR's in a branch or decision?

Post by Steve-Matrix »

That will work in a C code icon or if you customise the C code in a decision icon.

Post Reply