Basic AVR flashing LED program is not working

avrledprogramming

So I have begun with projects using AVR microcontrollers. A few months ago, I got one of these to simply flash an LED but I accidentally cooked that one with a bad power supply. Now I got some new ones and I believe that I'm doing the same thing before but the LED isn't flashing!

This is my current code:

#define F_CPU 20000000UL
#include <avr/io.h>
#include <util/delay.h>

int main(void){

    DDRB |= 1<<PB0;
    while(1){
        PORTB &= -(1<<PB0);
        _delay_ms(1000);
        PORTB |= 1<<PB0;
        _delay_ms(1000);
    }
    return 0;
}

I'm able to successfully program the device but when I test it, nothing happens. The device is an ATmega168A. This is my current pin connections:

Pin 1(Reset): 5V

Pin 7(Vcc): 5V

Pin 8(GND): GND

Pin 14(B0): LED OUT

Pin 20(AVCC): 5V

Pin 22(GND): GND

Is there something obvious that I'm just missing?

Best Answer

PORTB &= -(1<<PB0); should be PORTB &= ~(1<<PB0);.

~(1<<PB0) is 0xFE, which turns off bit 0. -(1<<PB0) is 0xFF, which works out to a no-op, so the pin is never getting turned off.