led on program / led blink program

Thread Starter

zak9000

Joined Jan 1, 2012
20
hi

i am new to embedded programming and am currently using a stk500 with a atmega32 mcu. i recently was able to program a simple led blink program which turns on and off all the leds connected to port b of the mcu as shown below:

#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
DDRB=0xFF;
while(1)
{

PORTB=0xFF;
_delay_ms(100);
PORTB=0x00;
_delay_ms(100);
}
}

this code works fine but then i want to just turn on the led and so i tried

#include <avr/io.h>

int main(void)
{
DDRB=0xFF;
PORTB=0xFF;
while(1)
{

}


}

after programming my mcu i expected all leds to light up but none of them lighted up, maybe im missing something?
 

Thread Starter

zak9000

Joined Jan 1, 2012
20
i did try adding the code in the while loop but the leds still do not turn on. however i have noticed that when i turn off my programming board and turn it back on with the mcu all the leds turn on a second before they are turned off.
 

spinnaker

Joined Oct 29, 2009
7,830
i did try adding the code in the while loop but the leds still do not turn on. however i have noticed that when i turn off my programming board and turn it back on with the mcu all the leds turn on a second before they are turned off.
That means very little.

If you have the blinking code working, try commenting out the code that turns the lights off.

Also you normally set latches and read ports. You might want to check that.
 

spinnaker

Joined Oct 29, 2009
7,830
PORTB=0xFF; //set all pins on port b to high
PORTB=0x00; // set all pins on port b to low
Yes that is obvious. but depending on the configuration of your LEDs, you can turn them on with a high or a low. Both cathode or anode can be tied to a pin. Cathode can be tied to one pin and anode tied to another.

Have you used a scope, logic probe or voltmeter to see if they are actually changing state?
 

ErnieM

Joined Apr 24, 2011
8,377
i did try adding the code in the while loop but the leds still do not turn on. however i have noticed that when i turn off my programming board and turn it back on with the mcu all the leds turn on a second before they are turned off.
That may be very significant. Just what does turn the LEDs on? Is it a high or a low on the I/O pins? I have no idea without a schematic.

What happens if you change this to:

PORTB=0x00;

inside the always on program?
 

Thread Starter

zak9000

Joined Jan 1, 2012
20
Yes that is obvious. but depending on the configuration of your LEDs, you can turn them on with a high or a low. Both cathode or anode can be tied to a pin. Cathode can be tied to one pin and anode tied to another.

yes you were right by simply changing portb=0x00 it sovled the problem thanks!!!
 

spinnaker

Joined Oct 29, 2009
7,830
Yes that is obvious. but depending on the configuration of your LEDs, you can turn them on with a high or a low. Both cathode or anode can be tied to a pin. Cathode can be tied to one pin and anode tied to another.

yes you were right by simply changing portb=0x00 it sovled the problem thanks!!!

Had you posted your schematic in the message at the top of the thread this would have been solved in the first answer.
 

tshuck

Joined Oct 18, 2012
3,534
umm.......

*Who the heck are you!?*


*Note: this was in reference to a post that was removed....
 
Last edited:

tshuck

Joined Oct 18, 2012
3,534
Wow, his post even got removed...well, he probably did it himself.... now I need to edit my post so i don't look too crazy:)
 
Top