LED glows on low port is set to 0

arduinocledmicrocontroller

I have an Arduino UNO board with a ATMEGA328-PU and am trying to control the LED on output 13 that is on the processor pin B5.

I have a switch connected on the Arduino port 7, which is on the processor pin D8.
This is the program I am running on the Arduino IDE like this:

    #include <util/delay.h>

   void setup() {                

   DDRB = DDRB | 0xff;
   DDRD = DDRD & 0x7f;
   PORTD=PORTD | 0x80; 
   }


   void loop() {
         ReadSwitch();
              }


   void ReadSwitch()
   {
    PORTB= PORTB | 0xff;   
     _delay_ms(500);
     if(PIND & 0x80)
        {
        PORTB=0x00;
        }
     else
       {
        PORTB= 0xff;   
        }
     _delay_ms(500);

   }

My question is: when I set the PORTB to all 0's it switches on the LED, but when I set it to all 1, it switches off the LED. How is that possible? Should not the LED switch off when the PORTB is set to 0? Is this normal or something is broken somewhere?

For a bit of background: I have been programming.NET for many years but have never written programs for the microprocessors directly. So I am really new, if this question is inappropriate for this forum, kindly re-direct me to the correct place.

Best Answer

After reading the comments and researching "pull up registers" some more, I have come to understand that my mental image of "pull up" registers was wrong. Fundamentally, when the pull up configuration is used, the switch "press" causes a 0 on the pin. When the switch is open it causes a 1 on the pin.I thought it was the other way around, hence the confusion.

Thanks for all the help and the hints.