Professional Documents
Culture Documents
Subroutines and Interrupts: Sistemas Embebidos Oscar Acevedo, PHD
Subroutines and Interrupts: Sistemas Embebidos Oscar Acevedo, PHD
Subroutines and Interrupts: Sistemas Embebidos Oscar Acevedo, PHD
Sistemas Embebidos
Oscar Acevedo, PhD
Subroutines
int main( )
{
float m, n ;
printf ( "\nEnter some number for finding square \n");
scanf ( "%f", &m ) ;
n = square ( m ) ;
printf ( "\nSquare of the given number %f is %f",m,n );
}
;Delay subroutine
Delay: LDI R17, 0xFF
loop: DEC R17
BRNE loop
RET
Subroutine in µC
• During a subroutine call, the return address Program Counter (PC) is stored on the Stack
automatically by the µC
• If your subroutine shares register with the calling program, you must store them in the
Stack before the subroutine starts and recover them when the subroutine ends
• C does this for you automatically
Interrupts
• During interrupts, the return address Program Counter (PC) is stored on the Stack
• The Global interrupt bit is cleared by hardware after an interrupt has occurred, and is set
by the return instruction to enable subsequent interrupts
• To avoid interrupt over interrupt calls
• All interrupts have a separate Interrupt Vector in the Interrupt Vector table. The interrupts
have priority in accordance with their Interrupt Vector position
• The lower the Interrupt Vector address, the higher the priority
Interrupt Vector Table ATMega328
Interrupt Response Time
• The interrupt execution response for all the enabled AVR interrupts is four clock cycles
minimum.
• The Program Counter is pushed onto the Stack
• Jump to the interrupt routine, and this jump takes three clock cycles
• After four clock cycles the program vector address for the actual interrupt handling
routine is executed
Interrupt Response Time