Professional Documents
Culture Documents
Final Exam Topic 2 Example Questions
Final Exam Topic 2 Example Questions
Problem 1 : Write the C program using external interrupt ISR to scan INT0,INT and INT2 when INT-X is pressed, toggle The aprropriate
LED0,LED1and LED3 .
#include "avr/io.h"
#include "avr/interrupt.h"
//MCUCSR = (1<<ISC2); // make INT2 rising edge triggered, un-cmt to make INT2 rising edge, keep this to low level triggered
GICR = (1<<INT0)|(1<<INT1)|(1<<INT2);
}
Problem 2 : Convert the C Code in Problem 1 into Assembly Code
#include "m32def.inc"
.org 0x0000
rjmp main
.org 0x0002
rjmp EXT_INT0
.org 0x0004
rjmp EXT_INT1
.org 0x0006
rjmp EXT_INT2
main:
LDI R16,0xFF
OUT DDRD,R16
OUT MCUCR,R16
LDI R16,(1<<INT0)|(1<<INT1)|(1<<INT2) ;
While_1:
rjmp While_1
;---------------------------------------------------------------------------------------
EXT_INT0:
ldi R17,(1<<4)
IN R16,PORTD
EOR R17,R16
RETI
;---------------------------------------------------------------------------------------
EXT_INT1:
ldi R17,(1<<5)
IN R16,PORTD
EOR R17,R16
RETI
;---------------------------------------------------------------------------------------
EXT_INT2:
ldi R17,(1<<6)
IN R16,PORTD
EOR R17,R16
RETI
Advance questions : Compile Assembly Code in Problem 2 into AVR Binary Machine Code