I want to get the input (or set the output) with a variable mask instead of a fixed mask. This last one is possible in Flowcode. But, as far as I know, the variable mask is not possible with Flowcode. The solution in C-code seems simple. For input use the FCP_SET() and for output use FCP_GET(), with the third variable the mask byte.
But where can I find the meaning of the other paramters of these functions?
With kind regards
Jan Lichtenbelt
Inout/output with variable mask
- Jan Lichtenbelt
- Posts: 797
- Joined: Tue Feb 17, 2009 8:35 pm
- Location: Haren GN, the Netherlands
- Has thanked: 128 times
- Been thanked: 264 times
- Contact:
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Inout/output with variable mask
Hello Jan,
You can find the definitions of those functions in the FAMILY_CAL_IO.h file in the CAL directory.
This is the prototype.
FCP_GET(Type, Port, Mask, Shift)
FCP_SET(Type, Port, Mask, Shift, Source)
Type:
B - Byte - Port Byte - Mainly on multi byte devices 16-bit PICs, ARM etc
M - Masked
F - Full Port
A simple way of allowing for data and mask is like this.
Mask = 0x18
Data = 0x08
Reg = (Reg & ~Mask) | (Mask & Data)
A more robust way to do the same thing but using absolute values might be to use something like this.
Shift = 3
Mask = 0x3
Data = 0x1
Reg = (Reg & ~(Mask << Shift)) | ((Mask & Data) << Shift)
You can find the definitions of those functions in the FAMILY_CAL_IO.h file in the CAL directory.
This is the prototype.
FCP_GET(Type, Port, Mask, Shift)
FCP_SET(Type, Port, Mask, Shift, Source)
Type:
B - Byte - Port Byte - Mainly on multi byte devices 16-bit PICs, ARM etc
M - Masked
F - Full Port
A simple way of allowing for data and mask is like this.
Mask = 0x18
Data = 0x08
Reg = (Reg & ~Mask) | (Mask & Data)
A more robust way to do the same thing but using absolute values might be to use something like this.
Shift = 3
Mask = 0x3
Data = 0x1
Reg = (Reg & ~(Mask << Shift)) | ((Mask & Data) << Shift)
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Jan Lichtenbelt
- Posts: 797
- Joined: Tue Feb 17, 2009 8:35 pm
- Location: Haren GN, the Netherlands
- Has thanked: 128 times
- Been thanked: 264 times
- Contact:
Re: Inout/output with variable mask
Dear Ben
I tried to set the Ports B0, B1 etc to 1, using the variable shift=0,1.2..7
But it does not works. What to do?
With kind regards
Jan
I tried to set the Ports B0, B1 etc to 1, using the variable shift=0,1.2..7
But it does not works. What to do?
With kind regards
Jan
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
Re: Inout/output with variable mask
Hi Jan,
You are nearly there, just need to adjust the mask as well ...
You are nearly there, just need to adjust the mask as well ...
Code: Select all
FCP_SET(M,B,(1<<FCV_SHIFT),FCV_SHIFT,(0xFF));
- Jan Lichtenbelt
- Posts: 797
- Joined: Tue Feb 17, 2009 8:35 pm
- Location: Haren GN, the Netherlands
- Has thanked: 128 times
- Been thanked: 264 times
- Contact:
Re: Inout/output with variable mask
Hi ...
It works. Please find an example with running light. I want to use it for an other application.
With kind regrads
Jan Lichtenbelt
It works. Please find an example with running light. I want to use it for an other application.
With kind regrads
Jan Lichtenbelt