variable initialisation

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
Adrien DG
Posts: 15
Joined: Thu Jun 11, 2009 11:09 am

variable initialisation

Post by Adrien DG »

Hello All !

i'm always working on a PIC - CPLD project, with SPI communication
I have to initialize an "unsigned long time = 0" variable in a macro, but i have a problem...
There is a while loop in my program, so it's always executed and i need to use this variable 'time',
but when i wrote Unisgned long time = 0 (init) i can work, with it (increment and decrement), but when i come back in this macro the variable is re-initialized.
So i've tried to put the initialisation out of the while loop, at the begining of the program, and at this time, i have a lot of error sayong "unknown variable 'time'"...
i don't know how can i resolve that !

one more time excuse me for my english.
Regards,

Adrien DG
France
Regards,
Adrien DG

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times

Re: variable initialisation

Post by Sean »

Hello Adrien

This looks like code from a C Code block. If this is the case, you might be able to declare and initialise the variable in the macro using the 'static' directive:

static unsigned long time = 0;

This should cause the variable to be initialized on the first call to the macro, and any changes retained on subsequent calls.

Adrien DG
Posts: 15
Joined: Thu Jun 11, 2009 11:09 am

Re: variable initialisation

Post by Adrien DG »

That runs, thank you so much ImageImage

I have learned that at school but i have forgoted it. Now i'll remember that !!

Merry Christmas at all and happy new year !!! Image
Regards,
Adrien DG

Post Reply