Compiler directive error

Thread Starter

dpeterson3

Joined Oct 9, 2009
19
I haven't used compiler directives too much in the past, but I found somewhere where one would be useful if I could get it to compile. I am writing a software PWM class for an AVR and have a function called generate_PWM

Rich (BB code):
#define Generate_PWM (c) { \
    if (c < 6) pinlevelB &= ~(1 << PORTB##c); \
    else { \ 
        c = c - 6; \
        pinlevelB &= ~(1 << PORTC##c);  \
    }
It gets called from here
Rich (BB code):
int i = 0; 
    for (i = NUMPWM; i = 0; i++) { 
        if (pwm == timer) { 
            Generate_PWM(i); 
        } 
        else if (timer == 0) {     
            Generate_PWM(i); 
        } 
    } 
}

I get this error message when I try to compile
Rich (BB code):
softPWM.c:36: error: ‘c’ undeclared (first use in this function)
softPWM.c:36: error: (Each undeclared identifier is reported only once
softPWM.c:36: error: for each function it appears in.)
softPWM.c:36: error: expected ‘;’ before ‘{’ token
softPWM.c:42: error: expected declaration or statement at end of input
softPWM.c:42: error: expected declaration or statement at end of input
I have seen this done before for PIC programing (in fact, I am almost borrowing this directly). Not sure why it won't compile. Thanks in advance
 
Remember that with pre-processor macros, the pre-processor will replace the identifier string with replacement string.

Look closely at the macro code that you posted. Where does the identifier string end and the replacement string begin?

Good luck!
 
Last edited:
Top