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

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

Re: [avr-gcc-list] Simple but wrong code


From: David Kelly
Subject: Re: [avr-gcc-list] Simple but wrong code
Date: Tue, 14 Jan 2014 13:03:33 -0600

On Jan 14, 2014, at 10:54 AM, dfx <address@hidden> wrote:

> Please consider this code:

[...]

> ISR(PCINT3_vect) { // FUNCTION KEY
>  uint8_t i;
> 
>  i = PORTD;
>  if ((i & FUNC_SEL_KEY) > 0) { // Test a key
>    LED_PORT |= (1 << PORTB0);
>    _delay_ms(100);
>    LED_PORT &= ~(1 << PORTB0);
>    _delay_ms(300);
>  }
>  reti();
> }

Why do you reti()? Use of ISR() should handle that for you. Plus your premature 
reti() prevents stack cleanup. Disassembly of an example I threw together:

/
//      Used to wake from sleep
//
ISR(INT0_vect)                  //      switch moved into "SET" position
{
 5fa:   1f 92           push    r1
 5fc:   0f 92           push    r0
 5fe:   0f b6           in      r0, 0x3f        ; 63
 600:   0f 92           push    r0
 602:   11 24           eor     r1, r1
        EIMSK = 0;                      //  disable once used
 604:   1d ba           out     0x1d, r1        ; 29
    reti();
 606:   18 95           reti
}
 608:   0f 90           pop     r0
 60a:   0f be           out     0x3f, r0        ; 63
 60c:   0f 90           pop     r0
 60e:   1f 90           pop     r1
 610:   18 95           reti


--
David Kelly N4HHE, address@hidden
============================================================
Whom computers would destroy, they must first drive mad.




reply via email to

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