I'm new in microcontrollers and I wrote simple program that set HIGH state at PB0 and PB1.

#include <avr/io.h>
#include <util/delay.h>

#define F_CPU 8000000L

int main(void){
    DDRB |= (1<<PB0) | (1<<PB1);
    PORTB |= (1<<PB1);
    PORTB |= (1<<PB0);


The problem is that my avr can't hold on HIGH state and connected leds are blinking. Where is the problem ?

  • 1
    \$\begingroup\$ What does your circuit look like? How do you know the MCU isn't just constantly resetting? How are the LEDs connected, and are you sure they aren't blinking LEDs? \$\endgroup\$ May 24, 2017 at 22:24
  • 2
    \$\begingroup\$ Can you describe how the LEDs blink? Do you have a scope and can you probe the power and LED pins? Oh, and please add a schematic. \$\endgroup\$
    – uint128_t
    May 25, 2017 at 1:09

1 Answer 1


Which ATmega exactly? What is your fuse configuration?

You can try calling wdt_disable() at the beginning (it is defined in <avr/wdt.h>), as the watchdog can be enabled for example by previous firmware (watchdog is not disabled after a reset) or can be by always enabled at reset.

There is also a fuse setting that does not allow disabling of the watchdog - you have to call wdt_reset() somewhere in the main loop.

  • \$\begingroup\$ This is Atmega8. I didn't set any fuse bits. \$\endgroup\$
    – mattsky
    May 24, 2017 at 21:34
  • \$\begingroup\$ which atmega8 specifically? come on, try to be as verbose as possible if asked for details; make sure the fuses are what you expect them to be. \$\endgroup\$ May 24, 2017 at 21:58
  • \$\begingroup\$ @MarcusMüller ATMega8 is a specific Atmel part. \$\endgroup\$ May 24, 2017 at 22:06
  • \$\begingroup\$ @TomCarpenter my understanding was that fuses were specific to case variant, but it seems I was mistaken. My apologies, Mattsky! \$\endgroup\$ May 24, 2017 at 22:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.