Last active
December 22, 2015 15:58
-
-
Save Embedded-linux/6495895 to your computer and use it in GitHub Desktop.
External INT for LPC 2148
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
| /************Main Function*****************/ | |
| #include <lpc214x.h> | |
| #include "ext_int.h" | |
| int main(void) { | |
| keypad_init(); //// initialize the keypad in interrup mode | |
| while(1) | |
| { | |
| } | |
| } | |
| /************************End of Main Function ******************************/ | |
| /************************start of ext_int.h *****************************************/ | |
| #ifndef KEYPAD_H | |
| #define KEYPAD_H | |
| #include <lpc214x.h> | |
| #define IODIR1 (*((volatile unsigned long *) 0xE0028018)) | |
| #define IOPIN1 (*((volatile unsigned long *) 0xE0028010)) | |
| #define IOSET1 (*((volatile unsigned long *) 0xE0028014)) | |
| #define IOCLR1 (*((volatile unsigned long *) 0xE002801C)) | |
| #define KEY_NOT_PRESSED 0xFF | |
| #define KEYPAD_DATA_DIR IODIR1 | |
| #define KEYPAD_DATA IOPIN1 | |
| #define KEYPAD_COL_SET IOSET1 | |
| #define KEYPAD_ROW_SET IOSET1 | |
| #define KEYPAD_COL_CLR IOCLR1 | |
| #define KEYPAD_ROW_CLR IOCLR1 | |
| #define COL_MASK (COL0 | COL1 | COL2 | COL3) | |
| #define ROW_MASK (ROW0 | ROW1 | ROW2 | ROW3) | |
| #define COL0 (1<<21) | |
| #define COL1 (1<<22) | |
| #define COL2 (1<<23) | |
| #define COL3 (1<<24) | |
| #define ROW0 (1 << 17) | |
| #define ROW1 (1 << 18) | |
| #define ROW2 (1 << 19) | |
| #define ROW3 (1 << 20) | |
| void keypad_init(void); | |
| unsigned char key_hit(unsigned char **key); | |
| void Ext_ISR(void) __irq; | |
| unsigned char read_key(void); | |
| #endif | |
| /******************************************End of ext_int.h*****************************/ | |
| /*****************************buzzer.c **********************************/ | |
| #include <lpc214x.h> | |
| #define IODIR0 (*((volatile unsigned long *) 0xE0028008)) | |
| #define IOSET0 (*((volatile unsigned long *) 0xE0028004)) | |
| #define IOCLR0 (*((volatile unsigned long *) 0xE002800C)) | |
| #define BUZZER (1<<25) | |
| #define BUZZER_DIR IODIR0 | |
| #define BUZZER_SET IOSET0 | |
| #define BUZZER_CLR0 IOCLR0 | |
| /** | |
| ******************************************************************************************** | |
| Function Name : turn_on_buzzer() | |
| Description : | |
| Input : | |
| Output : Void | |
| Note : | |
| ******************************************************************************************** | |
| */ | |
| void turn_on_buzzer() | |
| { | |
| BUZZER_DIR |= BUZZER; | |
| BUZZER_SET |= BUZZER; | |
| } | |
| /** | |
| ******************************************************************************************** | |
| Function Name : turn_off_buzzer() | |
| Description : | |
| Input : | |
| Output : Void | |
| Note : | |
| ******************************************************************************************** | |
| */ | |
| void turn_off_buzzer() | |
| { | |
| BUZZER_DIR |= BUZZER; | |
| BUZZER_CLR |= BUZZER; | |
| } | |
| /*************************************End of Buzzer.c function***********************************/ | |
| /****************************************ext_int.c function *************************************/ | |
| #include <lpc214x.h> | |
| #include "ext_int.h" | |
| #include "buzzer.h" | |
| #define EXTINT_EINT1_MASK 0x2 | |
| #define EXTPOLAR_EXTPOLAR1_MASK 0x2 | |
| #define EXTMODE_EXTMODE1_MASK 0x2 | |
| //Vectro Control Register Bit Definitions | |
| #define VIC_ENABLE (1<<5) | |
| //Convert channel to bit definitions | |
| #define VIC_BIT(chan) (1<<(chan)) | |
| #define VIC_EINT1 15 | |
| /** | |
| ************************************************************************** | |
| ****1111 | |
| Function Name : delay() | |
| Description :This function suspends the tasks for specified ticks. | |
| Input : ticks:no of ticks in multiple of 1 usec | |
| task: task to be suspended | |
| Output : void | |
| Note : | |
| ******************************************************************************* | |
| */ | |
| void delay(int count) | |
| { | |
| int j=0,i=0; | |
| for(j=0;j<count;j++) | |
| { | |
| for(i=0;i<35;i++); | |
| } | |
| } | |
| /** | |
| ******************************************************************************************** | |
| Function Name : key_init() | |
| Description : | |
| Input : | |
| Output : Void | |
| Note : | |
| ******************************************************************************************** | |
| */ | |
| void keypad_init() | |
| { | |
| KEYPAD_DATA_DIR &= ~(ROW_MASK | COL_MASK); | |
| KEYPAD_DATA_DIR |= COL_MASK; | |
| EXTMODE = EXTMODE_EXTMODE1_MASK; | |
| EXTPOLAR &= ~EXTPOLAR_EXTPOLAR1_MASK; | |
| PINSEL0 = (PINSEL0 & ~(3 << 28)) | (1 << 29); | |
| /* Initilize Interrupt Vector */ | |
| VICIntSelect &= ~VIC_BIT(VIC_EINT1); | |
| VICVectAddr5 = (unsigned int)Ext_ISR; | |
| VICVectCntl5 = VIC_ENABLE | VIC_EINT1; | |
| VICIntEnable = VIC_BIT(VIC_EINT1); // EINT0 interrupt enabled | |
| EXTINT &= ~EXTINT_EINT1_MASK; | |
| } | |
| /** | |
| ******************************************************************************************** | |
| Function Name : Ext_ISR() | |
| Description : | |
| Input : | |
| Output : Void | |
| Note : | |
| ******************************************************************************************** | |
| */ | |
| void Ext_ISR() __irq | |
| { | |
| turn_on_buzzer(); | |
| delay(100); | |
| turn_off_buzzer(); | |
| EXTINT |= EXTINT_EINT1_MASK; //Clear Interrupt | |
| VicVectAddr = 0; | |
| } | |
| } | |
| /********************************end of ext_int.c ****************************/ | |
| /*****************************Start of buzzer.h *********************************/ | |
| #ifndef _BUZZER_H | |
| #define BUZZER_H | |
| void turn_on_buzzer(void); | |
| void turn_off_buzzer(void); | |
| #endif //BUZZER_H | |
| /********************************End of Buzzer.h function***********************/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment