Understanding code

Having trouble understanding what this code means. In line 1 becomes, is the “1” a set bit and the 7 is the number of places it moves left? And then it is “OR” with what port D is already set to and that gives a high (or a bit set to 1) in position 7 ( the position start at 0) and leaves all the other positions unchanged. If that is true then I understand line 2.
Thanks for any help.

Line 1 SET(PORTD, 7); //Set pin 7 High
Line 2 CLR(PORTD, 7); // Set pin 7 Low

#define SET(x,y) (x|=(1<<y))
#define CLR(x,y) (x&=(~(1<<y)))

Line 1 becomes (PORTD|=(1<<7)) //gives B1xxxxxxx on portd
Line 2 becomes (PORTD&=(~(1<<7))) //gives B0xxxxxxx on portd

&= (compound bitwise and) // logic AND
~ (bitwise not) // logic NOT
<< (bitshift left)
|= (compound bitwise or) // logic OR

PORTD 8 bit “D” port

#define is a useful C component that allows the programmer to give a name to a constant value before the program is compiled. Defined constants in arduino don’t take up any program memory space on the chip. The compiler will replace references to these constants with the defined value at compile time.

Your thinking is okay.

Think of a macro as being text substitution handled by the pre processor.

Thanks for the link to Port Registers, the information is out there if I could only find it. Being pointed in the right direction is a big help. I had read the 328P datasheet but somehow I just seem to miss some of the finer points.

Again thank to both of you for your answers.

@1steve
Here are some fun macros:

// DebugMacros.h

/* Example of use:
   #define DEBUG          // <-----<<<< this line must appear before the include line
   #include <DebugMacros.h>
*/

//If you comment the line:  #define DEBUG
//The Macro lines are defined as blank, thus would be ignored by the compiler.
//If the line is NOT commented, these macros will be included in the sketch.
// examples:
// This  converts to         >>>>----->         This OR a Blank Line. 
//---–----------------------------------------------------------------------------------------
// DPRINTLN("Testing123");   >>>>----->     Serial.println("Testing123"); 
// DPRINTLN(0xC0FFEEul,DEC); >>>>----->     Serial.println(0xC0FFEEul,DEC);
// DPRINTLN(12648430ul,HEX); >>>------>     Serial.println(12648430ul,HEX);
// DPRINTLNF("This text came from flash");  Serial.println(F("This text came from flash"));
// DPRINT(myVariable);       >>>>----->     Serial.print(myVariable);
// DELAY(100);               >>>>----->     delay(100);
// SERIALBEGIN(9600);        >>>>----->     Serial.begin(9600);
// PINMODE(13,OUTPUT);       >>>>----->     pinMode(13,OUTPUT);
// TOGGLEd13;                >>>>----->     PINB = 0x20;  // D13 Toggle,for UNO ONLY
 
#ifdef DEBUG
//#define DPRINT(args...)  Serial.print(args)             //OR use the following syntax:
#define SERIALBEGIN(...)   Serial.begin(__VA_ARGS__)
#define DPRINT(...)        Serial.print(__VA_ARGS__)
#define DPRINTLN(...)      Serial.println(__VA_ARGS__)
#define DRINTF(...)        Serial.print(F(__VA_ARGS__))
#define DPRINTLNF(...)     Serial.println(F(__VA_ARGS__)) //Printing text using the F macro
#define DELAY(...)         delay(__VA_ARGS__)
#define PINMODE(...)       pinMode(__VA_ARGS__)
#define TOGGLEd13          PINB = 0x20                    //For the UNO only
 
#else
#define SERIALBEGIN(...)   //blank line
#define DPRINT(...)        //blank line
#define DPRINTLN(...)      //blank line
#define DPRINTF(...)       //blank line
#define DPRINTLNF(...)     //blank line
#define DELAY(...)         //blank line
#define PINMODE(...)       //blank line
#define TOGGLEd13          //blank line 
 
#endif
//***************************************************************

And Arduino has it's "bit" macros:

bitSet(PORTD,7);
bitClear(PORTD,7);
bitWrite(PORTD,7,a >= b);

Delta_G:
There's a debug macro like that which uses stringification so that you can pass in something like:

BUGOUT(myVariable)

and it turns into:

Serial.print("myVariable");

Serial.print(" = ");
Serial.println(myVariable);





But I remember there being something about how to do it safely and I don't remember all the details. Maybe someone can enlighten us. 

I know we had a thread on it before here, but I have searched many times before and I can't find it. I know I was involved in it.

http://forum.arduino.cc/index.php?topic=309948.0