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
;---------------------------------------
;
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
- Popular Resources
- Popular amplifiers
- Principles and Applications of Single Chip Microcomputers 3rd Edition (Zhang Yigang)
- Metronom Real-Time Operating System RTOS for AVR microcontrollers
- STM8 C language programming (1) - basic program and startup code analysis
- Learn C language for AVR microcontrollers easily (with video tutorial) (Yan Yu, Li Jia, Qin Wenhai)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- ESP32-C3 Debug Diary
- LPS28DFW driver and related information
- Battery Test Equipment --- Signal Chain
- Share: Debugging of SIM7020 and NB-IOT
- mini risc mcu source code
- The design application of TGA2509 is not particularly ideal
- Analysis of the problem that the program cannot run after F28004x online debugging reset
- Share a PD fast charging power deception chip CH224 is very practical
- Alloy sampling resistor series
- TI's Class AB car amplifier chip recommendations