完成功用:翻开并设置TimerA和TimerB守时器,并翻开它们的FIQ中止,当有TimerA/B的FIQ中止请求时,呼应相应的中止服务程序,在中止服务中翻转I/O端口输出电平,以操控接在I/O端口的发光二极管的亮灭。
试验现象:TimerA守时长度为2s,当进入TimerA的FIQ中止后,翻转IOA口低四位的输出电平以操控接在IOA低四位端口的发光二极管;TimerB守时长度为1s,当进入TimerB的FIQ中止后,翻转IOB口低四位的输出电平以操控接在IOB低四位端口的发光二极管。程序运行时,能够观察到接在IOA低四位端口的发光二极管亮灭的周期为4s,而接在IOB低四位端口的为2s。
#include “SPCE061A.H”
unsigned int n,Output1=0x00f0,Output2=0x000f;
void FIQ(void)__attribute__((ISR));
void FIQ()
{
if(*P_INT_Ctrl&0x2000)//当是TimerA中止是b13
{
*P_INT_Clear = 0x2000;
Output1^=0xffff;
*P_IOA_Data = Output1;
}
if(*P_INT_Ctrl&0x0800)//当是TimerB中止是b11
{
*P_INT_Clear = 0x0800;
Output2^=0xffff;
*P_IOA_Data = Output2;
}
}
int main()
{
__asm(“FIQ OFF”);
*P_IOA_Dir = 0x00ff;
*P_IOA_Attrib = 0x00ff;
*P_IOA_Data = 0x0000;
*P_TimerA_Ctrl = 0x000d;//挑选了1024HZ的
*P_TimerA_Data = 0xffff-2048;
*P_TimerB_Ctrl = 0x0004;//挑选了4096的
*P_TimerB_Data = 0xffff-4096;
*P_INT_Ctrl = 0x2800;
__asm(“FIQ ON”);
while(1)
{
*P_Watchdog_Clear = 0x0001;
}
}