- Is it possible to create a macro were the PORT and/or PIN can be provided as parameter? If it is possible, can you please provide some example?
- I set on panel properties panel few definitions of digital pin to be used on macros. So I can change the PORT/PIN easilly, but the INPUT/OUTPUT blocks do not accept any of these definitions. The only way to use it is using the CALCULATION blocks. Can you please confirm these two code writing will generate the same code, configuring all register correctly?
IO pin as variable
Moderator: Benj
- CamargoF
- Posts: 36
- Joined: Thu Aug 02, 2018 8:16 pm
- Location: Sao Paulo, SP - Brazil
- Has thanked: 6 times
- Been thanked: 7 times
- Contact:
IO pin as variable
Can you please clarify the following doubts about IO in Flowcode?
-
- Valued Contributor
- Posts: 1191
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 440 times
- Contact:
Re: IO pin as variable
Unfortunately (I think it would be a useful feature) - FC doesn't seem to support this directly.
However it is pretty easy to implement a macro to do it for you:
Note that this is specific for AVR (328p) processors - with ports B, C and D - and would need to be tweaked for other MCUs. The principle is simple though...
Martin
However it is pretty easy to implement a macro to do it for you:
Note that this is specific for AVR (328p) processors - with ports B, C and D - and would need to be tweaked for other MCUs. The principle is simple though...
Martin
- CamargoF
- Posts: 36
- Joined: Thu Aug 02, 2018 8:16 pm
- Location: Sao Paulo, SP - Brazil
- Has thanked: 6 times
- Been thanked: 7 times
- Contact:
Re: IO pin as variable
And what about the properties?
If I create a property TXpin = $PORTC.3 and a local bir variable .flag, the compiled code will be the same read an input pin:
If I create a property TXpin = $PORTC.3 and a local bir variable .flag, the compiled code will be the same read an input pin:
- INPUT BLOCK $PORTC.3 --> .flag
- CALCULATION BLOCK .flag = TXpin
- OUTPUT BLOCK .flag --> $PORTC.3
- CALCULATION BLOCK TXpin = .flag
-
- Valued Contributor
- Posts: 1191
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 440 times
- Contact:
Re: IO pin as variable
The Input/Output blocks don't accept/use the variables - however using them in a calculation works perfectly.
generates:
(With TXpin set to port B1)
Martin
Code: Select all
TXpin = .flag
.flag = TXpin
Code: Select all
SET_PORT_PIN(B, 1, FCL_FLAG);
FCL_FLAG = GET_PORT_PIN(B, 1);
Martin
- Steve
- Matrix Staff
- Posts: 3424
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
- Contact:
Re: IO pin as variable
Another thing you could do if you wanted to preserve the look of your flowchart is to use an input or output icon and customize the C code appropriately.
- 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: IO pin as variable
For dynamic pins where you want easy configuration but fixed at compile time use a pin property and calculation icons.
For dynamic pins where you need dynamic functionality on the embedded device use a function like Martin created.
The I/O icons are not currently dynamic and will always target a fixed port or pin and so if you change the pin you will have to edit every icon that references it.
For dynamic pins where you need dynamic functionality on the embedded device use a function like Martin created.
The I/O icons are not currently dynamic and will always target a fixed port or pin and so if you change the pin you will have to edit every icon that references it.
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