新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > LPC1114_外部中斷程序_MDK編譯環(huán)境

LPC1114_外部中斷程序_MDK編譯環(huán)境

作者: 時間:2016-11-29 來源:網(wǎng)絡(luò) 收藏
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延時函數(shù)
{
u16 i;
while(Time)
{
for(i=0;i<3000000;i++);
Time--;
}
}
void Delay_Ms(unsigned int Time) //1Ms*Time延時函數(shù)
{
u16 i;
while(Time)
{
for(i=0;i<3000;i++);
Time--;
}
}
void Delay_Us(unsigned int Time) //1Us*Time延時函數(shù)
{
u8 i;
while(Time)
{
for(i=0;i<3;i++);
Time--;
}
}
int main(void)
{
//SystemInit(); //系統(tǒng)初始化--主要是設(shè)置主時鐘
//GPIOInit(); //IO口初始化--主要是開啟GPIO時鐘
//GPIOSetDir( 0, 3, 1 ); //設(shè)置P0.3為輸出(LPC1114單片機,輸出需設(shè)置為1,輸入需設(shè)置為0)
LPC_GPIO0->DIR |= (0x1<<3); //設(shè)置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); //設(shè)置P1.8為輸入
}
void Key_Intrrupt_Init(void)
{
/*********配置中斷*********/
GPIOSetInterrupt(1,8,1,0,0); //P1.8低電平觸發(fā)中斷
/*********使能中斷*********/
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;
}


評論


技術(shù)專區(qū)

關(guān)閉