1 / 12

External & internal Interrupts

External & internal Interrupts. Interrupt Sources. There are 21 different interrupts and each one has its own vector located in a predefined location at the start of the memory space.

anakin
Télécharger la présentation

External & internal Interrupts

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. External & internal Interrupts

  2. Interrupt Sources • There are 21 different interrupts and each one has its own vector located in a predefined location at the start of the memory space. • 3 external interrupts (INT0, INT1 and INT2) are available at pins PD2(pin 16) and PD3 (pin 17) and PB2 (pin 3). They are Edge or Level triggered interrupts (except Int2 which is only edge triggered). • Reset input (pin 9) which causes also an interrupt and can be both externally and internally initiated. • If enabled, the interrupts will trigger even if the INT0 and INT1 pins are configured as outputs. This feature provides a way of generating a software interrupt (how?). • INT0, INT1 (level) and INT2 are detected asynchronously (no Clock needed and thus they can be used to get the µC from sleep modes.

  3. Reset and Interrupt Vectors

  4. Notes to interrupt vector table • If the program never enables an interrupt source, the Interrupt Vectors are not used, and regular program code can be placed at these locations.

  5. External Interrupts: • To enable INT0/INT1/INT2: • The I-bit in the Status Register must be set. But also the corresponding External Interrupt Request Enable bit in the General Interrupt Control Register (GICR) • When an event on the INT0/INT1/INT2 pin triggers an interrupt request, INT0-Flag/INT1-Flag/INT2-Flag (bit 6/7/5 of the General Interrupt Flag Register – GIFR) becomes set. The flag is cleared when the interrupt routine is executed. Alternatively, the flag can be cleared by writing a logical one to it. General Interrupt Flag

  6. Interrupt Triggering • The external interrupts INT0/INT1 can be triggered by a falling or rising edge or a low level.

  7. INT2 • The external interrupts INT2 can only be triggered by a falling or rising edge. • ISC2 (interrupt sense control of INT2): • ISC2 = 0 -> Falling Edge • ISC2 = 1 -> Rising Edge MCU Control and Status Register

  8. Using Interrupts in C The access to the AVR interrupt system is implemented with the interrupt keyword. Examples: interrupt [2] void external_int0(void) { /* Place your code here */ RETI } interrupt [10] void timer0_overflow(void) { /* Place your code here */ RETI }

  9. Using Interrupts in C (Contd.) • Interrupt vector numbers start with 1. • The compiler will automatically save the affected registers when calling the interrupt functions and restore them back on exit. • a RETI assembly instruction is placed at the end of the interrupt function. • Interrupt functions can't return a value nor have parameters. • You must also set the corresponding bits in the peripheral control registers to configure the interrupt system and enable the interrupts.

  10. Using the CodeVisionAVR Wizard by interrupts

  11. Including Assembly Lines in the Program You can include assembly language anywhere in your program using the #asm and #endasmdirectives. Example: void delay(unsigned char i) { while (i--) { /* Assembly language code sequence */ #asm nop nop #endasm }; } Inline assembly may also be used. Example: #asm("sei") /* enable interrupts */

More Related