NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » Setting register bits back to 0
November 11, 2010 by carlhako |
Quick question about settings the bits. I know this bit of code works
Im not too sure how its setting 2 bits in 1 go using a or statment? My reason for the question is I have the following bit of code to turn the clock off and im not sure if it will work.
Since im flipping the bits i am not sure if a | is correct. Ive googled a few c if guides and gone through the forums but cant find this explained. Thanks |
---|---|
November 11, 2010 by carlhako |
Ok I think i figured this one out, after going over bitwise again. e.g. A = 00001010 B = 1 C = 1 A &= ~((B<<3) | (C<1)); will be this 00001010 and 11110101 = 00000000 I think im right. My original command will work. |
November 11, 2010 by bretm |
That's right. The previous post wouldn't work because it's missing some parenthesis:
~(1<<CS01) is 11111101 ~(1<<CS00) is 11111110 OR them together and you get 11111111 AND that with TCCR0B and nothing will happen You need
|
January 15, 2011 by carlhako |
I am working on a new project where I am setting 2 pins back to low, I easily forget stuff so I have had to re go over this. Im pretty sure that last command is incorrect. Was probably just overlooked.
should be
if you use the first command (1<<CS01) = 00000010 ~(1<<CS00) = 11111110 or that you get 11111111 need to get rid of the ~ within the parenthesis (1<<CS01) = 00000010 (1<<CS00) = 00000001 or that you get 00000011 flip those bits around with a ~ then &= it on the register to just set those bits to 0. I ended up finding an easier way to alternate something between on/off. Every time this bit of code executes the bit is flipped.
|
Please log in to post a reply.
Did you know that you can build an analog amplifier with one transistor and a few resistors? Learn more...
|