relation between the physical and the logical values

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

I have a DVK90CAN1 evaluation board for AT90CAN128. This board has a compass card with 5 buttons. If a button is pressed, the connected pin will be ground level. To my surprise if I press the button, I get a logic ONE on the port. Is it possible to set the relation between the physical and the logical values?

Thank you
Senmeis

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is where the ! operator in C comes in handy.

As in:

if (!(PINB & (1<<PB3))) {
  // switch is on
}
else {
  // switch is off
}

Alternatively you simply use:

if (PINB & (1<<PB3)) {
  // switch is off
else {
  // switch is on
}

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If all the bits are contained in the same variable, I would use "~" operator (1´s complement).
like portbits = ~PB

clawson wrote:
This is where the ! operator in C comes in handy.

As in:

if (!(PINB & (1<<PB3))) {
  // switch is on
}
else {
  // switch is off
}

Alternatively you simply use:

if (PINB & (1<<PB3)) {
  // switch is off
else {
  // switch is on
}

Debugging is for sissies and delivery for surgeons. Real men do demonstration.