AVR中打开中断但没有相应的中断服务函数,会引起芯片重启,通过分析编译产生的汇编代码可以清楚的理解问题所在。
编译器使用 Atmel Atudio7.0
芯片:ATmega128A
由于没有找到产生汇编代码的方法,因此使用ReAVR进行反汇编。
以下为有ISR的情况
C语言
#include
#include "avr/interrupt.h"
void initTimer3();
int main(void)
{
initTimer3();
sei();
while(1)
{
}//while(1)
}
void initTimer3()
{
TCNT3=0x0000;
TCCR3B=0x01;
OCR3A=14745;
ETIMSK=0x10;
}
ISR(TIMER3_COMPA_vect)
{
TCNT3=0x0000;
}
汇编
; reassembly of "Electronic Counter.hex"
; created by ReAVR V3.5.0
; at 2016/02/28 - 16:42:14
; for Atmel AVR assembler
;---------------------------------------
; AVR_TYPE=
; FLASH_SIZE=8KB
; SRAM_START=0x60
;---------------------------------------
.cseg
.org 0x0000
;---------------------------------------
; byte constants:
;
.equ k01 = 0x01 ;
.equ k10 = 0x10 ;
.equ k39 = 0x39 ; '9'
.equ k99 = 0x99 ;
.equ kFF = 0xFF ; '˙'
;
; io register addresses:
;
.equ p3D = 0x3D
.equ p3E = 0x3E
.equ p3F = 0x3F
;
; bit numbers:
;
.equ b0 = 0x00
.equ b1 = 0x01
.equ b2 = 0x02
.equ b3 = 0x03
.equ b4 = 0x04
.equ b5 = 0x05
.equ b6 = 0x06
.equ b7 = 0x07
;---------------------------------------
;
L0000:
jmp _reset ; L0046
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0067 //向量号27 TIMER3_COMPA
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
;
_reset:
; L0046:
clr r1
out p3F,r1
ldi r28,kFF
ldi r29,k10
out p3E,r29
out p3D,r28
call L0063
jmp L0075
; ----------- jump on last line
L0050: //默认中断服务函数,相当于触发reset中断
jmp L0000
; ----------- jump on last line
L0052:
sts D0089,r1
sts D0088,r1
ldi r24,k01
sts D008A,r24
ldi r24,k99
ldi r25,k39
sts D0087,r25
sts D0086,r24
ldi r24,k10
sts D007D,r24
ret
;----------------------*
; pc=0x63(0xC6)
;
L0063:
call L0052
sei
L0066:
rjmp L0066
; ----------- jump on last line
; pc=0x67(0xCE)
;
L0067: //TIMER3_COMPA中断服务函数,正常
push r1
push r0
in r0,p3F
push r0
clr r1
sts D0089,r1
sts D0088,r1
pop r0
out p3F,r0
pop r0
pop r1
reti
;----------------------*
; pc=0x75(0xEA)
;
L0075:
cli
L0076:
rjmp L0076
; ----------- jump on last line
; pc=0x77(0xEE)
;
; last flash byte address = 0x00ED
; last flash word address = 0x0076
;---------------------------------------
.dseg
.org 0x007D
;
D007D:
.byte 9
D0086:
.byte 1
D0087:
.byte 1
D0088:
.byte 1
D0089:
.byte 1
D008A:
;
; last lds/sts data byte at 0x008A
;---------------------------------------
;
无ISR的汇编代码
; reassembly of "Electronic Counter.hex"
; created by ReAVR V3.5.0
; at 2016/02/28 - 16:40:21
; for Atmel AVR assembler
;---------------------------------------
; AVR_TYPE=
; FLASH_SIZE=8KB
; SRAM_START=0x60
;---------------------------------------
.cseg
.org 0x0000
;---------------------------------------
; byte constants:
;
.equ k01 = 0x01 ;
.equ k10 = 0x10 ;
.equ k39 = 0x39 ; '9'
.equ k99 = 0x99 ;
.equ kFF = 0xFF ; '˙'
;
; io register addresses:
;
.equ p3D = 0x3D
.equ p3E = 0x3E
.equ p3F = 0x3F
;
; bit numbers:
;
.equ b0 = 0x00
.equ b1 = 0x01
.equ b2 = 0x02
.equ b3 = 0x03
.equ b4 = 0x04
.equ b5 = 0x05
.equ b6 = 0x06
.equ b7 = 0x07
;---------------------------------------
;
L0000:
jmp _reset ; L0046
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050 //向量号27 TIMER3_COMPA
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
jmp L0050
; ----------- jump on last line
;
_reset:
; L0046:
clr r1
out p3F,r1
ldi r28,kFF
ldi r29,k10
out p3E,r29
out p3D,r28
call L0063
jmp L0067
; ----------- jump on last line
L0050: //默认中断服务函数,相当于触发reset中断
jmp L0000
; ----------- jump on last line
L0052:
sts D0089,r1
sts D0088,r1
ldi r24,k01
sts D008A,r24
ldi r24,k99
ldi r25,k39
sts D0087,r25
sts D0086,r24
ldi r24,k10
sts D007D,r24
ret
;----------------------*
; pc=0x63(0xC6)
;
L0063:
call L0052
sei
L0066:
rjmp L0066
; ----------- jump on last line
; pc=0x67(0xCE)
;
L0067:
cli
L0068:
rjmp L0068
; ----------- jump on last line
; pc=0x69(0xD2)
;
; last flash byte address = 0x00D1
; last flash word address = 0x0068
;---------------------------------------
.dseg
.org 0x007D
;
D007D:
.byte 9
D0086:
.byte 1
D0087:
.byte 1
D0088:
.byte 1
D0089:
.byte 1
D008A:
;
; last lds/sts data byte at 0x008A
;---------------------------------------
;
上一篇:Atmage16中断学习—外部中断
下一篇:在ATmega8中真实可用的ADC转换器写法
推荐阅读最新更新时间:2024-03-16 16:08