Once the main program enters the interrupt service routine, the AVR chip will automatically turn off the global interrupt, and no other interrupt requests will be executed during this period. The chip will automatically reopen the global interrupt until the interrupt program ends. (Note that during this period, some interrupt requests may be discarded, and some requests will leave interrupt request marks. Once the current interrupt is executed, the request with the interrupt mark may be responded to immediately. For example, the falling edge trigger of INT0 will leave an interrupt request mark, while the low level trigger will not leave an interrupt request mark.) If you want to respond to another more important interrupt while executing the interrupt service routine, you must add a statement to turn on the global interrupt in the interrupt service routine.
Use ICCAVR Application Builder to set up as shown below. You can set whether to use interrupts, rising delay, falling delay, low level, and any logic level change.
Modify the generated program, DDRA = 0x01; PORTD = 0x0C;, add the MAIN function as follows
-
//ICC-AVR application builder : 2006-12-8 17:04:44// Target : M16// Crystal: 7.3728Mhz#include
#include unsigned int i=0;void port_init(void){ PORTA = 0x00; DDRA = 0x01; PORTB = 0x00; DDRB = 0x00; PORTC = 0x00; //m103 output on ly DDRC = 0x00; PORTD = 0x0C; //Enable the pull-up resistors for INT0 and INT1 DDRD = 0x00; //Must set the corresponding ports of INT0 and INT1 as inputs}#pragma interrupt_handler int0_isr:2void int0_isr(void){ //external interrupt on INT0 i++; //Perform operations in the interrupt }#pragma interrupt_handler int1_isr:3void int1_isr(void){ //external interupt on INT1 PORTA = 0x01; //Perform operations in the interrupt }//call this routine to initialize all peripheralsvoid init_devices(void){ //stop errant interrupts until set up CLI(); //disable all interrupts port_init(); MCUCR = 0x08; //The falling edge of INT1 generates an asynchronous interrupt request, and the rising edge of INT0 is delayed GICR = 0xC0; //INT0 and INT1 enable TIMSK = 0x00; //timer interrupt sources SEI(); //re-enable interrupts //all peripherals are now initialized}void main(void){ init_devices(); while(1) //Infinite loop waiting for interrupt;}
Related explanation
- #pragma interrupt_handler int0_isr:2
- Conventional representation of interrupts: int0_isr has a corresponding application void int0_isr(void), 2 is the interrupt vector, the smaller the value, the higher the priority, and the priority of INT0 is second only to reset.
- MCU Control Register - MCUCR The MCU Control Register contains interrupt trigger control bits and general MCU functions.
- General Interrupt Control Register - GICR Enables or disables external interrupt requests
During use: In order to reduce interference, please add a 4.7K pull-up resistor to the interrupt pin. You can also add capacitor filtering to prevent jitter according to actual needs.
Previous article:Installation of AVR cross-compilation toolkit in Debian
Next article:AVR timer/counter application design
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- R8C uses RD timer and needs to use mov instruction to write trdstr register
- Capacitors and inductors
- If you don’t pay attention to the wiring, you will have to rework it sooner or later
- Purgatory Legend-The Battle between Pre-Simulation and Post-Simulation
- EEWORLD University Hall----labview2016
- Simulation and Calculation in PCB Circuit Design
- [Qinheng RISC-V core CH582] Incomplete evaluation summary
- Read the good book "Operational Amplifier Parameter Analysis and LTspice Application Simulation" 04 Amplifier Noise Evaluation Case
- Request a circuit diagram
- Program-controlled constant current source simulation is incorrect