Newbie Question- LED Blink ATTiny85

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm a newbie. I can get this code to light up an led but it turns on for a fraction of a second but not stay on. Why will the LED not stay on? Seems like it blowing right past the while loop. I'm using an ATTiny85 on a STK500 board using AVRStudio 4.19.

#include 
int main(void)
{
    DDRB = 0b00000001; 
    PORTB = 0b00000001;
      while(1)
        {
        }
}
Last Edited: Mon. Apr 2, 2012 - 04:28 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Always highlight your code and hit the "code" button ( whoch you can still go back and edit to your OP ) .
Maybe it needs a small delay between those 2 instructions ... ?

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I'm using an ATTiny85 on a STK500 board

STK500 LEDs are active low (they turn on when you write a 0 to the PORT and off when you write 1). Do you have a full 10 way header from the PORTB header to the LEDs or just a single wire for PORTB.0 ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks. Ok--> 0= On. 1 = Off. I'll give it a shot tonight. (Is that due to PNP/NPN transistor noted in the circuitry?)

I have the full 10 Way header as included with the STK500 Kit from PortB to LED Header.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

(Is that due to PNP/NPN transistor noted in the circuitry?)

Indirectly - it's to do with the circuitry having level conversion so it can work whether the MCU is running at 5 or 3.3V or whatever.
Quote:
I have the full 10 Way header as included with the STK500 Kit from PortB to LED Header.

In that case the other 7 LEDs should have been working in the opposite sense to the one you were trying to light.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
In that case the other 7 LEDs should have been working in the opposite sense to the one you were trying to light.
They could have if not the other pins were defined to be inputs.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

They could have if not the other pins were defined to be inputs.

Oh well spotted. I knew there was a reason I just always:

PORTB = 0xFF;

on an STK500 even if only planning to drive 1 or 2 LEDs. ;-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Oh well spotted. I knew there was a reason I just always:
Code:
PORTB = 0xFF;

on an STK500 even if only planning to drive 1 or 2 LEDs

That's what time do to us.
The conscious decisions made early in life to avoid painful mistakes eventually gets so deeply ingrained in our brain cells that we just act on reflex.
Works most of the time... :wink:

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for your clarifications.

Here is a really dumb question-- if 0b1111 1111 is all bits are on (or off), why do you say 0xFF and not 0xEE. Isn't 1111 = 15 = E (8 + 4 + 2 + 1= 15)

(I am new to actually getting into the weeds with binary/hex and not just doing it as lessons in intro to programming classes)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Isn't 1111 = 15 = E (8 + 4 + 2 + 1= 15)

Umm...

 0 = 0 = 0000
 1 = 1 = 0001
 2 = 2 = 0010
 3 = 3 = 0011
 4 = 4 = 0100
 5 = 5 = 0101
 6 = 6 = 0110
 7 = 7 = 0111
 8 = 8 = 1000
 9 = 9 = 1001
10 = A = 1010
11 = B = 1011
12 = C = 1100
13 = D = 1101
14 = E = 1110
15 = F = 1111

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

oops. user error. Thanks. (I feel really dumb for not being able to count on my fingers).