user28706: 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 <avr/io.h> //Defines pins, ports, etc.
#include <util/delay.h>

int main(void)
{

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

    while(1){

        PORTB |= ~(1<<PORTB1);
        _delay_ms(100);
        PORTB |= (1<<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 <avr/io.h> //Defines pins, ports, etc.
#include <util/delay.h>

int main(void)
{

    DDRB |= (1<<DDD1);
    PORTB |= (1<<PORTB1);

    while(1){

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

    }

}


user23841: Your code doesn't clear anything.

    PORTB |= ~(1<<PORTB1); // set everything except PORTB1 pin
    _delay_ms(100);
    PORTB |= (1<<PORTB1);  // set PORTB1 pin

And recommended tutorial: Bit manipulation (AKA "Programming 101") from the AVRFreaks.net
BTW: next issue might be "the pulse is way too fast so it seems there is none"
Try this:
while(1) {
    PINB = _BV(PINB1); // toggle pin
    _delay_ms(50);
}


user24459: 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 &= ~(1<<PORTB1);
    _delay_ms(50);
    PORTB |= (1<<PORTB1);
    _delay_ms(50); // You need a delay here too.
}


28706: <p>I'm trying to make a 10Hz pulse wave output at Arduino's pin 9 by using the following code I wrote:</p>

<pre><code>#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);

    }

}
</code></pre>

<p>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?</p>

<p>Still doesnt work 
<strong>edit:</strong></p>

<pre><code>#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);

    }

}
</code></pre>
 23841: <p>Your code doesn't clear anything.
</p>

<pre><code>    PORTB |= ~(1&lt;&lt;PORTB1); // set everything except PORTB1 pin
    _delay_ms(100);
    PORTB |= (1&lt;&lt;PORTB1);  // set PORTB1 pin
</code></pre>

<p>And recommended tutorial: <a href="http://www.avrfreaks.net/forum/tut-c-bit-manipulation-aka-programming-101?page=all" rel="nofollow noreferrer">Bit manipulation (AKA "Programming 101")</a> from the AVRFreaks.net</p>

<p>BTW: next issue might be "the pulse is way too fast so it seems there is none"</p>

<p>Try this:</p>

<pre><code>while(1) {
    PINB = _BV(PINB1); // toggle pin
    _delay_ms(50);
}
</code></pre>
 24459: <p>You have your whole 100ms wait time while the pin is low.
You need half of it while low, half while high.</p>

<pre><code>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.
}
</code></pre>
