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

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

Re: [avr-gcc-list] Setting pin to high in function instead of main, inst


From: Peter Fuhrmann
Subject: Re: [avr-gcc-list] Setting pin to high in function instead of main, instructions in main never run?
Date: Thu, 01 Mar 2012 14:15:33 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.8) Gecko/20100802 Thunderbird/3.1.2


=== // Bare minimum start (faulty behavior) ===

#include<avr/io.h>

void turn_on_pb(void);

int main(void)
{
        DDRB |= (1<<  PB0);
        turn_on_pb();

        for (;;) {

        }

        return 0;
}

void turn_on_pb(void)
{
        PORTB |= (1<<  PB0);
}

--- --- Disassembly start --- ---

00000000<turn_on_pb>:
        return 0;
}

void turn_on_pb(void)
{
        PORTB |= (1<<  PB0);
    0:  28 9a           sbi     0x05, 0 ; 5
}
    2:  08 95           ret

00000004<main>:

void turn_on_pb(void);

int main(void)
{
        DDRB |= (1<<  PB0);
    4:  20 9a           sbi     0x04, 0 ; 4
        turn_on_pb();
    6:  0e 94 00 00     call    0       ; 0x0<turn_on_pb>
    a:  00 c0           rjmp    .+0             ; 0xc<main+0x8>

--- --- Disassembly end --- ---

=== \\ Bare minimum end ===


The assembly looks correct. This should work. Maybe the RAM of your AVR is faulty so function return doesn't work, or the powersupply is unstable. I think this is most likely to be a hardware problem. Another possibilitty ist that the Stack Pointer isn't set up properly in the startup code, so the function can not return.

Could you try another chip or another Board ?

Best Regards,
Peter



reply via email to

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