#Define

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
stewartbaker
Posts: 116
Joined: Tue Jul 17, 2012 9:34 am
Been thanked: 18 times
Contact:

#Define

Post by stewartbaker »

Coming from an assembler background something I miss in Flowcode is the ability to define Port pins with a label.

e.g

#DEFINE INHIBIT PORT B, 2

So INHIBIT = True

rather than B2 = True

It's all right using standard pin labels with simple projects, but gets tedious when many I/O pins are involved. Easy to make simple mistakes...

Is there anyway to use labels to reference Port pins in Flowcode ?

Cheers

Stewart

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: #Define

Post by Benj »

Hi Stewart,

The simplest way using Flowcode v6 is to use properties. Click on an empty area of the Flowcode panel and in the property window you will get properties for your project, default is none.

Click on the drop down by the "Properties" heading in the properties window and select "Add New".

Give it a meaningful name and variable name e.g. "My Pin" and "pin" and set the type to a "single digital pin".

Then you can select the pin as you normally would for a component and assign values to the pin by passing values to the variable.

e.g. using a calculation icon you can enter things like..

Code: Select all

pin = 1       //outputs a logic 1
pin = 0       //outputs a logic 0
var = pin       //Reads the input logic level and assigns to var

stewartbaker
Posts: 116
Joined: Tue Jul 17, 2012 9:34 am
Been thanked: 18 times
Contact:

Re: #Define

Post by stewartbaker »

Hi Benj,
I was OK up to "Give it a meaningful name and variable name e.g. "My Pin" and "pin" and set the type to a "single digital pin"."
Then I am lost...

If I want to set up for example PORT B pin 2 as INHIBIT, what must I enter ? The fancy bits can come later.

Cheers

Stewart

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: #Define

Post by Benj »

Hello,

Creating a property is a lot like creating a variable.

The cosmetic name is essentially the label shown by the property in the property window.
The property type is a drop down list of available property types, for a single pin connection you need the single digital pin setting.
The property variable is the variable name which you will use to refer to the property value in your program.

When you click ok the property is created allowing you to assign a pin to the property variable, like you would for a LED component for example.

You then refer to the property variable in your program e.g. if the property variable is ready_led then in your program you would write ready_led = 1 using a calculation icon to output a 1 to the pin.

stewartbaker
Posts: 116
Joined: Tue Jul 17, 2012 9:34 am
Been thanked: 18 times
Contact:

Re: #Define

Post by stewartbaker »

Hi Benj,
Got it...
I had not pressed OK, so did not take things to the next step - Duh !

That seems to work and do what I want. However, I have some questions.

1) Is the cosmetic name used anywhere other than the property window ?

2) What is "Generate a define for the property" used for ? It works OK with this unticked.

3) I presume that it is not possible to monitor a property variable in the Simulation window during debugging, but rather use the actual pin ?

Cheers

Stewart

miggarcbs
Posts: 20
Joined: Fri Dec 04, 2015 1:14 pm
Location: Portugal
Been thanked: 2 times
Contact:

Re: #Define

Post by miggarcbs »

Hi

stewartbaker asked " if I want to set up for example PORT B pin 2 as INHIBIT "


I´m with Flowcode 9 with microchip PICs at the enterprise I work.
At home I have bought flowcode 6 some years ago.

So, I ask nearly the same, assuming both version could do it:

If I want to set up for example PIC PORTB RB2 as TEST ?

Which will be the cosmetic name and the property variable.

should I check generate a variable for the property ?

Can someone tell me how to achieve the same, please?

Thanks,

Miguel
.
.

Thanks in advance,

---------------------------------------------

Miguel Garcia
Electronics Technician
Electronic Systems Developer

.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: #Define

Post by medelec35 »

Hi Miguel.
Hover over the lower properties to show a drop-down.
Select Add new
Panel Properties.png
Panel Properties.png (27.5 KiB) Viewed 5061 times
The Cosmetic name will be TEST
You can have spaces within the cosmetic name.
The Property type you can select Single digital pin.
The Property variable can be something like PIC_PORTB_RB2.
Leave Visible, Writable and Generate a define for the property as the defaults.
After Selecting OK, you will need to select the pin that is next to TEST
The TEST is now available to use which will be assigned to your chosen pin.

For future reference, the Flowcode forums are for any V9 related questions.
You can sign up for them here if not already done so
Martin

miggarcbs
Posts: 20
Joined: Fri Dec 04, 2015 1:14 pm
Location: Portugal
Been thanked: 2 times
Contact:

Re: #Define

Post by miggarcbs »

Hi medelec35

Lots of thanks for your answer...

That days my mind was too jammed and you made things much more clear..
Last edited by miggarcbs on Sun Feb 13, 2022 5:18 pm, edited 1 time in total.
.
.

Thanks in advance,

---------------------------------------------

Miguel Garcia
Electronics Technician
Electronic Systems Developer

.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: #Define

Post by medelec35 »

Hi Miguel.
You're welcome.
I'm happy I have helped you.
Martin

Post Reply