I need clarification.
I undertand what << operator does
The left shift operator
<< causes the bits of the left operand to be shifted left by the number of positions specified by the right operand.
variable << number_of_bits;
Now with pin registers I have following command
1 << DDC3
I thought DDC3 would represent the 4th bit of the DDRC register but by the look of it DDC3 is the index of that bit so it is 4.
then the comand really is
So the command
would set the forth bit of the DDRC register to one meaning setting A3 pin as output
Do I understand this correctly?
DDC3 is a macro defined in iom328p.h (assuming you're compiling for an Uno board):
#define DDRC _SFR_IO8(0x07)
#define DDC0 0
#define DDC1 1
#define DDC2 2
#define DDC3 3
#define DDC4 4
#define DDC5 5
#define DDC6 6
Ok. So that means I got it ok. I am compiling it for Arduino Nano. But this is the same thing
Yes, I think so.
I find the practice of having separate names for "4" depending on which registers you're going to apply
(1<<4) to to be "annoying", but it's common practice. (and you actually want that if the name is something like "the tx complete bit", rather than "bit 4 in register portc", so it sort-of makes sense.)
Unlike Arduino's board-wide "pin numbers", the Atmel-provided definitions have no way of uniquely identifying a port/bit combination in a single symbol.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.