-2
\$\begingroup\$

I tried the simplest code with a blinking LED, but it is not working.

I connected the LED to PB0 through a 1k resistor. The software (AVRDUDESS) is detecting the microcontroller (ATmega16) fine, but when I run the program, the code is not working. The LED stays OFF.

The MCU was working till recently, is it possible it's damaged even though the program recognizes it?

I checked the LED and it's not damaged, so don't see a reason why it wouldn't work.

The code:

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

int main(void)
{
    DDRB = 0xFF; 
    while(1) 
    {
        PORTB |= (1<<PB0); //TURN LED ON
        _delay_ms(1000); 
        PORTB &= ~(1<<PB0); //Turns OFF LED
        _delay_ms(1000); 
    }

enter image description here

\$\endgroup\$
2
  • \$\begingroup\$ Do you need to config the clock in the code? I'm not sure, though, maybe there are some pre-defined configurations in a bootloader-like config file. \$\endgroup\$ May 19 at 15:50
  • \$\begingroup\$ @VictorGrounds has it right. Please check here for more info. \$\endgroup\$
    – bitsmack
    May 19 at 15:55

2 Answers 2

4
\$\begingroup\$

Check your resistor and LED wiring. You'll see you have one side of the LED connected straight to the microcontroller as well as both ends of the resistor. The picture heavy Arduino tutorials have many examples of series wiring of LED's on a bread board. That should clear up your mistake.

\$\endgroup\$
1
  • \$\begingroup\$ Nice catch Victor! :) \$\endgroup\$
    – bitsmack
    May 19 at 15:54
1
\$\begingroup\$

Disconnect LED and pull your pin up by a 10k ohm external resistor, measure the pin voltage when its 0 and 1.

A damaged Pin may be always 0 with no pullup resistor and makes true value with pullup resistor. Connect cathode to the pin while anode is connected to VCC series with a resistor and check again. If LED is turned on when its Low then PMOS may have been damaged.

\$\endgroup\$

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.