在LPC213x/4x上初始化外部中断



嗨,我在下面为KEIL 4.7编译器中LPC2138的初始外部中断写代码,当在proteus软件中运行代码时,代码dosent Work。我仔细检查VIC和EXTINT寄存器是否正确。感谢

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++);
  }
}

您应该更正以下行:

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

至:

(VICVectCntl5 = 0x20 | 16;) 

正如数据表所说。

最新更新