凌陽16位單片機(jī)之IRQ6中斷
實(shí)現(xiàn)功能:利用IRQ6的兩個(gè)時(shí)基中斷,即IRQ6_TMB1和IRQ6_TMB2中斷,在各自的中斷服務(wù)程序中對相應(yīng)的變量進(jìn)行累加;并通過點(diǎn)亮、熄滅發(fā)光二極管來表示相應(yīng)變量計(jì)數(shù)器累加的速度。
實(shí)驗(yàn)現(xiàn)象:D4~D7四個(gè)發(fā)光二極管狀態(tài)變化周期為4s,D8~D11四個(gè)發(fā)光二極管狀態(tài)變化周期為2s
#include "SPCE061A.H"
#define sec1 0x00f0
#define sec2 0x000f
unsigned int i,Output,tim1=0,tim2=0;
void IRQ6(void)__attribute__((ISR));
void IRQ6()
{
if(*P_INT_Ctrl & C_IRQ6_TMB1)
{
tim1++;
if(tim1 >= 64*2)
{
tim1=0;
if((*P_IOA_Data & sec1) == 0)
{
*P_IOA_Data += sec1;
}
else
{
*P_IOA_Data-=sec1;
}
}
*P_INT_Clear = C_IRQ6_TMB1;
}
if(*P_INT_Ctrl & C_IRQ6_TMB2)
{
tim2++;
if(tim2 >= 64*2)
{
tim2=0;
if(!(*P_IOA_Data &sec2))
{
*P_IOA_Data += sec2;
}
else
{
*P_IOA_Data-=sec2;
}
}
*P_INT_Clear = C_IRQ6_TMB2;
}
}
int main()
{
__asm("FIQ OFF");
*P_IOA_Dir = 0x00ff;
*P_IOA_Attrib = 0x00ff;
*P_IOA_Data = 0x0000;
*P_Timebase_Setup = (C_TMB1_64Hz+C_TMB2_128Hz);
*P_INT_Ctrl = C_IRQ6_TMB1+C_IRQ6_TMB2; //Tim1是64Hz Tim2是128Hz
__asm("INT IRQ");
while(1)
{
*P_Watchdog_Clear = 0x0001;
}
}
評論