Search code examples
assemblyavratmega

what is wrong with interupt vector in assembly


why changetime not called? i want to do some operation when the rising edge of int0 be true. i set interupt and do allthing i think that the wrong are from the first lines from .org

.include "m32def.inc"
.ORG $00
RJMP define
.ORG $002
RJMP changetime
.ORG $40
.DB $0C,$0A,$21,$11
.ORG $100
.DB $FC,$60,$DA,$F2,$66,$B6,$BE,$E0,$FE,$F6
.ORG $200
.DB $FB,$F6,$F1,$E2,$C4

define:
LDI R20,246
LDI R24,$41
OUT GICR,R24
LDI R24,$40
OUT GICR,R16
SEI
LDI R24,$03
OUT MCUCR,R24
SBI DDRD,0
SBI DDRD,1
LDI R16,$04
OUT SPH,R16
LDI R16,$00
OUT SPL,R16

changetime:
LDI R20,$FF
CPI R21,5
BRNE dochangetime
LDI R21,0
RJMP exitchangetime
dochangetime:
LDI R31,$03
MOV R30,R21
LPM R20,Z
INC R21
LOPP:RJMP LOPP
exitchangetime:
RETI

but exactly never the pc go to changetime.


Solution

  • I think you are somehow confused about external interrupts. There is a good tutorial about external interrupts for 8 bit AVR microcontrollers:

    http://www.avr-tutorials.com/interrupts/The-AVR-8-Bits-Microcontrollers-External-Interrupts

    First of all, since I don't know what you want to do I will give some general ideas how to solve your problem. You have defined your external interrupt directive here:

    .ORG $002
    RJMP changetime
    

    This part says that an when an external interrupt happens (for $002 case it is external interrupt 0 ) jump to changetime. So to interrupt we should enable the bit 2 of PORTD. The External Interrupt 0 can be activated by the external pin INT0 if the SREG I-flag and the corresponding interrupt mask are set. So if you want to change time externally you should enable the corresponding PIN.