Powered By Blogger

Sabtu, 26 Mei 2012

External Interupt pada Code VIsion AVR

Posting kali ini saya akan memberikan tutorial penggunaan external interupt menggunakan software compiler CodeVision AVR.

Terlebih dahulu kita membuat simulasi di proteus, seperti gambar dibawah ini


Terlebih dahulu kita setting code visionnya,



 ketikkanlah syntax berikut :

#include <mega16.h>
#include <delay.h>

// Alphanumeric LCD Module functions
#asm
   .equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>

// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
        lcd_gotoxy(0,0);
        lcd_putsf("Ex - Int");

        lcd_gotoxy(0,1);
        lcd_putsf("INTERRUPT 0");
        delay_ms(2000); 
        lcd_clear();
}

// External Interrupt 1 service routine
interrupt [EXT_INT1] void ext_int1_isr(void)
{
        lcd_gotoxy(0,0);
        lcd_putsf("Ex - Int");

        lcd_gotoxy(0,1);
        lcd_putsf("INTERRUPT 1");
        delay_ms(2000); 
        lcd_clear();
}

// External Interrupt 2 service routine
interrupt [EXT_INT2] void ext_int2_isr(void)
{
        lcd_gotoxy(0,0);
        lcd_putsf("Ex - Int");

        lcd_gotoxy(0,1);
        lcd_putsf("INTERRUPT 2");
        delay_ms(2000);
        lcd_clear();
}

// Declare your global variables here

void main(void)
{
// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Falling Edge
// INT1: On
// INT1 Mode: Falling Edge
// INT2: On
// INT2 Mode: Falling Edge
GICR|=0xE0;
MCUCR=0x0A;
MCUCSR=0x00;
GIFR=0xE0;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

// LCD module initialization
lcd_init(16);

// Global enable interrupts
#asm("sei")

while (1)
      {
      lcd_gotoxy(0,0);
      lcd_putsf("Ex - Int");

      lcd_gotoxy(0,1);
      lcd_putsf("NO INTERRUPT");
      };
}

Maka bila  PORTD.2 ditekan (ground) :


bila PORTD.3 ditekan (ground) :


bila PORTB.2 ditekan (ground) :