This code was posted 2 or 3 years ago from AVR freaks and the user is probably moved on. Therefore, I have been trying to understand what is going on line by line. I know that the user is pulsing the TX pin high and low for specific delay times but, I am having trouble understanding the lines that look like bit shifting and compounding. Basically, anywhere there are things that look like "bitwise" code, I get confused.

If someone would have time to do something like...///"this line he is compound x and y to get x(y)"Or other wise say TX_PORT &= ~_BV(TX_BIT); ///"this line means this".

I would be grateful for any help or direction to help me understand what this code is doing.

11.6 What is all this _BV() stuff about?When performing low-level output work, which is a very central point in microcontrollerprogramming, it is quite common that a particular bit needs to be set or clearedin some IO register. While the device documentation provides mnemonic names forthe various bits in the IO registers, and the AVR device-specific IO definitions reflectthese names in definitions for numerical constants, a way is needed to convert a bitnumber (usually within a byte register) into a byte value that can be assigned directlyto the register. However, sometimes the direct bit numbers are needed as well (e. g. inan SBI() instruction), so the definitions cannot usefully be made as byte values in thefirst place.

So in order to access a particular bit number as a byte value, use the _BV() macro.Of course, the implementation of this macro is just the usual bit shift (which is doneby the compiler anyway, thus doesn't impose any run-time penalty), so the followingapplies:_BV(3) => 1 << 3 => 0x08

However, using the macro often makes the program better readable."BV" stands for "bit value", in case someone might ask you. :-)

So, the following statement clears the TX_BIT in the TX_PORT register. Refer to the datasheet to understand the register and bit mnemonics. Not sure which datasheet to refer you to, as TX_PORT and TX_BIT aren't in the few AVR datasheets that I'm familiar with.

Thank you Jack Christensen! You have solved the BV mystery that I was hung up in! I followed your link for the manual and found the quote for BV on page 77. I am that much wiser now.

@Awol, I think you are correct about the TX_PORT being a general define for a port register. I wasn't sure about it but, when it would not compile I suspected it as a variable that needed defined somewhere.

Thanks you guys have gotten me closer to understanding how to put this to use.

Thank you WizenedEE for taking the time to comment every part of that code! I looked up shiftOut() and I can see the similarity. I am going to take parts of the code and do some tests with an led and see if I can see it in action.

@Awol thanks for pointing out the "without the clock" part, I found what you mean in the shift() tutorial.