Inout/output with variable mask

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
User avatar
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:

Inout/output with variable mask

Post 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

User avatar
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

Post 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)

User avatar
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

Post 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
Output_1_to_B_Ports.jpg (7.9 KiB) Viewed 22908 times
But it does not works. What to do?

With kind regards

Jan

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Inout/output with variable mask

Post 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));

User avatar
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

Post 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
Test_variable_Port_index.fcfx
(4.59 KiB) Downloaded 1134 times

Post Reply