Problems creating 10Hz pulse wave I'm trying to make a 10Hz pulse wave output at Arduino's pin 9 by using the following code I wrote:

#define F_CPU 16000000UL
#include &lt;avr/io.h&gt; //Defines pins, ports, etc.
#include &lt;util/delay.h&gt;

int main(void)
{

    DDRB |= (1&lt;&lt;DDD1); //Does this set port B pin 1 and is this pin 9 in UNO board?
    PORTB |= (1&lt;&lt;PORTB1);

    while(1){

        PORTB |= ~(1&lt;&lt;PORTB1);
        _delay_ms(100);
        PORTB |= (1&lt;&lt;PORTB1);

    }

}


I use Atmel Studio to uplaad the code and it works fine with other codes. But for some reason this code doesn't work. What can be the problem here?

Still doesnt work 
edit:

#define F_CPU 16000000UL
#include &lt;avr/io.h&gt; //Defines pins, ports, etc.
#include &lt;util/delay.h&gt;

int main(void)
{

    DDRB |= (1&lt;&lt;DDD1);
    PORTB |= (1&lt;&lt;PORTB1);

    while(1){

        PORTB &amp;= ~(1&lt;&lt;PORTB1);
        _delay_ms(100);
        PORTB |= (1&lt;&lt;PORTB1);

    }

}
You have your whole 100ms wait time while the pin is low.
You need half of it while low, half while high.

while(1){

    PORTB &amp;= ~(1&lt;&lt;PORTB1);
    _delay_ms(50);
    PORTB |= (1&lt;&lt;PORTB1);
    _delay_ms(50); // You need a delay here too.
}