main.c #include "LPC11XX.h" #include "gpio.h" #include "timer16.h" #include "main.h" #include "Key.h" #include "LCD.h" void Delay_Sec(unsigned char Time) //1s*Time延时函数 { u16 i; while(Time) { for(i=0;i<3000000;i++); Time--; } } void Delay_Ms(unsigned int Time) //1Ms*Time延时函数 { u16 i; while(Time) { for(i=0;i<3000;i++); Time--; } } void Delay_Us(unsigned int Time) //1Us*Time延时函数 { u8 i; while(Time) { for(i=0;i<3;i++); Time--; } } int main(void) { //SystemInit(); //系统初始化--主要是设置主时钟 //GPIOInit(); //IO口初始化--主要是开启GPIO时钟 //GPIOSetDir( 0, 3, 1 ); //设置P0.3为输出(LPC1114单片机,输出需设置为1,输入需设置为0) LPC_GPIO0->DIR |= (0x1<<3); //设置P0.3为输出 LPC_GPIO2->DIR |= (0x1<<9); Key_GPIO_Init(); Key_Intrrupt_Init(); while(1) { //GPIOSetValue( 0, 3, 0 ); //给P0.3位写0 //LPC_GPIO0->DATA &= ~(0x1<<3); //给P0.3位写0 LCD_RW_High; //for(i=0;i<0xFFFFF;i++); //延时 Delay_Ms(100); //延时 //GPIOSetValue( 0, 3, 1 ); //给P0.3位写1 //LPC_GPIO0->DATA |= (0x1<<3); //给P0.3位写1 LCD_RW_Low; //for(i=0;i<0xFFFFF;i++); //延时 Delay_Ms(100); //延时 } } key.c #include "LPC11XX.h" #include "gpio.h" #include "main.h" #include "Key.h" void Key_GPIO_Init(void) { LPC_GPIO1->DIR &= ~(0x1<<8); //设置P1.8为输入 } void Key_Intrrupt_Init(void) { /*********配置中断*********/ GPIOSetInterrupt(1,8,1,0,0); //P1.8低电平触发中断 /*********使能中断*********/ GPIOIntEnable(1,8); /*********使能中断入口*********/ NVIC_EnableIRQ(EINT1_IRQn); } gpio.c #include "LPC11xx.h" /* LPC11xx Peripheral Registers */ #include "gpio.h" void PIOINT1_IRQHandler(void) { uint32_t regVal; gpio1_counter++; regVal = GPIOIntStatus( 1, 8 ); if ( regVal ) { LPC_GPIO0->MASKED_ACCESS[(1<<3)] = (0<<3); Delay_Ms(2000); LPC_GPIO0->MASKED_ACCESS[(1<<3)] = (1<<3); Delay_Ms(2000); LPC_GPIO0->MASKED_ACCESS[(1<<3)] = (0<<3); Delay_Ms(2000); LPC_GPIO0->MASKED_ACCESS[(1<<3)] = (1<<3); Delay_Ms(2000); //GPIOSetValue( 0, 3, 0 ); //给P0.3位写0 //Delay_Ms(1000); //GPIOSetValue( 0, 3, 1 ); //给P0.3位写0 //Delay_Ms(1000); GPIOIntClear( 1, 8 ); } return; }