Hello!
I just had a project in which I wanted the ADC clock division to be calculated by the preprocessor rather than the user/me.
So I did what I normally do in assembler in AVR GCC which gave me weird errors, so I reverted to this older trick, which gave the same errors:
#define ADC_CLOCK_PRESCALER 4; /* 0 = div 2 (100kHz to 400kHz I/O clock) 1 = div 2 (100kHz to 400kHz I/O clock) 2 = div 4 (200kHz to 800kHz I/O clock) 3 = div 8 (400kHz to 1600kHz I/O clock) 4 = div 16 (800kHz to 3200kHz I/O clock) 5 = div 32 (1600kHz to 6400kHz I/O clock) 6 = div 64 (3200kHz to 12800kHz I/O clock) 7 = div 128 (6400kHz to 25600kHz I/O clock) */ int main(void) { // some code ADCSRA = (0b11001000 | (ADC_CLOCK_PRESCALER & 0b00000111)); // more code }
This throws the error "Expected ')' before ';'." on that line.
I can take the logic operation out of the code and put it into a definition: Same error.
I can do:
ADCSRA = (0b11001000 | ADC_CLOCK_PRESCALER);
And it compiles and runs without problems, independent of whether the logic operation is in code or in a constant definition (which is logical, as the preprocessor usually merely replaces constants by their definition).
But no matter how I want to add the & operation to it, it will keep throwing that error, even if I do:
#define ADC_CLOCK_PRESCALER 4; #define ADC_PRESC_MSKD (ADC_CLOCK_PRESCALER & 0b00000111); #define ADCSRA_CONST_DEF (0b11001000 | ADC_PRESC_MSKD);
Any time the & is used in conjunction with the | no matter how many parantheses I add or remove from the formula it throws the error, while the same method works fine in avr assembler.
Anyone out there have a clue why this is? Just curious really, not a real problem.
Robert!