-1
#define F_CPU 8000000UL
#include <avr/io.h>
#include <util/delay.h>
#define testButton           PINA & 0b00000001;
#define smokeDetector (PINA & (1<<1));
#define ToggleSmoke (PORTE ^= (1<<4));
 
int main(void)
{
 
  ADCSRA = 0b11100111;
  ADMUX =  0b01100110;
  DDRE = 0xFF;
  PORTE = 0x04;
  while(1)
  {
    if (testButton)
    {
      _delay_ms(250);
      ToggleSmoke;
    }
  }
   

}

I'm in the process of making a smoke alarm program and there is a test button that causes the siren in my microcontroller board (AT90USB87) to sound. However, I keep getting the error as expressed in the question. Is there something wrong with my code or is my IDE tripping? The line in question is line 4, which defines the test button.

  • 7
    The semicolon at the end of `testButton` is causing a syntax error when the macro is expanded, i.e. in `if (PINA & 0b00000001;)` The semicolon isn't allowed there. Remove it from the macro (and your other macros), and wrap the value in parentheses so that it can be used in expressions without regrouping. – Tom Karzes Mar 22 '22 at 00:24

1 Answers1

4

Take the ; off the defines.

 #define testButton           PINA & 0b00000001
 #define smokeDetector (PINA & (1<<1))
 #define ToggleSmoke (PORTE ^= (1<<4))

why?

Because #define syntax is this

 #define FOO BAR

Every time FOO appears it is replaced by BAR.

So your code did the following

 #define testButton   PINA & 0b00000001;
         FOOOOOOOOO   BARRRRRRRRRRRRRRRR

and

  if (testButton)

giving

 if (PINA & 0b00000001;)
 ---------------------^

which is not valid c syntax, it expected to see a ')' hence

error "expected ')' before ';' token


as pointed out by Tom Karzes better is

 #define testButton          ( PINA & 0b00000001)

as you did for the other defines

pm100
  • 48,078
  • 23
  • 82
  • 145