Generating 40 kHz square wave using ATtiny13
I often use the ATtiny13 for little one-off projects that blink LEDs or control timing of external switches (theatrical props). Sometimes I just need them to change an IO pin at a given frequency and literally nothing else. The following is a quick and dirty way to toggle a GPIO using a delay.

Note: this is not a timing-accurate nor recommended way to accomplish this in an efficient manner. Using a timer and PWM allows you to continue executing other code while the signal is generated.

#define F_CPU 1200000

#include &lt;avr/io.h&gt;
#include &lt;util/delay.h&gt;

int main(void)
{
    // Set PB3 and PB4 as output
    DDRB |= (1 &lt;&lt; DDB3) | (1 &lt;&lt; DDB4);
    // Start PB4 high
    PORTB |= (1 &lt;&lt; PORTB4);

    while (1) 
    {
        // Toggle PB3 and PB4
        PORTB ^= (1 &lt;&lt; PORTB3) | (1 &lt;&lt; PORTB4);
        // 40kHz period is 25µs
        _delay_us(25);
    }
}


Toggling pins isn't a single clock-cycle, and the util/delay function is not accurate, so delaying for 25 microseconds is a naive approach, but if your requirements are not strict, it may suit your purpose. Adjust the delay value if needed.