Blink LED program puzzle - Solved

  1. I compiled blink program.
  2. Uploaded to ATTINY45
  3. Powered ATTINY in standalone mode and attached LED.
    LED blinks OK.
    4 Switched two lines of code placing PORTB 0x00 in place of PORTB 0x10.
    and PORTB 0x010 in place of PORTB 0x00. Compiled and uploaded.
    LED does not blink.
  4. Repeated procedure two more times with the same result.

Can anyone explain why the LED stopped blinking?

============LED blinks===========
#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>

int main(void)
{ DDRB=0x10;
while(1)
{
PORTB = 0x10;
_delay_ms(500);
PORTB=0x00;
_delay_ms(2000);
}
}

========LED does not blink=========
#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>

int main(void)
{ DDRB=0x10;
while(1)
{
PORTB=0x00;
_delay_ms(500);
PORTB = 0x10;
_delay_ms(2000);
}
}

After 29 posts to this Forum, we expect you to have read and start following the rules for posting as detailed in the first two stickies at the start of this Forum. Reading those and following what's contained therein will help you get responses from the rest of us.

What @econjack said ...

x50505: 4 Switched two lines of code placing PORTB 0x00 in place of PORTB 0x10. and PORTB 0x010 in place of PORTB 0x00. Compiled and uploaded. LED does not blink.

Can anyone explain why the LED stopped blinking?

It would save us a lot of time if you explain why they should continue blinking?

In other words, why did you make the change to the code and what is it supposed to accomplish?

...R

Robin2:

  1. Just for the record, I described my skill level as “newbie”. It seems to me that

while(1) { //code } creates an endless loop. So the LED should be blinking.

  1. What I am trying to accomplish? Trying to learn how to program a microcontroller. I first used ATMEL328 and programmed it to blink an LED. Then I tried to accomplish the same using ATTINY45. It worked. Then just for the heck of it I switched the lines of code as shown above expecting ATTINY connected LED to blink. I uploaded the second code and this time the LED stopped working. So I want to find out why this happened. As thought about what went wrong, I got some idea of why that might have happened and will check it tomorrow.

Frankly, I expected someone who has programmed ATTINY45 to tell me a) that the second program should work as written or b) tell me what I have done wrong.