Hello guys, I'm developing a project where I need to set a led just before another led. As far as I read in the datasheet, instruction sets like PORTB|= 0b00000001 takes 1 clock cycle. For reasons of my project I need to assign the other led like this PORTD|=1 . I need to have measured the time between both signals.
So, my question is PORTB|=1 also takes 1 instruction set? This is my code. I just get the number before the other led assignment in order to not create a bigger delay between both signals.
So PORTD led will be turned on 62,5 ns before (Arduino UNO)?
int portBNum = laserArray[counter];
PORTD |= B10000000;
PORTB = portBNum;
You mean "one instruction cycle" but, yes, probably. The values 1 and 0b00000001 are the same. The compiler will probably generate a 'set bit immediate' instruction.
There should be no difference. The compiler converts C++ into machine code where EVERYTHING in binary.
Usually, binary or hex is used when a value represents a bit states or bit pattern so it's easy for humans visualize what the code is doing.
(Hex is popular because it's easier to read & write hex, especially when you get to 16-bits or more, and you can learn to convert variables of any size between hex & binary in your head. With decimal you need a calculator, except you don't need a calculator for 1. )