Delay_ms with variable using microC

Status
Not open for further replies.

Solar000

Member level 2
Joined
Feb 6, 2013
Messages
49
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Greece
Visit site
Activity points
1,649
Hello, i am trying to use Delay_ms function with a variable which i calculate from another function and i want to pass it to the function with the Delay_ms.

I know that Delay_ms is better from Vdelay and works with numbers and constants.
So this works :
Code:
const unsigned long  y=60000/x;
Delay_ms(y);

I want to do this :

Code:
#define Tempo 60

void main(void)
{
const unsigned long DPBms=y(Tempo);
Tetarta(DPBms,4);
}

const y(const x) { 

return (60000/x);
}

void Tetarta(const unsigned long Delay,int metra){
int i;
const unsigned long  Tetarto=Delay;  //it doesn't work.Works only if 60000/Tempo ; instead of delay variable.Also tried   const Tetarto,*Delay;
metra=metra*4;
for(i = 0; i < metra; i++){
Delay_ms(Tetarto);

Movement();

}
}

I want to make one time the calculation and pass the result from one function to another.Why it doesn't work?How i can do this, instead of calculating const y=60000/x;
to every function?
 

Delay_ms function of microc requires constant (fixed), you can't pass variables, even of type constant i think.

You can use macros for calculations.

Code:
#define TEMO 60
#define DELAY 60000/TEMPO

Delay_ms(DELAY)
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…