久久ER99热精品一区二区-久久精品99国产精品日本-久久精品免费一区二区三区-久久综合九色综合欧美狠狠

新聞中心

EEPW首頁 > 嵌入式系統 > 設計應用 > LPC1114外中斷應用

LPC1114外中斷應用

作者: 時間:2016-11-10 來源:網絡 收藏
LPC1114微處理器每一個GPIO都可以中斷,不過在設計中斷時需要注意,下面就舉例說明:

/**************************************************************************************
* global variable
**************************************************************************************/
volatile uint8 KeyValue = 0;

/**************************************************************************************
* FunctionName : KeyInit()
* Description : 初始化按鍵
* EntryParameter : None
* ReturnValue : None
**************************************************************************************/
void KeyInit(void)
{
// 設置為輸入端口
GPIOSetDir(PORT1, KEY1, 0);
GPIOSetDir(PORT1, KEY2, 0);
GPIOSetDir(PORT1, KEY3, 0);
GPIOSetDir(PORT1, KEY4, 0);
GPIOSetDir(PORT1, KEY5, 0);
GPIOSetDir(PORT1, KEY6, 0);

本文引用地址:http://cqxgywz.com/article/201611/317380.htm

// 設置為低電平中斷
GPIOSetInterrupt(PORT1, KEY1, 1, 0, 0);
GPIOSetInterrupt(PORT1, KEY2, 1, 0, 0);
GPIOSetInterrupt(PORT1, KEY3, 1, 0, 0);
GPIOSetInterrupt(PORT1, KEY4, 1, 0, 0);
GPIOSetInterrupt(PORT1, KEY5, 1, 0, 0);
GPIOSetInterrupt(PORT1, KEY6, 1, 0, 0);

// 使能中斷
GPIOIntEnable(PORT1, KEY1);
GPIOIntEnable(PORT1, KEY2);
GPIOIntEnable(PORT1, KEY3);
GPIOIntEnable(PORT1, KEY4);
GPIOIntEnable(PORT1, KEY5);
GPIOIntEnable(PORT1, KEY6);

NVIC_EnableIRQ(EINT1_IRQn); // 使能PORT1中斷
}

/**************************************************************************************
* FunctionName : PIOINT1_IRQHandler()
* Description : 中斷服務函數
* EntryParameter : None
* ReturnValue : None
**************************************************************************************/
void PIOINT1_IRQHandler(void)
{
uint32 key;

key = GPIOIntStatus(PORT1, KEY1);
if (key == 1)
{
KeyValue = K1;
GPIOIntClear(PORT1, KEY1);
return ;
}

key = GPIOIntStatus(PORT1, KEY2);
if (key == 1)
{
KeyValue = K2;
GPIOIntClear(PORT1, KEY2);
return ;
}

key = GPIOIntStatus(PORT1, KEY3);
if (key == 1)
{
KeyValue = K3;
GPIOIntClear(PORT1, KEY3);
return ;
}

key = GPIOIntStatus(PORT1, KEY4);
if (key == 1)
{
KeyValue = K4;
GPIOIntClear(PORT1, KEY4);
return ;
}

key = GPIOIntStatus(PORT1, KEY5);
if (key == 1)
{
KeyValue = K5;
GPIOIntClear(PORT1, KEY5);
return ;
}

key = GPIOIntStatus(PORT1, KEY6);
if (key == 1)
{
KeyValue = K6;
GPIOIntClear(PORT1, KEY6);
return ;
}
}

/**************************************************************************************
* End Of File
**************************************************************************************/

在中斷函數中需要注意的是,如果直接使用如下格式,將無法讀取端口中斷狀態。

if (GPIOIntStatus(PORT1, KEY6) == 1)
{
KeyValue = K6;
GPIOIntClear(PORT1, KEY6);
return ;
}



需要先定義一個臨時變量,讀取端口狀態,再通過變量值進行判斷,此問題已經記過驗證。



關鍵詞: LPC1114外中

評論


技術專區

關閉