Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: [avr] Re: [AVR-Chat] Re: mega 168

2005-08-23 by Don Jackson

Dennis wrote:
> Not that I disagree with you, however, look at the RETI for th 8051. Also, 
> check out the RET and RETI instruction explanantion is the instruction set 
> manual. Both of the latter use the same stack operation implying they 
> function the same. RET returns to the instruction following the CALL, RETI 
> does not.
> 
> I've changed my code to accomodate the RETI. Doesn't make much sense to have 
> infinite loops.
> 
> RETI (80C51 Instruction Set)
> 
> Function: Return from interrupt
> 
> Description: RETI pops the high- and low-order bytes of the PC successively 
> from the stack and restores the interrupt logic to
> 
> accept additional interrupts at the same priority level as the one just 
> processed. The Stack Pointer is left
> 
> decremented by two. No other registers are affected; the PSW is not 
> automatically restored to its pre-interrupt
> 
> status. Program execution continues at the resulting address, which is 
> generally the instruction immediately after
> 
> the point at which the interrupt request was detected. If a lower- or 
> same-level interrupt was pending when the
> 
> RETI instruction is executed, that one instruction is executed before the 
> pending interrupt is processed.

Excuse me for the intrusion, but aren't we discussing the Atmel
ATMega168 rather than an 80C51?

Even then, note in the above for the '51 that it says "Program execution
continues at the resulting address, whis is generally the instruction
immediately after the point at which the interrupt request was detected."

This is also true for the AVR and every other micro I have seen ... but
the key word is "generally".  GENERALLY this means that the micro is
executing sequential inline code and the statement is then true.

Use a simulator or other tool and watch what happens when you step thru
the code.  You should be able to see what return address is pushed onto
the stack in an infinite loop situation (jump to yourself).

In many micros (not all!) the only difference between a RET and RETI
instruction is the treatment of the interrupt flag(s).  An interrupt
will not get you out of an infinite loop unless you somehow alter the
return address on the stack.

Don

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.