avr-chat
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-chat] Endless loop in AVR?


From: Bob Paddock
Subject: Re: [avr-chat] Endless loop in AVR?
Date: Sat, 28 Jul 2007 06:05:40 -0400
User-agent: KMail/1.9.5

On Saturday 28 July 2007 04:04, Wojtek Dabrowski wrote:

> ...the diodes light up when I press the reset button, but
> as soon as I let go, they go off again.

If the LEDs are lighting up *while* you have RESET asserted,
then you have a hardware problem.  PORTD will be in a high impedance
state so there should be no current flow to permit them to light up.
How do you have the LEDs connected?

> It can't be the optimization - I've compiled it with -O0, and the same
> thing still happens.

> int main(void) {
>   DDRD = 0xff;
>   PORTD = 0xff;
> 
>   while(1) {
>   }
> 
>   return(0);
> }

Place a NOP inside the while(1){}.  Sometimes the compiler is 'helpful'
and optimizes away that it thinks you don't need.  I don't think
that is the case here, as you tried -O0.

#define NOP() do { __asm__ __volatile__ ("nop"); } while (0)

My preference for a infinite loop is this style:

 for(;;)
 {
   NOP();
 }

That avoids a Lint warning of "evaluating a constant boolean",
and gives the compiler a NOP to much on to keep it from
removing the loop.


-- 
                http://www.wearablesmartsensors.com/
 http://www.softwaresafety.net/ http://www.designer-iii.com/
                 http://www.unusualresearch.com/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]