"Integral constant expected"

Thread Starter

peck68

Joined Nov 27, 2009
73
For some reason i can't use a variable to use with delay_us() with Mikro for a PIC, I am making like a homemade PWM since my pic doesn't support it

Rich (BB code):
unsigned int delay;
void main(){
    TRISB = 0;
    PORTB = 0;
    delay = 0;
    while(1){
        PORTB = 0xff;
        delay_us(1);
        PORTB = 0;
        delay_us(delay);
        
        if(delay < 50000){
            delay++;
        }
        else{
            delay--;
        }
    }
}
That brings up the error of "Integral constant expected" for "delay_us(delay);"

However if i used say delay_us(5); it works completely fine?

thanks for any help :)
 

rjenkins

Joined Nov 6, 2005
1,013
You'll have to write you own delay loop function, just a for( ; ; ) with the input value multiplied by whatever you need to get uS.
 
Last edited:

mik3

Joined Feb 4, 2008
4,843
The delay_us() function does not support variables, according to your problem. Therefore, as rjenkins said, you can use a for loop and set the delay_us() inside the loop to 1 us. Then use your variable delay to execute the loop as many times you want the total delay.
 
Top