AVR interrupt causes restart

Publisher:心愿实现Latest update time:2018-07-16 Source: eefocusKeywords:AVR Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

If interrupts are enabled in AVR but there is no corresponding interrupt service function, the chip will restart. By analyzing the assembly code generated by the compilation, you can clearly understand the problem.


Compiler uses Atmel Atudio7.0


Chip: ATmega128A


Since no method was found to generate assembly code, ReAVR was used for disassembly.


The following is the case with ISR


C


#include

#include "avr/interrupt.h"

 

void initTimer3();

 

int main(void)

{

initTimer3();

be();

while(1)

{

 

}//while(1)

}

 

 

void initTimer3()

{

TCNT3=0x0000;

TCCR3B=0x01;

OCR3A=14745;

ETHYM=0x10;

}

 

ISR(TIMER3_COMPA_vect)

{

TCNT3=0x0000;

}



compilation


; 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 //Vector number 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: //Default interrupt service function, equivalent to triggering reset interrupt

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

right

;----------------------*

; pc=0x63(0xC6)

;

L0063:

call L0052

be

L0066:

rjmp L0066

; ----------- jump on last line

; pc=0x67(0xCE)

;

L0067: //TIMER3_COMPA interrupt service function, normal

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

;---------------------------------------

;





Assembly code without 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 //vector number 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: //Default interrupt service function, equivalent to triggering reset interrupt

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

right

;----------------------*

; pc=0x63(0xC6)

;

L0063:

call L0052

be

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

;---------------------------------------

;

Keywords:AVR Reference address:AVR interrupt causes restart

Previous article:Atmage16 interrupt learning - external interrupt
Next article:How to write a real ADC converter in ATmega8

Recommended ReadingLatest update time:2024-11-16 20:22

AVR timer/counter 1 --TC1 --input capture mode (capture external event mode)
The input capture unit of the T/C can be used to capture external events and give them a time stamp to indicate the time when this time occurs. The trigger signal of the external event is input by pin ICP1 (PD6) or can be realized by the analog comparator unit. The time stamp can be used to calculate the frequency, du
[Microcontroller]
IAR For AVR Precision Delay
It is not easy to use an accurate delay program in C language. IAR has a function called __delay_cycles(), which is defined in the header file intrinsics.h. The function is to delay N instruction cycles. Based on this function, an accurate delay function can be implemented (but it cannot be 100% accurate). Implementat
[Microcontroller]
How to use AVR microcontroller to test the remaining power of the battery?
As a backup power source, batteries have been widely used in computer networks, communications, electricity and other fields. The charge of the battery is closely related to the reliability of the entire power supply system. The higher the remaining battery power, the higher the system reliability, and vice versa. For
[Microcontroller]
How to use AVR microcontroller to test the remaining power of the battery?
Introduction of energy-saving elevator based on AVR microcontroller
1. Project Overview 1.1 Introduction With the development of society, high-rise buildings and intelligent buildings are constantly emerging. As a vertical transportation tool, elevators have been more and more widely used, and people have put forward higher and higher requirements for the service quality and reliable
[Microcontroller]
Introduction of energy-saving elevator based on AVR microcontroller
Avr128 watchdog settings
 When there is WDR() in the program, that is, the watchdog is fed, the program only executes the part in while, because the watchdog is fed again before the watchdog timing is up, which means the counter is still counting again. There is no WDR() in the program, that is, the watchdog is not fed. When the program execu
[Microcontroller]
AVR microcontroller internal RC oscillator calibration method
Introduction: VR microcontroller has an internal RC oscillator. Calibration of the internal oscillator has always been a difficult problem. Due to this problem, many normal programs cannot work properly. This document is specially compiled for readers' reference. Theory of Operation – Internal RC Oscillator The inte
[Microcontroller]
Design of intelligent energy-saving socket based on AVR
0 Introduction The standby energy consumption of computer peripheral devices (such as printers, scanners, speakers, etc.) not only increases consumers' daily electricity bills, but also causes great waste of electricity resources. The computer intelligent energy-saving socket designed in this paper uses the powe
[Microcontroller]
Design of intelligent energy-saving socket based on AVR
Introduction to C language programming style for AVR microcontrollers
  Abstract: How can a beginner have a good programming style? The following article will introduce the C language programming style of AVR microcontroller.   Introduction to C programming style   1. Variable definition   When defining a variable, the prefix is ​​the type of variable, followed by an English word or abb
[Microcontroller]
Introduction to C language programming style for AVR microcontrollers
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号