I need to use interrupt function which I had open sample project and the code like this
PLL and clock setting
#include "lpc213x.h" // Header file for Phillips LPC2138 controller void init() { PLLCFG=0x24; // MSEL = 4,PSEL = 2 PLLFEED=0xAA; // Feed process PLLFEED=0x55; PLLCON=0x1; PLLFEED=0xAA; // Feed process PLLFEED=0x55; while(!(PLLSTAT & 0x400)) ; // Wait until PLL Locked PLLCON=0x3; // Connect the PLL as the clock source PLLFEED=0xAA; // Feed process PLLFEED=0x55; MAMCR=0x2; // Enabling MAM and setting number of clocks used for Flash memory fetch (4 cclks in this case) MAMTIM=0x4; VPBDIV=0x02; // PCLK at 30 MHz }
Interrupt Subroutine Function
void isr_int2(void) __irq { FIO0PIN ^= (1<<21); // Toggle LED at P0.21 EXTINT |= 0x4; // Clear interrupt flag EINT2 VICVectAddr = 0; // Acknowledge Interrupt }
main function
int main() { init(); // Initialize the system SCS = 0x03; // select the "fast" version of the I/O ports FIO0DIR |= (3<<21); // Config. output P0.21, p0.22 connect LED FIO0SET |= (3<<21); // OFF LED EXTMODE |= 0x4; // EINT2 Edge sensitive detection(Falling edge in this program) PINSEL0 = 0xC000; // Enable EINT2 at P0.7 VICVectAddr0 = (unsigned)isr_int2; // Register Interrupt service routine name VICVectCntl0 = 0x20 | 16; // EINT2 Interrupt VICIntEnable |= 1 << 16; // Enable EINT2 Interrupt while(1){ FIO0SET |= (1<<22); // OFF LED delay_ms(500); // Delay 500 ms FIO0CLR |= (1<<22); // On LED delay_ms(500); // Delay 500 ms } // Infinite loop }
I had compile/debug it by simulator function in Keil 4.53 evaluation. It run only in main loop and don't go to isr_int2 when I clear or set p0.7 in peripheral and in main loop is work correctly...
I try to test by open this project but don't compile it and jump to simulator debug which it work correctly , it go to isr_int2 and done and back to while loop.
I don't know why it work when I don't compile and it's not work when I compile by keil uv4...