avr-gcc-list
[Top][All Lists]
Advanced

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

Re: [avr-gcc-list] Compile problem


From: Dave Hansen
Subject: Re: [avr-gcc-list] Compile problem
Date: Fri, 07 Oct 2005 16:41:14 -0400

From: Patrick Blanchard <address@hidden>

On Fri, 2005-10-07 at 08:24 -0700, Razvan Turiac wrote:
> I think I have a compile problem. I am using WinAVR
> 20050214 and I've got one problem when compiling some
> code.

OK, but you need to show us the compiler errors received...

You have to scan the attachments. It probably would have been better for the OP to simply include the code in-line with his message.

From what I see, there were no error messages, but it appears the compiler
generated incorrect code.


also, avr/io.h header does not define wait(), nor does avr/delay.h

It was his function, in the attached (to his message) C file.


> The assembler code is all wrong.

how?

It appears the TIFR register is not "acting" volatile. Perhaps it's incorrectly declared in the header?

The wait function is:
---
void wait(unsigned char time)
{
        TCCR0 = 0x02;                           //set prescaler to 2

        while(time--)                                   //wait time * 100us 
increments @ XTAL = 16MHz
        {
                TCNT0 = 56;
                TIFR |= (1 << TOV0);

                while(!(TIFR & TOV0));

        }

}
---
Note: the "TIFR |= (1 << TOV0);" should more properly be "TIFR = (1 << TOV0);" due to the way TIFR works. But I digress.

The generated code is:
---
wait:
.LFB3:
.LM1:
/* prologue: frame size=0 */
/* prologue end (size=0) */
.LM2:
        ldi r25,lo8(2)
        out 83-0x20,r25
.LM3:
        tst r24
        breq .L9
.LM4:
        ldi r24,lo8(56)
        out 82-0x20,r24
.LM5:
        in r24,88-0x20
        ori r24,lo8(1)
        out 88-0x20,r24
.L4:
.LM6:
        in r24,88-0x20
        rjmp .L4
.L9:
        ret
---
Note the inner loop is optimized out, apparently on the assumption that the low bit in TIFR has just been set, so it remains set.

Regards,
  -=Dave






reply via email to

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