This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

help

ive got this code and dont know what is wrong.

#define a 1
#define b 2
#define c 3
#define 22 37
#define binary1 0x01
#define binary2 0x02
#define binary3 0x04
#define binary4 0x08
#define binary5 0x09
#define binary6 0x10
#define binary7 0x20

int toggle__pin ( int port , int pin )
{
  if ( port == a && pin == 1 )
  {
    P0 = binary1;
    delay(1);
    P0 = ~binary1;
  }
  if ( port == a && pin == 2 )
  {
    P0 = binary2;
    delay(1);
    P0 = ~binary2;
  }

  // repeated

  return 23;
}

Parents Reply Children
  • First take at look at your defines....

    Everywhere your code has an a it will be substituted, not just where you think it will be.

    If you use PREPRINT compiler directive it will give you a list of the code the compiler will see after the #define stuff has been added to your code. This will show you a great deal and teach you a lot about how defines work in your code. Simply, each define must have a unique label

    #define PORT_A 1 for eg

  • "Everywhere your code has an a it will be substituted, not just where you think it will be."

    The preprocessor works on tokens, not on individual characters, so the C preprocessor will not replace any a that is part of a longer token or that is inside a C string.