新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 凌陽(yáng)16位單片機(jī)之外部中斷

凌陽(yáng)16位單片機(jī)之外部中斷

作者: 時(shí)間:2016-11-20 來(lái)源:網(wǎng)絡(luò) 收藏
實(shí)現(xiàn)功能:利用外部中斷來(lái)控制8個(gè)發(fā)光二極管的點(diǎn)亮與熄滅,利用鍵盤產(chǎn)生外部中斷觸發(fā)信號(hào)。

實(shí)驗(yàn)現(xiàn)象:當(dāng)按S20鍵時(shí),D8~D11四個(gè)發(fā)光二極管點(diǎn)亮,當(dāng)按S21鍵時(shí),D4~D7四個(gè)發(fā)光二極管點(diǎn)亮。

本文引用地址:http://2s4d.com/article/201611/318712.htm

#include "SPCE061A.H"
unsigned int output=0;
void IRQ3(void)__attribute__((ISR));
void IRQ3()
{
unsigned int delay;
*P_IOA_Data = 0x00ff;
if(*P_INT_Ctrl & C_IRQ3_EXT1)
{
*P_IOA_Data = 0x000f;
delay = 0x7fff;
while(delay--);
*P_INT_Clear = C_IRQ3_EXT1;
}
else if(*P_INT_Ctrl & C_IRQ3_EXT2)
{
*P_IOA_Data = 0x00f0;
delay = 0x7fff;
while(delay--);
*P_INT_Clear = C_IRQ3_EXT2;
}
else
{
*P_INT_Clear = C_IRQ3_KEY;
}
}
int main()
{
asm("INT OFF");
*P_IOA_Dir = 0x00ff;
*P_IOA_Attrib = 0x00ff;
*P_IOA_Data = 0x0000;

*P_IOB_Dir = 0x0000;
*P_IOB_Attrib = 0x0000;
*P_IOB_Data = 0x0008+0x0004;

*P_INT_Ctrl = C_IRQ3_EXT1 + C_IRQ3_EXT2;
asm("INT IRQ");
while(1)
{
*P_Watchdog_Clear = 0x0001;
}
}


評(píng)論


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

關(guān)閉