AVR > mega8 외부 인터럽트 설정

TODAY6,293 TOTAL7,736,412
사이트 이용안내
Login▼/회원가입
최신글보기 질문게시판 기술자료 동영상강좌

아두이노 센서 ATMEGA128 PWM LED 초음파 AVR 블루투스 LCD UART 모터 적외선


BASIC4MCU | AVR | 외부인터럽트 | mega8 외부 인터럽트 설정

페이지 정보

작성자 키트 작성일2017-08-29 09:17 조회4,901회 댓글0건

본문

My Books > AVR GUIDE >

EXTERNAL INTERRUPTS ON THE ATmega8

INTRODUCTION:

    In the previous section I talked about the basics of interrupts. In this section, we will talk about the first type of device interrupts called external interrupts.  These interrupts are basically called on a given status change on the INTn pin. This is essentially an input interrupt and is great to use for applications when you might need to react quickly to an outside source, such as a bumper of your robot hitting the wall or to detect a blown fuse.





HARDWARE:

3660040649_WMds8r3I_ATmega82520-2520INTx2520.JPG
Figure 1: ATmega8 - External Interrupt Pins

    Hardware wise there is not difference between External Interrupts and Inputs so don't be afraid to reread the Digital Input Tutorial if you need a refresher.

    If you look at the AVR pinout diagram you will see the INTx which are used for External Interrupts.





THEORY OF OPERATION:


    External interrupts are fairly powerful, they can be configured to trigger on one of 4 states.  Low level will trigger whenever the pin senses a LOW (GND) signal.  Any Logic Change trigger at the moment the pin changes from HIGH (Vcc) to LOW (GND) or from LOW (GND) to HIGH(Vcc). On Falling Edge will trigger at the moment the pin goes from HIGH (Vcc) to LOW (GND). On Rising Edge will trigger at the moment the pin goes from LOW (GND) to HIGH (Vcc).  The best part is that you can configure each INTx independently.

    External interrupts use the below 3 registers.  Which you could find under the "External Interrupts section of the datasheet.

  7 bit6 bit 5 bit 4 bit 3 bit 2 bit 1 bit  0 bit
 MCUCRSE SM2 SM1 SM0 ISC11 ISC10 ISC01 ISC00 
MCU Control Register


 ISCx1 ISCx0 DESCRIPTION 
00 Low level of INTx generates an interrupt request
01 Any logic change on INTx generates an interrupt request 
10 The falling edge of INTx generates an interrupt request 
11 The rising edge of INTx generates an interrupt request 
ISC Bits Settings


  7 bit
6 bit 
5 bit 
4 bit 
3 bit 
2 bit 
1 bit 
0 bit 
GICR INT1INT0 




IVSEL 
IVCE 
General Interrupt Control Register


  7 bit
6 bit 
5 bit 
4 bit 
3 bit 
2 bit 
1 bit 
0 bit 
GIFRINTF1 
INTF0 





-
General Interrupt Flag Register


    When the event specified by the Interrupt Sense Control (ISCxy) bits in the MCU Control Register (MCUCR) is sensed on the INTx pin, the External Interrupt Flag x (INTFx) in the General Interrupt Flag Register (GIFR) is set HIGH (1).  If the I-bit in SREG and the INT1 bit in the GICR are both HIGH(1) the MCU will jump to the corresponding vector.  The Flag is set to LOW (0) when the INTx_vect routine is executed.  





SOFTWARE:


    The external interrupt code is fairly simple, just declare your INTx pins as inputs, set the inputs as interrupts, turn on the interrupts, and finally don't forget your ISR routines.


ATmega8 Code:
#include
#include



int main(void)
{
    DDRD &= ~(1 << DDD2
    
    MCUCR |= (1 << ISC00);    // set INT0 to trigger on ANY logic change
    GICR |= (1 << INT0);      // Turns on INT0

    sei();                    // turn on interrupts

    while(1)
    {
        /*main program loop here */
    }
}



ISR (INT0_vect)
{
    /* interrupt code here */
}


    I like big bots and I can not lie.

Cheers
Q



이 글의 mega8 설정을 128 설정과 비교해보겠습니다.


  7 bit6 bit 5 bit 4 bit 3 bit 2 bit 1 bit  0 bit
 MCUCRSE SM2 SM1 SM0 ISC11 ISC10 ISC01 ISC00 
MCU Control Register


 ISCx1 ISCx0 DESCRIPTION 
00 Low level of INTx generates an interrupt request
01 Any logic change on INTx generates an interrupt request 
10 The falling edge of INTx generates an interrupt request 
11 The rising edge of INTx generates an interrupt request 
ISC Bits Settings

mega8의 MCUCR 레지스터는 트리거 설정이므로 
mega128의 EICRA EICRB 레지스터와 같습니다. 128은 인터럽트 갯수가 많아서 레지스터가 두 개입니다.



  7 bit
6 bit 
5 bit 
4 bit 
3 bit 
2 bit 
1 bit 
0 bit 
GICR INT1INT0 




IVSEL 
IVCE 
General Interrupt Control Register

mega8의 GICR 레지스터는 인터럽트 마스크 설정이므로
mega128의 EIMSK 레지스터와 같습니다.


  7 bit
6 bit 
5 bit 
4 bit 
3 bit 
2 bit 
1 bit 
0 bit 
GIFRINTF1 
INTF0 





-
General Interrupt Flag Register

mega8의 GIFR 레지스터는 인터럽트 플래그이므로
mega128의 EIFR 레지스터와 같습니다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//ATmega8 Code:
#include <avr/io.h>
#include <avr/interrupt.h>
//
ISR (INT0_vect){
}
//
int main(void){
    PORTD=0x04// 내부 풀업저항
    MCUCR=0x0A// falling edge
    GICR=0x40;  // 인터럽트 마스크 이네이블
    SREG=0x80;  // 전역인터럽트 이네이블
    while(1){
    }
}
 
cs

mega8을 128 카페 예제처럼 설정하면 이렇게 됩니다. 

댓글 0

조회수 4,901

등록된 댓글이 없습니다.

AVRHOME > AVR > 외부인터럽트 목록

게시물 검색

2022년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2021년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2020년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2019년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2018년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
Privacy Policy
MCU BASIC ⓒ 2020
모바일버전으로보기