完成功用:使用外部中止来操控8个发光二极管的点亮与平息,使用键盘发生外部中止触发信号。
试验现象:当按S20键时,D8~D11四个发光二极管点亮,当按S21键时,D4~D7四个发光二极管点亮。
#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;
}
}