Atmega8535 INT0 INT1 INT2 INT3

时间:2013-04-18 10:23:41

标签: assembly external avr interrupt atmega

我正在使用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

1 个答案:

答案 0 :(得分:0)

你可能会对这个处理器要求太多。根据{{​​3}}(第65页),该处理器只有3个外部中断INT0,INT1和INT2(分别在PORTD.2,PORTD.3和PORTB.2上)...也值得阅读pg 68ff!< / p>

我没有看到你最初设置全局中断允许位(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