본문 바로가기

ARM7

9,10(스위치)번 입력(HIGH)핀은오 1, 2(예)LED)번 출력 제어 하기

//#include "AT91SAM7S256.h"
//#include "lib_AT91SAM7S256.h"
//#include "OK7S256ads.h"

#define PIO_SODR (*(volatile unsigned int *) 0xFFFFF430) //출력
#define PIO_CODR (*(volatile unsigned int *) 0xFFFFF434) //출력 하지 않음
#define PIO_OER  (*(volatile unsigned int *) 0xFFFFF410) //출력 방향 설정
#define PIO_PER  (*(volatile unsigned int *) 0xFFFFF400) //병렬 입출력 제어 레지스터 병렬 입출력 포트로 사용한다.
#define PIO_IFER (*(volatile unsigned int *) 0xFFFFF420)
#define PIO_IER (*(volatile unsigned int *) 0xFFFFF440)
#define AIC_IDCR (*(volatile unsigned int*) 0xFFFFF124)
#define AIC_SVR ((volatile unsigned int*) 0xFFFFF080)
#define AIC_SMR ((volatile unsigned int*) 0xFFFFF000)
#define AIC_IECR  (*(volatile unsigned int*) 0xFFFFF120)
#define AIC_ICCR (*(volatile unsigned int*) 0xFFFFF128)
#define PIO_ISR (*(volatile unsigned int*) 0xFFFFF44C)
#define PIO_PUDR (*(volatile unsigned int*) 0xFFFFF460)// 풀업저항 인터럽트 레지스터
 

//---------- 전력 제어 설정

#define PMC_PCER (*(volatile unsigned int *) 0xFFFFFC10)

 
#define MASTERCLOCK 48000000
 
void Delay_ms(unsigned int ms) //딜레이 함수..
{
  volatile unsigned int count, countmax = (MASTERCLOCK / 10000) * ms;

  for(count = 0; count < countmax; count++);
}

//--------- 전역 변수
 
void PIO_ISR001(void)
{ unsigned int i,status;
 //status =(AT91F_PIO_GetInterruptStatus(AT91C_BASE_PIOA)>>7) & 0x00000003;
 status =PIO_ISR & 0x00000600;// 9번,10번 인터럽트 신오가 들어恙철?
 if(status == 0x200) //포트PA9번에 입력이들어올때
  {  for(i=1;i<3;i++)
  { 
  PIO_SODR = 0x00000001;//PA0 LED ON
   //LED_on(LED1);
   Delay_ms(500);
   //LED_off(LED1);
  PIO_CODR = 0x00000001;// PA0 LED OFF
  Delay_ms(500); 
     }
  }
 else if(status == 0x400)// WHEN PA10번에 입려이들어
 { for(i=1;i<3;i++)
  {
  PIO_SODR = 0x00000002;//PA1번에 LED ON
   //LED_on(LED2);
   Delay_ms(500);
  //LED_off(LED2);
  PIO_CODR = 0x00000002;//PA1 LED OFF
  Delay_ms(500); 
  }
 }
}
/*
void Delayms(unsigned int ms) //딜레이 함수..
{
  volatile unsigned int count, countmax = (MASTERCLOCK / 10000) * ms;

  for(count = 0; count < countmax; count++);
}
*/
int main(void)

PMC_PCER = (unsigned int )1<<2;
PIO_OER = 0x00000FFF;  //포트PA0~PA10 출력 을 허용 한다
 //PIO_SODR = 0x00000600;   //PA9,10번  출력 1로 출력 한다 
PIO_PUDR = 0x00000600;// 9 번 10번 으로 입력 허용
 //PIO_IFER = 0x00000600;//
 //Delay_ms(50);
//MCU_initialize();
//Delay_ms(50);

 

//AT91F_PIO_InputFilterEnable(AT91C_BASE_PIOA,KEY2|KEY1);
PIO_IFER=(unsigned int)1<<9|(unsigned int)1<<10;// 인터럽트 필터 이네이블

//AT91F_PIO_InterruptEnable(AT91C_BASE_PIOA,KEY2|KEY1);
PIO_IER=(unsigned int)1<<9|(unsigned int)1<<10;//인터럽트 이네이블레지스터

//AT91F_AIC_ConfigureIt(AT91C_BASE_AIC,AT91C_ID_PIOA,7,1,PIO_ISR);
AIC_IDCR = (volatile unsigned int)1<<2;
AIC_SVR[2] = (unsigned int) PIO_ISR001;
AIC_SMR[2] = 7;// 병렬 입출력포트(2번임)에 우선 순위 인터럽트 7(가장높若??를 주어라  

//AT91F_AIC_EnableIt(AT91C_BASE_AIC,AT91C_ID_PIOA);
AIC_IECR=(volatile unsigned int)1<<2;   //인터럽트 허용 명령 레지스터
AIC_ICCR=(volatile unsigned int)1<<2;   //인터럽트를 금지 한다


while(1);
}

 

//  PIO_CODR = 0x0000000F;
//  Delayms(500);}
  

 
 // End Main....