Continue to Site

Welcome to EDAboard.com

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.

what is the difference between DDRA&=~(1<<AINpin) and DDRA=0x01

Status
Not open for further replies.

cheenu02

Junior Member level 3
Junior Member level 3
Joined
Jun 16, 2011
Messages
31
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,500
what is the difference between DDRA&=~(1<<AINpin) and DDRA=0x01
 

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

Alex
 

Big difference:

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!
 
Last edited:

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.

Best regards
Alex
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top