L.R.A 78 Posted July 27, 2013 Share Posted July 27, 2013 I was trying a code that toggles a LED when i press a button. So i used P1OUT^=00000001; just toggle the output state of P1_0 right? Well when i use that the push button stops working. I don't know why but it seems the pin just stays LOW always. Is this command overriding the PinMode command? I'm not sure but after P1REN is used you can control the pins with the pull ups/down enabled with P1OUT wich choses if it is pullup or down. But with P1OUT^=00000001; should not change the bit 3 Used this code to test the state of the pin: boolean estado=digitalRead(P1_3); Serial.println(estado); if (digitalRead(P1_3)==LOW){ // P1OUT ^= 00000011; delay(1); while(digitalRead(P1_3)==LOW){ estado=digitalRead(P1_3); Serial.println(estado); } } } First i enabled the P1OUT line. The serial said that the pin was always 0. The voltmeter confirms that Then i disabled it. The pin is only 0 while it's pressed. The voltmeter also confirms that. Is this normal? Quote Link to post Share on other sites
simpleavr 399 Posted July 28, 2013 Share Posted July 28, 2013 What you are describing (flipping BIT0 only) does not agree w/ your code. I assume it's the line you commented out that's offending. i.e P1OUT ^= 00000011; This is not binary but decimal. The device sees it in hex as 0x0b or binary as 0b00001011. This would toggle the bits 0, 1 and 3 which would upset your button. Or did you paste your actual code accurately? cde 1 Quote Link to post Share on other sites
oPossum 1,083 Posted July 28, 2013 Share Posted July 28, 2013 This is not binary but decimal. The device sees it in hex as 0x0b or binary as 0b00001011. It's octal (for historical reasons) 011 == 9 == 0x09 == 0b00001001 == BIT3 | BIT0 BIT3 is the switch simpleavr and tripwire 2 Quote Link to post Share on other sites
L.R.A 78 Posted July 28, 2013 Author Share Posted July 28, 2013 i dont look into registers for soo long that i forgot how to use them in binary. Thanks Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.