This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

I cant run the EXTI0:(

Hey guys.I want to use the EXTI0 to light an LED but my code does not work.Im using LPC2138 that has simulation in proteus.

Parents
  • #include <LPC213x.h>
    
    
    /******************************************************************************
                      EINT0 interrupt service function
    ******************************************************************************/
    __irq void EINT0_IRQHandler(void) {
    /* write code here */
     IOSET0=1;
    
    EXTINT = (1UL<<0);   /* Clear EINT0 interrupt flag */
    VICVectAddr = 0;     /* Acknowledge Interrupt */
    }
    
    /* Default Interrupt Function: may be called when ISR is disabled */
    __irq void DefISR (void) {
    }
    
    int main(void)
    {
    /*
        P0.0:  PORT0.0 (General purpose I/O)  Output
        P0.1:  EINT0 (External interrupt 0 input)
    
    */
    
    
        PINSEL0 = 0x0000000C;     /* binary: 00000000_00000000_00000000_00001100 */
        IO0DIR = 0x80000001;     /* binary: 10000000_00000000_00000000_00000001 */
        PINSEL1 = 0x00000000;     /* binary: 00000000_00000000_00000000_00000000 */
        PINSEL2 = 0x00000000;     /* binary: 00000000_00000000_00000000_00000000 */
        IO1DIR = 0x00000000;     /* binary: 00000000_00000000_00000000_00000000 */
    
    /******************************************************************************
                               External interrupts
    *******************************************************************************
        Ext. interrupt 0 mode: Edge sensitivity / Falling edge  / wake on interrupt 0 is Off
    */
        EXTMODE = 0x01;     /* binary: 00000001 */
        EXTPOLAR = 0x00;     /* binary: 00000000 */
        INTWAKE = ( INTWAKE & 0xC00F ) | 0x0000;     /* binary: 00000000_00000000 */
        EXTINT = 0x01;     /* clear the external interrupt flags */
    
    /******************************************************************************
                               Vector interrupt initialization
    ******************************************************************************/
    
       VICVectAddr0 = (unsigned long) EINT0_IRQHandler;           /* set interrupt vector 0 */
       VICVectCntl0 = ( 0x20 | 14 );           /* enable slot & use it for EINT0 Interrupt */
       VICIntEnable |= (1UL<<14);           /* Enable EINT0 Interrupt */
    
       VICDefVectAddr = (unsigned long) DefISR;           /* un-assigned VIC interrupts */
    
       while(1)
      {
    
    
       }
    
    }
    

Reply
  • #include <LPC213x.h>
    
    
    /******************************************************************************
                      EINT0 interrupt service function
    ******************************************************************************/
    __irq void EINT0_IRQHandler(void) {
    /* write code here */
     IOSET0=1;
    
    EXTINT = (1UL<<0);   /* Clear EINT0 interrupt flag */
    VICVectAddr = 0;     /* Acknowledge Interrupt */
    }
    
    /* Default Interrupt Function: may be called when ISR is disabled */
    __irq void DefISR (void) {
    }
    
    int main(void)
    {
    /*
        P0.0:  PORT0.0 (General purpose I/O)  Output
        P0.1:  EINT0 (External interrupt 0 input)
    
    */
    
    
        PINSEL0 = 0x0000000C;     /* binary: 00000000_00000000_00000000_00001100 */
        IO0DIR = 0x80000001;     /* binary: 10000000_00000000_00000000_00000001 */
        PINSEL1 = 0x00000000;     /* binary: 00000000_00000000_00000000_00000000 */
        PINSEL2 = 0x00000000;     /* binary: 00000000_00000000_00000000_00000000 */
        IO1DIR = 0x00000000;     /* binary: 00000000_00000000_00000000_00000000 */
    
    /******************************************************************************
                               External interrupts
    *******************************************************************************
        Ext. interrupt 0 mode: Edge sensitivity / Falling edge  / wake on interrupt 0 is Off
    */
        EXTMODE = 0x01;     /* binary: 00000001 */
        EXTPOLAR = 0x00;     /* binary: 00000000 */
        INTWAKE = ( INTWAKE & 0xC00F ) | 0x0000;     /* binary: 00000000_00000000 */
        EXTINT = 0x01;     /* clear the external interrupt flags */
    
    /******************************************************************************
                               Vector interrupt initialization
    ******************************************************************************/
    
       VICVectAddr0 = (unsigned long) EINT0_IRQHandler;           /* set interrupt vector 0 */
       VICVectCntl0 = ( 0x20 | 14 );           /* enable slot & use it for EINT0 Interrupt */
       VICIntEnable |= (1UL<<14);           /* Enable EINT0 Interrupt */
    
       VICDefVectAddr = (unsigned long) DefISR;           /* un-assigned VIC interrupts */
    
       while(1)
      {
    
    
       }
    
    }
    

Children