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
variable initialisation
Moderator: Benj
-
Sean
- Valued Contributor

- Posts: 548
- Joined: Tue Jun 26, 2007 11:23 am
- Has thanked: 6 times
- Been thanked: 44 times
Re: variable initialisation
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.
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.
Re: variable initialisation
That runs, thank you so much 

I have learned that at school but i have forgoted it. Now i'll remember that !!
Merry Christmas at all and happy new year !!!


I have learned that at school but i have forgoted it. Now i'll remember that !!
Merry Christmas at all and happy new year !!!

Regards,
Adrien DG
Adrien DG