assembly - How external interrupts are recognized in AVR Atmega16? -
i'm working on assembly program turn led on/off each time pressing button(creating external interrupt). can't understand how external interrupts wake device or how impact program counter change current running code , going interrupt service routine. wrote below code , i'm using bootrst=0 , ivsel=0 options in code. guess have missed 2 things , don't know how implement them: 1. setup clock option: falling or rising edge 2. implementation of interrupt service routine(handle_sw1). need wait external interrupt in (start - jmp start) section , check pinb every time see wether it's 0 or 1, or microcontroller handle external interrupts it's own , route them directly handle_sw1 ?
; reserved 2 bytes: jump reset @ beginnning .org 0x00 jmp reset_isr ; configuration: put interrupt 1 vector @ address $002 .org 0x02 jmp handle_sw1 handle_sw1: ; turn on led here, set pd7 output led ldi r16,(1 << pd7) out ddrd,r16 out portd,r16 ; control data output, keep led on untill key-press interrupt comes in ; skip if previous status of led on sbis portd,7 ret ; create delay call short_delay ; otherwise turn off led ldi r16,(0 << pd7) out portd,r16 ; enable global interrupt flag sei ret .org $1c00 reset_isr: ; set stack pointer top of ram ldi r16,high(ramend) out sph,r16 ldi r16,low(ramend) out spl,r16 ; enable int1 ldi r16, (1 << int1) out gicr, r16 ; configuration: ivsel = 0, bootrst = 0 ; make sure ivsel set 0 ldi r16,(0 << ivce) out gicr,r16 ldi r16,(0 << ivsel) out gicr,r16 ; enable global interrupt flag sei start: ; enable input direction pd3 ldi r16,(0 << pd3) out ddrd,r16 rjmp start ; short delay synchronization between press , reaction short_delay: ldi r25,5 loop: dec r25 brne loop ret
Comments
Post a Comment