Direct access digital IO pins - not working as expected

Need some help to understand why my program isn't working as expected.

Here's the breadboard view of my circuit.

Basically a ATtiny85 with PB1 hooked to a 4-legged PCB-mount push-button switch, with a 10K pull-down resistor to GND, s.t. when button is pressed PB1 is pulled HIGH, else LOW. Also PB4 is hooked to an LED via a 470R. Only other thing connected to the IC is Vcc and GND.

The current behavior is that the LED is always on, while it was supposed to be normally off, and turn-on only when button is pressed. Here is my code. What is it that I am doing wrong --

// PB1 is of type INPUT
#define XPB1    B00000010
#define XPB1_N  B11111101
// PB4 is of type OUTPUT
#define XPB4    B00010000
#define XPB4_N  B11101111

void setup()
  DDRB = DDRB | XPB4;           // set PB4 to OUTPUT
  PORTB = PORTB & XPB4_N;   // turn off LED

void loop()
  if (PINB & XPB1_N) {
  else {

Is it possible that the conditional expression (PINB & XPB1_N) always evaluates to true ?

Yes. The other pins are floating and could easily be HIGH. Try this...

  if ( (PINB & _BV(PINB1)) != 0 ) {


  if (PINB & XPB1)

Argh... my, so bad ! Deserve a hard kick... yes indeed.


  if (PINB & XPB1)

Precisely. Thanks @MarkT.