系統(tǒng)時(shí)鐘和定時(shí)器——看門狗定時(shí)器
WATCHDOG定時(shí)器所涉及的寄存器如下:
本文引用地址:http://m.butianyuan.cn/article/201611/316625.htm1、WTCON寄存器
用于設(shè)置預(yù)分頻系數(shù)、選擇工作頻率、決定是否使能中斷、是否啟用WATDOG功能(即是否輸出復(fù)位信號(hào))。
WATDOG定時(shí)器工作頻率=PCLK/(prescaler value+1)/(divider value)
prescaler value=0~255;
divider value=16,32,64,128;
芯片手冊(cè)中的WTCON如下圖:
#include "2440addr.h"
#define U32 unsigned int
void Delay(int a)
{
int k;
for(k=0;k
;
}
void __irq watchdog(void)
{
rGPBDAT |= 1; /*蜂鳴器響*/
/*清中斷標(biāo)志位*/
/*注意接下來這兩行代碼。一般來說中斷標(biāo)志清除順序?yàn)椋篠UBSRCPND-->SRCPND-->INTPND。但是在用CodeWarrior調(diào)用AXD調(diào)試過程中,并沒有因?yàn)槠湎群箜樞虿煌霈F(xiàn)中斷,但是當(dāng)我點(diǎn)擊STOP鍵,之后再點(diǎn)擊GO鍵時(shí),每一次都會(huì)聽到蜂鳴,這個(gè)現(xiàn)象是后來發(fā)現(xiàn)的,是不是每次STOP之后,相當(dāng)于直接產(chǎn)生中斷信號(hào),致使不能正常喂狗?這里不是很理解,希望哪位達(dá)人給予講解*/
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;/*設(shè)置預(yù)分頻系數(shù)[15:8],以及時(shí)鐘選擇[4:3]。PCLK=50MHz Prescaler = 15*16+9=249, Division = WTCON[4:3]=0b00=16,時(shí)鐘頻率為12.5kHz*/
rWTDAT = 50000; /*設(shè)置看門狗定時(shí)器超時(shí)時(shí)間為4秒(50÷12.5)*/
rWTCNT = 50000;
rWTCON |= (1<<5)|(1<<2); /*開啟定時(shí)器[5],中斷使能[2],不發(fā)出復(fù)位信號(hào)[0]*/
/*中斷設(shè)置,看門狗有子中斷源*/
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); /*大約延時(shí)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);
}
}
}
}
評(píng)論