Re: Help: Explaining Code
Hi,
Please, post your code between code tags. Look here.
The operator <<, is a left shift operator:
Quote:
The << operator shifts its first operand left by a number of bits given by its second operand
So,
Code:
BIT(0) = 1 << 0 = 1;
BIT(1) = 1 << 1 = 10 (binary) = 2 (decimal)
BIT(2) = 1 << 2 = 100 (binary) = 4 (decimal)
...
In other words, left << operator adds n 0's to the right, in binary base. And this is same than multiply first operant (1, in your code) by 2^n in decimal base.
On the other hand, there's a rigth shift operator: >>, that makes the reverse operation: Divides first operator by 2^n.
The instruction:
Code:
PORTD = ~BIT(LEDbit) = ~(1 << (LEDbit));
sets all bits of PORTD to 1, except the bit LEDbit. I guess it should switch led state, but I'm not sure.
I think delay function doesn't wait the amount of time in seconds, unless
Code:
for (t2 = 255; t2 > 0; --t2){
count += 1;
}
takes 1 second exactly in that chip, but it makes 'a delay'.
t2 = 255 is the highest integer for a unsigned char.
AlbertGM