LPC213x / 4x初始化外部中断

时间:2016-05-06 07:09:42

标签: arm interrupt

您好我在KEIL 4.7编译器中为LPC2138的初始外部中断编写了以下代码,当在proteus软件中运行代码时,代码剂量工作。我仔细检查VIC和EXTINT寄存器似乎是正确的。感谢

Project Picture on Proteus

一个开关EXTINT2(P0.15)和P1.25上的一个LED

#include <LPC213x.h>  

void delay(int count);
void init_ext_interrupt(void);
__irq void Ext_ISR(void);

int main (void) 
{
  init_ext_interrupt();   // initialize the external interrupt

  while (1)  
  {     
    }
}

void init_ext_interrupt(void)  //Initialize Interrupt
{
  EXTMODE = (1<<2);     //Edge sensitive mode on EINT2 
  EXTPOLAR &= ~(1<<2);  //Falling Edge Sensitive
  PINSEL0 = 0x80000000; //Select Pin function P0.15 as EINT2 
  /* initialize the interrupt vector */
  VICIntSelect &= ~(1<<16);        // EINT2 selected as IRQ 16
  VICVectAddr5 = (unsigned)Ext_ISR; // address of the ISR
  VICVectCntl5 = (1<<5) | 16;            
  VICIntEnable = (1<<16);           // EINT2 interrupt enabled

  EXTINT &= ~(1<<2);    //Set interrupt
}

__irq void Ext_ISR(void) // Interrupt Service Routine-ISR 
{
 IO1DIR |= (1<<25);
 IO1SET |= (1<<25); // Turn ON LED
 delay(100000);
 IO1CLR |= (1<<25); // Turn OFF LED

 EXTINT |= (1<<2);  //clear interrupt
 VICVectAddr = 0;   // End of interrupt execution
}

void delay(int count)
{
  int j=0,i=0;
  for(j=0;j<count;j++)
  {
    for(i=0;i<35;i++);
  }
}

1 个答案:

答案 0 :(得分:0)

您应更正以下行:

(VICVectCntl5 = (1<<5) | 16;)

收件人:

(VICVectCntl5 = 0x20 | 16;) 

如数据表所述。