관리 메뉴

드럼치는 프로그래머

[마이크로프로세서 응용설계] 실습자료 - Interrupt 본문

★─Multi Media/☆─3학년 1학기

[마이크로프로세서 응용설계] 실습자료 - Interrupt

드럼치는한동이 2008. 10. 13. 19:43

#include <ina90.h>
#include <iom128.h>

#define DEF_USE   1
#define DEF_NOTUSE  0

#define ON   1
#define OFF   0

#define UINT8                   unsigned char
#define Set_pullup(x)  {SFIOR_PUD = !x;}

#define Set_port_a(x, y) {DDRA = (UINT8) ~x; PORTA = y;}
#define Set_port_c(x, y) {DDRC = (UINT8) ~x; PORTC = y;}
#define Get_id_hi()  (~PINA & 0xff)
#define Get_id_low()  (~PINC & 0xff)

/*
// input setting
#define Get_sw0()               !PIND_Bit0
#define Get_sw1()               !PIND_Bit5
#define Get_sw2()               !PIND_Bit6
*/
// output setting
//#define Set_led0(x)           PORTE_Bit3 = !x
//#define Set_led1(x)           PORTE_Bit4 = !x
//#define Set_led2(x)           PORTE_Bit5 = x
#define Set_led3(x)             PORTE_Bit6 = x

void init_mcu()
{
    Set_pullup(DEF_USE); 
    DDRD = (UINT8) ~(0x61);   // ~(01100001) = (10011110) = 0x9e 
    DDRE = (UINT8) ~(0x87);   // ~(10000111) = (01111000) = 0x78
    PORTD = 0x61;             // 01100001
    PORTE = 0x18;             // 00011000
    Set_port_a(0xff, 0xff);   // 00000000  11111111
    Set_port_c(0xff, 0xff);   // 00000000  11111111
}

// External Interrupt O service routine
#pragma vector = INT0_vect
__interrupt void ext_intO_isr(void)
{
        __disable_interrupt();
 if ( Get_id_hi() == Get_id_low() )  Set_led3(ON);
 else Set_led3(OFF);
}

void main(void)
{
 // 초기화
        init_mcu();
       
 __enable_interrupt();

        EIMSK |= 0x01;
        EICRA |= 0x02;
       
// EICRA_ISC11 = 1; // 인터럽트 하강에지
// EICRA_ISC00 = 0; // EICRA_ISC01 = 0
// EIMRK_INT0  = 1;
 
 while (1)
 {
  __watchdog_reset();
 }
}

Comments