본문 바로가기
코스웨어/16년 스마트컨트롤러

인터럽트

by 알 수 없는 사용자 2016. 3. 14.
728x90
반응형

#define PINA (*((volatile unsigned char *)0x20))
#define DDRA (*((volatile unsigned char *)0x21))
#define PORTA (*((volatile unsigned char *)0x22))
#define EICRA (*((volatile unsigned char *)0x69))
#define EICRB (*((volatile unsigned char *)0x6A))
#define EIMSK (*((volatile unsigned char *)0x3D))
#define SREG (*((volatile unsigned char *)0x5F))

#define INT7 7    
#define INT6 6
#define INT5 5
#define INT4 4
#define INT3 3
#define INT2 2
#define INT1 1
#define INT0 0

#define ISC7 6
#define ISC6 4
#define ISC5 2
#define ISC4 0
#define ISC3 6
#define ISC2 4
#define ISC1 2
#define ISC0 0


#define sei()   __asm__ __volatile__ ("sei" ::)//7번비트만 1로 만들어줌.어셈블리코드
#define sleep() __asm__ __volatile__ ( "sleep" "\n\t" :: )

 

void __vector_1(void) __attribute__((signal, used, externally_visible));//인터럽트 신호를 받는다,사용된다,외부에서 이걸 볼 수 있어야한다.(호출가능하다)


int main(void)
{

 DDRA=0xff;
 PORTA=0x00;
 EICRA=(3<<ISC0);//ISC0==INT0
 EIMSK=(1<<INT0);//==EIMSK=1;,INT0만 열고 나머지문은 다 닫는다.만약 다른것도 열고 싶으면 (1<<INT0) | (1<<INT3);이렇게 쓴다.
 SREG=SREG|(1<<7);//어셈블리보다 코드보다 느리다.SREG=SREG | (1<<7)==sei();


 while(1)
 {
  sleep();
 }
 return 0;
}

void __vector_1(void)
{
 volatile unsigned int uiCnt;

 for(uiCnt = 0; 30000>uiCnt ; ++uiCnt);

 PORTA=~PORTA;

}

728x90