Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.
1<<AINpin shifts left 1 AINpin positions, for example
1<<0 =0b00000001
1<<1 =0b00000010
1<<6 =0b01000000
~ is Ones compliment , it actually inverts the bits , 0 become 1s and 1s become 0s so
~(1<<0) =0b11111110
~(1<<1) =0b11111101
~(1<<6) =0b10111111
DDRA&=~(1<<AINpin) is the same as DDRA= DDRA & ~(1<<AINpin).
When you AND any bit with 1 it keeps its value, when you AND it with 0 it becomes 0
DDRA &= ~(1<<0) is the same as DDRA= DDRA & 0b11111110, this will clear (set to 0 bit0 of DDRA) and all other bits will keep the value they had
DDRA &= ~(1<<6) is the same as DDRA= DDRA & 0b10111111, this will clear (set to 0 bit6 of DDRA) and all other bits will keep the value they had
on the other hand DDRA=0x01 will force the value 0b00000001 , it will write these values to each bits of DDRA
The DDRA = 0x01 explicitly sets the value of DDRA to 0x01.
DDRA &= ~(1<<AINpin) performs a logic AND function with the value of the inverted binary number created by a single bit 'AINpin'. It acts on whatever value was already in DDRA.
For example, if AINpin is bit 3, (1<<AINpin) would be 00001000 and ~(1<<AINpin) would therefore be 11110111. The logic AND function therefore makes bit 3 of DDRA into a zero while leaving the other bits as they were.
Brian.
Sorry Alex - we were typing at the same time. Same explanation though!
Yes happens a lot but it's not a bad thing, why be sorry for trying to help, after all two answers are better than none, I have seen this in other cases where the question in very simple and each one leaves someone else to answer the question and in the end nobody answers it.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.