凌陽16位單片機(jī)之外部中斷
實(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://cafeforensic.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)論