AVR external interrupt operation under IAR

Publisher:pingbashouLatest update time:2016-10-06 Source: eefocusKeywords:IAR  AVR Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Chip: ATMega16

Crystal: 7.3728 MHz

External interrupt 0, falling edge triggered.

About hardware: If you want to use external interrupts stably, it is best to pull up a resistor at the pin (usually 10K, of course, whether to pull up or pull down depends on your trigger conditions). If it is a button, you should add a capacitor (usually 104). This will have a better effect and effectively prevent jitter.

Code:

#include
#include
#include

void int0_init()
{
_CLI(); //disable all interrupts //Disable total interrupt

MCUCR = 0x02; //Falling edge triggers external interrupt 0
GICR = 0x40; //Enable external interrupt 0
GIFR_INTF0 = 1; //Clear external interrupt 0 flag

_SEI(); //re-enable interrupts //Open general interrupt
}

void main(void)

DDRB_Bit0 = 1; //define an LED 
int0_init();

while(1);
}

#pragma vector = INT0_vect //External interrupt 0 entry address 
__interrupt void ex_int0(void) 

PORTB_Bit0 = ~PORTB_Bit0; //Each time an interrupt is entered, an LED will turn from bright to dark, and from dark to bright
}

Keywords:IAR  AVR Reference address:AVR external interrupt operation under IAR

Previous article:IAR For AVR -- LCD1602
Next article:IAR For AVR About the use of comp_a90.h header file

Recommended ReadingLatest update time:2024-11-16 15:26

AVR 8515 MCU remote control decoding program
This program implements K1D and China Telecom set-top box remote control decoding. I just switched from 51 MCU to AVR and learned C programming. I spent a day to correct some sentence formats and finally finished it. The effect is very good. Share it with everyone. I only post the decoded part of the file here, forget
[Microcontroller]
AVR communication--the difference between synchronous and asynchronous
We all know that data communication is the sending and receiving of digital signals between two communicating entities. Suppose the following data is to be sent: 12, 23, 34, 45, 56, 67, 78, 89. In order for the receiver to correctly receive this data, it must know when the data starts and ends. Otherwise, the data may
[Microcontroller]
Using AVR microcontroller to control GSM module to send and receive text messages
GSM modules are useful when our projects require remote access. With these modules we can do everything that our normal mobile phones can do, such as making/receiving calls, sending/receiving SMS, connecting to the internet using GPRS, etc. You can also connect a normal microphone and speaker to this module to talk to
[Microcontroller]
Using AVR microcontroller to control GSM module to send and receive text messages
IAR Systems supports NXP S32K3 MCU family for next-generation automotive applications
IAR Systems supports NXP S32K3 MCU family for next-generation automotive applications IAR Embedded Workbench® for Arm®, the complete development tool chain from IAR Systems®, now supports the latest automotive-grade S32K3 MCU family from NXP® Semiconductor  Uppsala, Sweden—November 2021—IAR Systems®, a leading
[Embedded]
IAR Systems supports NXP S32K3 MCU family for next-generation automotive applications
AVR microcontroller controlled relay
#include "macros.h" #define uchar unsigned char #define uint  unsigned int void delay_ms(uchar i) { uchar a,b; for(a=1;a i;a++)    for(b=1;b 141;b++)    {;} } void main(void) { DDRA=0X80; PORTA=0X80; DDRB=0XFF; PORTB=0XFF; DDRC=0X01; PORTC=0X01; DDRD=0X00; PORTD=0XFF; while(1)   {    PORTA  ^=  BIT(7);     delay_ms
[Microcontroller]
AVR microcontroller controlled relay
How to make program debugging easier with AVR microprocessors
  introduction   With the development of technology, the design and application of embedded systems have had a great impact on people's lives and will gradually change people's future lifestyles. Developing applications on a specific operating system allows developers to ignore many underlying hardware details, maki
[Microcontroller]
IAR Systems announces support for 64-bit RISC-V cores, expanding its powerful RISC-V solutions
IAR Systems announces support for 64-bit RISC-V cores, further expanding its powerful RISC-V solutions IAR Systems offers high-performance, proven technology to companies choosing emerging RISC-V 64-bit cores for upcoming development projects Uppsala, Sweden, March 2022 – IAR Sy
[Embedded]
IAR Systems announces support for 64-bit RISC-V cores, expanding its powerful RISC-V solutions
Design of intelligent treadmill controller based on AVR microcontroller
1 Introduction The electric treadmill is the mainstream product among fitness equipment at present. It uses a motor to drive the running belt to make people run or walk passively at different speeds. In terms of human strength, it saves a stretching action compared to running and walking on the ground, which ca
[Microcontroller]
Design of intelligent treadmill controller based on AVR microcontroller
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号