0

我正在使用 Atmega8535 微控制器和 STK200 开发板,我试图使用多个外部中断,但由于某种原因,只有 INT0 工作,其他人什么都不做,这里是相关代码:

;Interrupt Vector Addresses 
.equ     INT0addr=$001            ;External Interrupt0 Vector Address 
.equ     INT1addr=$002
.equ     INT2addr=$003
.equ     INT3addr=$004
.equ     INT4addr=$005

//interrupts
.org     INT0addr 
         rjmp   INT0              ;External Interrupt0 Vector 
.org     $0015                    ;Program address 

.org     INT1addr 
         rjmp   INT1              ;External Interrupt1 Vector 
.org     $0015                    ;Program address

.org     INT2addr 
         rjmp   INT2              ;External Interrupt0 Vector 
.org     $0017

.org     INT3addr 
         rjmp   INT3              ;External Interrupt0 Vector 
.org     $0018

.org     INT4addr 
         rjmp   INT4              ;External Interrupt0 Vector 
.org     $0019
;External Interrupt0 Service Routine 
INT0:    cli                      ;Prevent any more interrupts while ISR is running

     rjmp reset 
     reti                     ;Return and enable interrupts again

;External Interrupt1 Service Routine 
INT1:    cli                      ;Prevent any more interrupts while ISR is running

         rjmp reset 
         reti                     ;Return and enable interrupts again
;External Interrupt1 Service Routine 
INT2:    cli                      ;Prevent any more interrupts while ISR is running

         rjmp reset 
         reti                     ;Return and enable interrupts again
;External Interrupt1 Service Routine 
INT3:    cli                      ;Prevent any more interrupts while ISR is running

         rjmp reset 
         reti                     ;Return and enable interrupts again
;External Interrupt1 Service Routine 
INT4:    cli                      ;Prevent any more interrupts while ISR is running

         rjmp reset 
         reti                     ;Return and enable interrupts again
4

1 回答 1

0

你可能对这个处理器要求太多了。根据处理器参考资料(第 65 页),该处理器只有 3 个外部中断 INT0、INT1 和 INT2(分别在 PORTD.2、PORTD.3 和 PORTB.2 上)……也值得一读 pg 68ff!

我没有看到您最初设置了全局中断启用位(SREG 的第 7 位),该位在复位后为 0 并防止处理任何中断,并且必须启用各个中断(寄存器 GICR)

您的代码中有很多多余.org的部分(例如第 11、13 行)。

我建议您包含设备特定的 inc 文件,并且 - 为了清楚起见 - 指定完整的中断向量表,例如

.nolist
.include <m8535def.inc>
.list

.org 0x0000
                     ; .... highest priority
    jmp V_RESET      ; Reset
    jmp V_ExtINT0    ; External Interrupt 0
    jmp V_ExtINT1    ; External Interrupt 1
    jmp V_NOINT      ; Timer/Counter2 Compare Match
    jmp V_NOINT      ; Timer/Counter2 Overflow
    jmp V_NOINT      ; Timer/Counter1 Capture Event
    jmp V_NOINT      ; Timer/Counter1 Compare Match A
    jmp V_NOINT      ; Timer/Counter1 Compare Match B
    jmp V_NOINT      ; Timer/Counter1 Overflow
    jmp V_NOINT      ; Timer/Counter0 Overflow
    jmp V_NOINT      ; SPI Serial Transfer Complete
    jmp V_NOINT      ; USART, RX Complete
    jmp V_NOINT      ; USART Data Register Empty
    jmp V_NOINT      ; USART, TX Complete
    jmp V_NOINT      ; ADC Conversion Complete
    jmp V_NOINT      ; EEPROM Ready
    jmp V_NOINT      ; Analog Comparator
    jmp V_NOINT      ; Two-wire Serial Interface
    jmp V_ExtINT2    ; External Interrupt Request 2
    jmp V_NOINT      ; TimerCounter0 Compare Match
    jmp V_NOINT      ; Store Program Memory Read
                     ; .... lowest priority

V_RESET:
    ; define stack pointer
    ; set individual interrupt bits
    ; initialize ports, etc.

    sei              ; enable general interrupts

MAIN:
    rjmp MAIN

V_ExtINT0:
    ; INT0 handler
    reti

V_ExtINT1:
    ; INT1 handler
    reti

V_ExtINT2:
    ; INT2 handler
    reti

V_NOINT:
    ; e.g. flash a LED otherwise unused to show abnormal condition
    reti
于 2013-04-25T09:46:34.950 回答