Page 1 of 1
Inout/output with variable mask
Posted: Thu Nov 12, 2015 1:37 pm
by Jan Lichtenbelt
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
Re: Inout/output with variable mask
Posted: Thu Nov 12, 2015 3:56 pm
by Benj
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)
Re: Inout/output with variable mask
Posted: Thu Nov 12, 2015 8:52 pm
by Jan Lichtenbelt
Dear Ben
I tried to set the Ports B0, B1 etc to 1, using the variable shift=0,1.2..7

- Output_1_to_B_Ports.jpg (7.9 KiB) Viewed 26199 times
But it does not works. What to do?
With kind regards
Jan
Re: Inout/output with variable mask
Posted: Fri Nov 13, 2015 9:44 am
by LeighM
Hi Jan,
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));
Re: Inout/output with variable mask
Posted: Fri Nov 13, 2015 10:58 am
by Jan Lichtenbelt
Hi ...
It works. Please find an example with running light. I want to use it for an other application.
With kind regrads
Jan Lichtenbelt