کد:
/************************************************************************************ Code created using the ARMwizard, visit http://alexan.edaboard.eu
************************************************************************************/
#include <LPC17xx.h>
void delay (unsigned long tick) { /* Delay Function */
unsigned long dly = tick*300;
while(dly--);
}
/******************************************************************************
External Interrupt 0 Interrupt service function
******************************************************************************/
void EINT0_IRQHandler(void) {
/* write code here */
LPC_GPIO0->FIOSET=0x00000001;
delay(2000);
LPC_GPIO0->FIOCLR=0x00000001;
delay(2000);
LPC_SC->EXTINT = (1UL<<0); /* Clear EINT0 interrupt flag */
}
/******************************************************************************
External Interrupt 1 Interrupt service function
******************************************************************************/
void EINT1_IRQHandler(void) {
/* write code here */
LPC_GPIO0->FIOSET=0x00000001;
delay(2000);
LPC_GPIO0->FIOCLR=0x00000001;
delay(2000);
LPC_GPIO0->FIOSET=0x00000001;
delay(2000);
LPC_GPIO0->FIOCLR=0x00000001;
delay(2000);
LPC_SC->EXTINT = (1UL<<1); /* Clear EINT1 interrupt flag */
}
/******************************************************************************
External Interrupt 2 Interrupt service function
******************************************************************************/
void EINT2_IRQHandler(void) {
/* write code here */
LPC_GPIO0->FIOSET=0x00000001;
delay(2000);
LPC_GPIO0->FIOCLR=0x00000001;
delay(2000);
LPC_GPIO0->FIOSET=0x00000001;
delay(2000);
LPC_GPIO0->FIOCLR=0x00000001;
delay(2000);
LPC_GPIO0->FIOSET=0x00000001;
delay(2000);
LPC_GPIO0->FIOCLR=0x00000001;
delay(2000);
LPC_SC->EXTINT = (1UL<<2); /* Clear EINT2 interrupt flag */
}
/******************************************************************************
External Interrupt 3 Interrupt service function
******************************************************************************/
void EINT3_IRQHandler(void) {
/* write code here */
LPC_GPIO0->FIOSET=0x00000001;
delay(2000);
LPC_GPIO0->FIOCLR=0x00000001;
delay(2000);
LPC_GPIO0->FIOSET=0x00000001;
delay(2000);
LPC_GPIO0->FIOCLR=0x00000001;
delay(2000);
LPC_GPIO0->FIOSET=0x00000001;
delay(2000);
LPC_GPIO0->FIOCLR=0x00000001;
delay(2000);
LPC_GPIO0->FIOSET=0x00000001;
delay(2000);
LPC_GPIO0->FIOCLR=0x00000001;
delay(2000);
LPC_SC->EXTINT = (1UL<<3); /* Clear EINT3 interrupt flag */
}
int main(void)
{
LPC_GPIO0->FIODIR = 0x000000FF;
/*
P0.0: PORT0.0 (General purpose I/O) Input, pull-up resistor enabled
P0.1: PORT0.1 (General purpose I/O) Input, pull-up resistor enabled
P0.2: PORT0.2 (General purpose I/O) Input, pull-up resistor enabled
P0.3: PORT0.3 (General purpose I/O) Input, pull-up resistor enabled
P0.4: PORT0.4 (General purpose I/O) Input, pull-up resistor enabled
P0.5: PORT0.5 (General purpose I/O) Input, pull-up resistor enabled
P0.6: PORT0.6 (General purpose I/O) Input, pull-up resistor enabled
P0.7: PORT0.7 (General purpose I/O) Input, pull-up resistor enabled
P0.8: PORT0.8 (General purpose I/O) Input, pull-up resistor enabled
P0.9: PORT0.9 (General purpose I/O) Input, pull-up resistor enabled
P0.10: PORT0.10 (General purpose I/O) Input, pull-up resistor enabled
P0.11: PORT0.11 (General purpose I/O) Input, pull-up resistor enabled
P0.15: PORT0.15 (General purpose I/O) Input, pull-up resistor enabled
P0.16: PORT0.16 (General purpose I/O) Input, pull-up resistor enabled
P0.17: PORT0.17 (General purpose I/O) Input, pull-up resistor enabled
P0.18: PORT0.18 (General purpose I/O) Input, pull-up resistor enabled
P0.19: PORT0.19 (General purpose I/O) Input, pull-up resistor enabled
P0.20: PORT0.20 (General purpose I/O) Input, pull-up resistor enabled
P0.21: PORT0.21 (General purpose I/O) Input, pull-up resistor enabled
P0.22: PORT0.22 (General purpose I/O) Input, pull-up resistor enabled
P0.23: PORT0.23 (General purpose I/O) Input, pull-up resistor enabled
P0.24: PORT0.24 (General purpose I/O) Input, pull-up resistor enabled
P0.25: PORT0.25 (General purpose I/O) Input, pull-up resistor enabled
P0.26: PORT0.26 (General purpose I/O) Input, pull-up resistor enabled
P0.27: PORT0.27 (General purpose I/open-drain O) Input
P0.28: PORT0.28 (General purpose I/open-drain O) Input
P0.29: PORT0.29 (General purpose I/O) Input
P0.30: PORT0.30 (General purpose I/O) Input
P1.0: PORT1.0 (General purpose I/O) Input, pull-up resistor enabled
P1.1: PORT1.1 (General purpose I/O) Input, pull-up resistor enabled
P1.4: PORT1.4 (General purpose I/O) Input, pull-up resistor enabled
P1.8: PORT1.8 (General purpose I/O) Input, pull-up resistor enabled
P1.9: PORT1.9 (General purpose I/O) Input, pull-up resistor enabled
P1.10: PORT1.10 (General purpose I/O) Input, pull-up resistor enabled
P1.14: PORT1.14 (General purpose I/O) Input, pull-up resistor enabled
P1.15: PORT1.15 (General purpose I/O) Input, pull-up resistor enabled
P1.16: PORT1.16 (General purpose I/O) Input, pull-up resistor enabled
P1.17: PORT1.17 (General purpose I/O) Input, pull-up resistor enabled
P1.18: PORT1.18 (General purpose I/O) Input, pull-up resistor enabled
P1.19: PORT1.19 (General purpose I/O) Input, pull-up resistor enabled
P1.20: PORT1.20 (General purpose I/O) Input, pull-up resistor enabled
P1.21: PORT1.21 (General purpose I/O) Input, pull-up resistor enabled
P1.22: PORT1.22 (General purpose I/O) Input, pull-up resistor enabled
P1.23: PORT1.23 (General purpose I/O) Input, pull-up resistor enabled
P1.24: PORT1.24 (General purpose I/O) Input, pull-up resistor enabled
P1.25: PORT1.25 (General purpose I/O) Input, pull-up resistor enabled
P1.26: PORT1.26 (General purpose I/O) Input, pull-up resistor enabled
P1.27: PORT1.27 (General purpose I/O) Input, pull-up resistor enabled
P1.28: PORT1.28 (General purpose I/O) Input, pull-up resistor enabled
P1.29: PORT1.29 (General purpose I/O) Input, pull-up resistor enabled
P1.30: PORT1.30 (General purpose I/O) Input, pull-up resistor enabled
P1.31: PORT1.31 (General purpose I/O) Input, pull-up resistor enabled
P2.0: PORT2.0 (General purpose I/O) Input, pull-up resistor enabled
P2.1: PORT2.1 (General purpose I/O) Input, pull-up resistor enabled
P2.2: PORT2.2 (General purpose I/O) Input, pull-up resistor enabled
P2.3: PORT2.3 (General purpose I/O) Input, pull-up resistor enabled
P2.4: PORT2.4 (General purpose I/O) Input, pull-up resistor enabled
P2.5: PORT2.5 (General purpose I/O) Input, pull-up resistor enabled
P2.6: PORT2.6 (General purpose I/O) Input, pull-up resistor enabled
P2.7: PORT2.7 (General purpose I/O) Input, pull-up resistor enabled
P2.8: PORT2.8 (General purpose I/O) Input, pull-up resistor enabled
P2.9: PORT2.9 (General purpose I/O) Input, pull-up resistor enabled
P2.10: EINT0 (External interrupt 0 input), pull-up resistor enabled
P2.11: EINT1 (External interrupt 1 input), pull-up resistor enabled
P2.12: EINT2 (External interrupt 2 input), pull-up resistor enabled
P2.13: EINT3 (External interrupt 3 input), pull-up resistor enabled
P3.25: PORT3.25 (General purpose I/O) Input, pull-up resistor enabled
P3.26: PORT3.26 (General purpose I/O) Input, pull-up resistor enabled
P4.28: PORT4.28 (General purpose I/O) Input, pull-up resistor enabled
P4.29: PORT4.29 (General purpose I/O) Input, pull-up resistor enabled
*/
LPC_SC->PCONP = (LPC_SC->PCONP & 0xEFEFF7DE) | (1UL<<15); /* Enable peripheral clock for IOCON, GPIO, GPIO interrupts (default is enabled) */
LPC_PINCON->PINSEL0 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_PINCON->PINMODE0 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
//LPC_GPIO0->FIODIR = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_PINCON->PINMODE_OD0 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_PINCON->PINSEL1 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_PINCON->PINMODE1 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_PINCON->PINSEL2 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_PINCON->PINMODE2 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_GPIO1->FIODIR = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_PINCON->PINMODE_OD1 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_PINCON->PINSEL3 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_PINCON->PINMODE3 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_PINCON->PINSEL4 = 0x05500000; /* binary: 00000101_01010000_00000000_00000000 */
LPC_PINCON->PINMODE4 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_GPIO2->FIODIR = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_PINCON->PINMODE_OD2 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_PINCON->PINSEL7 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_PINCON->PINMODE7 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_GPIO3->FIODIR = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_PINCON->PINMODE_OD3 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_PINCON->PINSEL9 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_PINCON->PINMODE9 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_GPIO4->FIODIR = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
LPC_PINCON->PINMODE_OD4 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
/******************************************************************************
External interrupts
*******************************************************************************
Ext. interrupt 0 mode: Edge sensitivity / Rising edge
Ext. interrupt 1 mode: Edge sensitivity / Rising edge
Ext. interrupt 2 mode: Edge sensitivity / Rising edge
Ext. interrupt 3 mode: Edge sensitivity / Rising edge
*/
LPC_SC->EXTMODE = 0x0F; /* binary: 00001111 */
LPC_SC->EXTPOLAR = 0x0F; /* binary: 00001111 */
LPC_SC->EXTINT = 0x0F; /* clear the external interrupt flags */
/******************************************************************************
Vectored Interrupt initialization
******************************************************************************/
NVIC_SetPriority(EINT0_IRQn,0); /* Default priority group 0, can be 0(highest) - 31(lowest) */
NVIC_EnableIRQ(EINT0_IRQn); /* Enable External Interrupt 0 Interrupt */
NVIC_SetPriority(EINT1_IRQn,0); /* Default priority group 0, can be 0(highest) - 31(lowest) */
NVIC_EnableIRQ(EINT1_IRQn); /* Enable External Interrupt 1 Interrupt */
NVIC_SetPriority(EINT2_IRQn,0); /* Default priority group 0, can be 0(highest) - 31(lowest) */
NVIC_EnableIRQ(EINT2_IRQn); /* Enable External Interrupt 2 Interrupt */
NVIC_SetPriority(EINT3_IRQn,0); /* Default priority group 0, can be 0(highest) - 31(lowest) */
NVIC_EnableIRQ(EINT3_IRQn); /* Enable External Interrupt 3 Interrupt */
while(1)
{
}
}