0
\$\begingroup\$

I am currently programming an AVR butterfly dev board. I want to take input from the joystick and my program to do certain things whenever the joystick is puled down. To do this I have the following pieces of code. (There are more but this is what you need to answer the question.)

#define false 0

#define true 1

DDRB = (0<<DDB7);

PORTB = (1<<PB7);

....

while (PINB==1)

....

while (PINB==0)

....

Right now the program avt as PINB is never 0 neither is it 1. I think my problem is that I never even read if the joystick is moved down or not.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Welcome to EE.SE. "AVR butterfly" is not a microcontroller. It's a development board. When you are using dev boards an the like, you should at least add links to the documentation. In addition, relevant schematic snippets are even more useful: saves time reading docs. \$\endgroup\$ Commented Jul 12, 2013 at 20:55

1 Answer 1

1
\$\begingroup\$

Checking

while (PINB == 1)  {...}

is probably not what you want. PINB refers to the 8 bit register for the whole port B. If you want to check the state of a specific pin you have to mask it like this:

while (PINB & (1<<PB0)) {...}

That condition is true as long as pin 0 on port B is high.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.