AVR中断引起重启

单片机 专栏收录该内容
1 篇文章 0 订阅

AVR中打开中断但没有相应的中断服务函数,会引起芯片重启,通过分析编译产生的汇编代码可以清楚的理解问题所在。

编译器使用 Atmel Atudio7.0

芯片:ATmega128A

由于没有找到产生汇编代码的方法,因此使用ReAVR进行反汇编。

以下为有ISR的情况

C语言

#include <avr/io.h>
#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=<unknown>
; 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
<span style="color:#ff0000;">	jmp	L0067   //向量号27 TIMER3_COMPA</span>
;	-----------	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
<span style="color:#ff0000;">L0050:  //默认中断服务函数,相当于触发reset中断
	jmp	L0000</span>
;	-----------	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)
;
<span style="color:#ff0000;">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</span>
;----------------------*
; 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
;---------------------------------------
;<eof>



无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=<unknown>
; 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
;---------------------------------------
;<eof>






工具下载:AVR反汇编ReAVR

  • 0
    点赞
  • 1
    评论
  • 0
    收藏
  • 打赏
    打赏
  • 扫一扫,分享海报

©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页

打赏作者

SinoEmbedded

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值