Simple operation of AVR external interrupt INT0

Publisher:码字先生Latest update time:2016-03-03 Source: eefocusKeywords:AVR Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
#include
#include
#include    //Call WINAVR's interrupt library function.

volatile unsigned char count = 0;  //Define loop variables. Please note that we need to add volatile here.
                                  //Because the count function will change in the interrupt function.
ISR(INT0_vect)                     //Interrupt function, note that we use ISR (interrupt name) when writing interrupt function
{
    _delay_ms(10);                 //Key delay
    if((PIND&(1 << PD0)) == 0)     //Repeat anti-shake detection, only execute the statement in if when the key is pressed
      
       count++;
       PORTB = 0xff;
       if(count > 7)
            
            count = 0;
          }
    }
    while(!(PIND&(1 << PD0)));     //Wait for the key to be released
    _delay_ms(10);                 //This is also anti-shake
}

void Interrupt_Init(void)          //Interrupt initialization function
{
   EICRA |= _BV(1);                //INT0 is a falling edge that generates an external interrupt request
   EIMSK |= _BV(INT0);                //Enable external interrupt 0
   sei();                             //Set global interrupt bit
}
int main(void)
{
    DDRB = 0xff;                    //PB port is in output mode
    PORTB = 0xff;                   //Initialize to 1
    
    DDRD = 0x00;                    //PD port is in input mode
    PORTD = 0xff;                   //With pull-up
    Interrupt_Init();
    while(1)
    {
        PORTB |= _BV(count);
        _delay_ms(500);
        PORTB &= ~_BV(count);
        _delay_ms(500);          
       
}
Keywords:AVR Reference address:Simple operation of AVR external interrupt INT0

Previous article:AVR timer counter 0 simple application of normal mode
Next article:CEPARK AVR University ---- SPI Communication of Linglong AVR Microcontroller

Recommended ReadingLatest update time:2024-11-16 08:51

Realization of home security guard system based on ATMEL AVR microcontroller
Introduction: With the theme of "convenience, comfort, enjoyment, advancement and comfort", we have designed the following modules: "contactless IC card access control module", "anti-theft and fire alarm module", "safety power control module", "air quality detection module", "temperature and humidity detection module"
[Microcontroller]
Realization of home security guard system based on ATMEL AVR microcontroller
AVR hardware operation library functions
/************************************************************************      Purpose: To build AVR hardware extraction library, add various patches, and facilitate system program transplantation Target system: Based on AVR microcontroller                                                  Application software: ICCAVR 
[Microcontroller]
Old article backup: Analysis of AVR reading and writing EEPROM
Since the AVR EEPROM write cycle is relatively long (usually in milliseconds), special attention should be paid during programming. There is nothing much to say about reading EEPROM. It takes 4 clock cycles to read one byte of data, which is tolerable. Writing is more troublesome, although the data stored in EEPROM is
[Microcontroller]
Arduino+Avr libc makes Badusb principle and example explanation
I. Introduction After researchers Jakob Lell and Karsten Nohl demonstrated the attack method of badusb at the 2014 Black Hat Conference in the United States, there have been some articles related to badusb in China, but most people still feel that badusb is still a hazy veil after reading the related articles. After a
[Microcontroller]
Arduino+Avr libc makes Badusb principle and example explanation
AVR MCU Learning Hardware Circuit Design Tutorial
Introduction: AVR microcontroller hardware circuit design tutorial  Power supply: digital power supply VCC: required in any occasion, analog power supply AVCC: required when using on-chip ADC or analog comparator Crystal oscillator: required in occasions with strict clock requirements, such as when using USART (with b
[Microcontroller]
AVR MCU Learning Hardware Circuit Design Tutorial
avr bootloader source code
assembly.s   .text    SPMCR = 0x57 ; RWW area busy flag, read RWW area allowed, allow write program storage area ; void write_page (unsigned int adr, unsigned char function); ; bits 8:15 adr addresses the page...(must setup RAMPZ beforehand!!!) _write_page::     XCALL __WAIT_SPMEN__     movw    r30, r16        ;move
[Microcontroller]
Two very practical methods for debugging AVR microcontrollers
Friends who have been playing with microcontrollers for a long time know that program running bugs are inevitable, and the repetitive debugging process is always painful. If you are not very familiar with the IDE application you are using, and are not very comfortable using its online simulation debugging tools, then
[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号