Created
September 4, 2013 14:09
-
-
Save Embedded-linux/6437448 to your computer and use it in GitHub Desktop.
External Interrupt2 for LPC2148
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //————————————————————————————————————————————————————————————————————————// | |
| // Program : Example for EINT2(External interrupt2) | |
| // Description : Test interrupt from switch press display by LED at P0.21 | |
| // : toggle and sound beep | |
| // Frequency : Crystal 12 MHz at PLL 5x(CCLK = 60 MHz),PCLK = 30 MHz | |
| // Filename : ext_int2.c | |
| // C compiler : Keil CARM Compiler | |
| //————————————————————————————————————————————————————————————————————————// | |
| #include “lpc214x.h” // Header file for Phillips LPC2148 controller | |
| #include “sound.h” // Header file for Phillips LPC2148 controller | |
| //—————————————— Function for Initial system clock ————————————————// | |
| void init() | |
| { | |
| PLL0CFG=0x24; // MSEL = 4,PSEL = 2 | |
| PLL0FEED=0xAA; // Feed process | |
| PLL0FEED=0x55; | |
| PLL0CON=0x1; | |
| PLL0FEED=0xAA; // Feed process | |
| PLL0FEED=0x55; | |
| while(!(PLL0STAT & 0x400)) ; // Wait until PLL Locked | |
| PLL0CON=0x3; // Connect the PLL as the clock source | |
| PLL0FEED=0xAA; // Feed process | |
| PLL0FEED=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 service routine for EINT2 ———————————————// | |
| void isr_int2(void) __irq | |
| { | |
| beep(); // Sound beep 1 time | |
| FIO0PIN ^= (1<<21); // Toggle LED at P0.21 | |
| EXTINT |= 0x4; // Clear interrupt flag EINT2 | |
| VICVectAddr = 0; // Acknowledge Interrupt | |
| } | |
| //————————————————— Main Program ————————————————————————// | |
| void main() | |
| { | |
| init(); // Initialize the system | |
| SCS = 0x03; // select the “fast” version of the I/O ports | |
| FIO0DIR |= (1<<21); // Config. output P0.21 connect LED | |
| FIO0SET |= (1<<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); // Infinite loop | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment