Page 1 of 1

C CODE doesn't work with V3

Posted: Wed Nov 28, 2007 3:33 am
by MIKE_31
Hi,
I write this following program but the C Code doesn't work
LCD display always "48' why ??

Thank
----------------------------------------
//Appel de la Routine Composant
Appel de la Routine Composant:

LCDDisplay(0)::Init
----------------------------------------

----------------------------------------
//Appel de la Routine Composant
Appel de la Routine Composant:

LCDDisplay(0)::Efface
----------------------------------------

----------------------------------------
//Calcul
Calcul:

RANG = 51
TOTO = 3
OUT = 48
----------------------------------------

----------------------------------------
//Boucle
Boucle:

Tant que1
<LOOP>

----------------------------------------
//Code C
Code C:

FCV_OUT = FCV_OUT + 1;
----------------------------------------

----------------------------------------
//Appel de la Routine Composant
Appel de la Routine Composant:

LCDDisplay(0)::Γ‰crit_Num(OUT)
----------------------------------------

----------------------------------------
//Pause
Pause:

1 s
----------------------------------------

----------------------------------------
//Appel de la Routine Composant
Appel de la Routine Composant:

LCDDisplay(0)::Efface
----------------------------------------

</LOOP>
----------------------------------------

Posted: Wed Nov 28, 2007 9:03 am
by Steve
I can think of 2 possibilities:

1) The watchdog timer config bit is enabled, meaning your program restarts before OUT increments

2) The clock sped is set wrong and the delay of 1s is actually much larger.

Posted: Wed Nov 28, 2007 10:21 am
by Benj
The Flowcode simulation will not work as you are using C code to increment the OUT variable. It should work fine on hardware.

re POW in C Code

Posted: Thu Nov 29, 2007 11:56 pm
by MIKE_31
Yes Benj,

Thank a lot,It's better using hardware.......

I have a other question :

Is it possible to have the function pow(x,y) in flowcode ??
If i use it I have a message error ?
How can i use X^Y ??

Thank for you replay........


Mike

Posted: Fri Nov 30, 2007 10:32 am
by Benj
Hello Mike

You can do power calculations as follows.

Create your two variables eg A and B.

Variable A may need to be an Int 16 bit variable to hold the result.

Then assign values to A and B with a calculation icon.

Then create a while loop with "B" in the loop while text box (do not include the brackets). This means that the loop will run while B is greater then 0.

Inside the loop create the following calculation "A = A * A"

Then create another calculation to decrment variable B "B = B - 1"

Hope that this helps.