If you include the comments from the code you linked, it actually explains exactly what those #define
s are doing.
#define LTC_CS 2 // LTC2400 Chip Select Pin on Portb 2
#define LTC_MISO 4 // LTC2400 SDO Select Pin on Portb 4
#define LTC_SCK 5 // LTC2400 SCK Select Pin on Portb 5
This seems to explain that the physical IO pin corresponding to IO port B pin 2 of the Arduino shall connect to the CS (Chip Select) pin on the LTC2400, and similarly the other two pins connect to other named pins on the LTC2400.
The reason these numbers are different from the actual physical pin numbers is that they don't refer to the pin number, they refer to the position of the bit that controls the pin in the PORTB
register. sbi(PORTB,LTC_CS)
means "Set the 2nd bit of the PORTB register to 1" and will raise the pin to logic high.
#define
itself is not code that runs on the Arduino; it is a preprocessor directive. What #define
is doing here is defining constants. #define LTC_CS 2
means "In this code file, when I write LTC_CS
, pretend I wrote 2
instead". Later these macros are used in the code like sbi(PORTB,LTC_CS);
. In that function call you could instead write sbi(PORTB,2)
, and since LTC_CS has been defined with a value of 2, it means the same thing and compiles to the same code.