LED flasher

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

Okay I am using an ATmega32 with the AVR Dragon

I am trying to make An LED FLash, here is the code I am trying to use!!

#include 

typedef unsigned long u32;

void Delay(u32 count);


int main(void)
{	
	DDRB = 0xFF;
	PORTB = 0x00;
	while(1)
	{
		PORTB = ~PORTB; 
		Delay(20000);				
		PORTB = ~PORTB; 
		Delay(20000);		
	}
}


void Delay(u32 count)
{		
	while(count--);
}

K now the problem is when I download the program Via the JTAG interface the Led on Port B turns on and stays on, so I tried to debug my code, when i put it on to autostep it worked just fine the led would blink but when I put it into run the led goes dim and it says in the message window,

AVR dragon: Target has entered sleep mode.
AVR Dragon: Target has left sleep mode.

And it keeps repeating those to lines untill Pause the debugging

Please help

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

The compiler likely has optimized your delay function away. Use one of the delay functions from the avr-libc.

Stealing Proteus doesn't make you an engineer.

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

So maybe try something like:

#ifndef F_CPU
// edit the following number to be your CPU frequency
#define F_CPU 1000000UL
#endif
#include  
#include 

int main(void) 
{    
   DDRB = 0xFF; 
   PORTB = 0x00; // unecessary - it is the default
   while(1) 
   { 
      PORTB = ~PORTB; 
      _delay_ms(500);             
   } 
}

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

and set compiler optimization to -s

KISS - Keep It Simple Stupid!

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

Just a thought, but you say the LED goes dim. What clock speed are you running? Is the pulsing happening so quick that you cant see it?
At 8Mhz 20000 instructions is only 2.5mS

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

It is running fine now with clawsons code..thanks for all the help

It was running at 1Mhz