int main(void)
{char text[]={"dddddd"};
ARMTargetInit();
Init_Timer3(255,4,65535,0);
while(1){
Uart_SendString(0,text);
Start_Timer3();
INTS_OFF();
SetISR_Interrupt(INT_TIMER3_OFFSET,Timer3_ISR,0);
Open_INT_GLOBAL();
Open_INT(BIT_TIMER3);
INTS_ON(); }
return(0);
}
定时器中断程序:
void Timer3_ISR(void)
{int Timer3INTCount=0;
Timer3INTCount++;
if(Timer3INTCount>=30)
{
rTCON&=~(0x01<<19); //DISABLE AUTO RELOAD
Close_INT(BIT_TIMER3);}
}
void Start_Timer3(void)
{ rTCON|=(0x01<<17);//Manual Update
rTCON&=~(0x01<<18);//Inverter off
rTCON|=(0x01<<16);//Start Timer3
rTCON&=~(0x01<<17);//Must clear Manual update bit
void Init_Timer3(U8 prescaler1,U8 divider3,U16 countb3,U16 compb3)
{ U8 div;
switch(divider3)
{case 2: div=0x00;break;
case 4: div=0x01;break;
case 8: div=0x02;break;
case 16: div=0x03;break;
default: div=0x04;
rTCFG0&=~(0xff<<8);
rTCFG0|=(prescaler1<<8);
rTCFG1&=~(0x0f<<24|0x0f<<12);
rTCFG1|=(div<<12);
rTCMPB3=compb3;
rTCNTB3=countb3;
rTCON|=(0x01<<19);//Auto reload
}
void SetISR_Interrupt(int vector, void (*handler)(), int ExInt)
{
if(vector==EINT4567_OFFSET){
InterruptHandlers[vector] = ExInt4567;
ExInt4567Handlers[ExInt] = handler;
}
else {
InterruptHandlers[vector] = handler;
}
}