看门狗定时器和一般定时器相同。仅仅一般定时器一般是段一段时刻,待时刻完毕后,进入中止处理程序中,而看门狗在界说的时刻完毕时,并不期望中止发生,为了避免中止发生,就要在中止发生前,对看门狗定时器某些寄存器进行从头赋值,使它从头开端计数,俗称喂狗操作。
WATCHDOG定时器所触及的寄存器如下:
1、WTCON寄存器
用于设置预分频系数、挑选作业频率、决议是否使能中止、是否启用WATDOG功用(即是否输出复位信号)。
WATDOG定时器作业频率=PCLK/(prescaler value+1)/(divider value)
prescaler value=0~255;
divider value=16,32,64,128;
芯片手册中的WTCON如下图:
#include “2440addr.h”
#define U32 unsigned int
void Delay(int a)
{
int k;
for(k=0;k
;
}
void __irq watchdog(void)
{
rGPBDAT |= 1; /*蜂鸣器响*/
/*清中止标志位*/
/*留意接下来这两行代码。一般来说中止标志铲除次序为:SUBSRCPND–>SRCPND–>INTPND。可是在用CodeWarrior调用AXD调试过程中,并没有由于其先后次序不同而呈现中止,可是当我点击STOP键,之后再点击GO键时,每一次都会听到蜂鸣,这个现象是后来发现的,是不是每次STOP之后,相当于直接发生中止信号,致使不能正常喂狗?这儿不是很了解,期望哪位达人给予解说*/
rSRCPND = 0x1<<9;
rSUBSRCPND = 0x1<<13;
rINTPND = 0x1<<9;
}
void Main(void)
{
int light;
int temp;
int i;
rGPBCON = 0x155555; /*B0输出,给蜂鸣器;B5~B8输出,给LED*/
rGPBUP = 0x7ff;
rWTCON = 0xf9<<8;/*设置预分频系数[15:8],以及时钟挑选[4:3]。PCLK=50MHz Prescaler = 15*16+9=249, Division = WTCON[4:3]=0b00=16,时钟频率为12.5kHz*/
rWTDAT = 50000; /*设置看门狗定时器超时时刻为4秒(50÷12.5)*/
rWTCNT = 50000;
rWTCON |= (1<<5)|(1<<2); /*敞开定时器[5],中止使能[2],不宣布复位信号[0]*/
/*中止设置,看门狗有子中止源*/
rSRCPND = 0x1<<9;
rSUBSRCPND = 0x1<<13;
rINTPND = 0x1<<9;
rINTSUBMSK = ~(0x1<<13);
rINTMSK = ~(0x1<<9);
pISR_WDT_AC97 = (U32)watchdog;
light = 0x000;
temp = light | 1;
rGPBDAT = ~temp;
Delay(500000); /*大约延时0.4S*/
while(1)
{
for(i=0;i<4;i++)
{
light = 1<<(5+i);
temp = light | 1;
rGPBDAT = ~temp;
Delay(500000);
if(i>=2)
{
light = 1<<(4+2*i);
temp = light | 1;
rGPBDAT = ~temp;
Delay(500000);
}
}
rWTCNT = 50000; /*喂狗,从头赋值,避免中止*/
for(i=0;i<4;i++)
{
light = 1>>(5+i);
temp = light | 1;
rGPBDAT = ~temp;
Delay(500000);
if(i>=2)
{
light = 1>>(4+2*i);
temp = light | 1;
rGPBDAT = ~temp;
Delay(500000);
}
}
}
}