LPC2103开发板WDT看门狗测试试验_i++LPC2103开发板WDT看门狗测试试验_i++_02代码
#include "config.h"

#define LED1 (1 << 19)
#define KEY1 (1 << 18)

void DelayNS(uint32 dly)
{
uint32 i;
for(;dly > 0; dly--)
{
for(i = 0; i < 50000; i++);
}
}

void WDTInit(uint32 uiTime)
{
WDTC
= uiTime;
WDMOD
= 0x03;


WDFEED
= 0xaa;
WDFEED
= 0x55;
}

void FeedDog(void)
{
IRQDisable();
WDFEED
= 0xaa;
WDFEED
= 0x55;

IRQEnable();
}

int main(void)
{
uint32 i;
PINSEL0
= 0x00000000;
PINSEL1
= 0x00000000;

IODIR
= LED1;
IOCLR
= LED1;

DelayNS(
100);
IOSET
= LED1;

WDTInit(
0x200000);

while(1)
{
while((IOPIN & KEY1) == 0);
for(i = 0; i < 0xff; i++);
FeedDog();
}
}

 

#include "config.h"

 

#define LED1 (1 << 19)
#define KEY1 (1 << 18)

void DelayNS(uint32 dly)
{
    uint32 i;
    for(;dly > 0; dly--)
    {
        for(i = 0; i < 50000; i++);
    }
}

void WDTInit(uint32 uiTime)
{
    WDTC = uiTime;
    WDMOD = 0x03;
   
   
    WDFEED = 0xaa;
    WDFEED = 0x55;
}

void FeedDog(void)
{
    IRQDisable();
    WDFEED = 0xaa;
    WDFEED = 0x55;
   
    IRQEnable();
}

int main(void)
{
    uint32 i;
    PINSEL0 = 0x00000000;
    PINSEL1 = 0x00000000;
   
    IODIR = LED1;
    IOCLR = LED1;
   
    DelayNS(100);
    IOSET = LED1;
   
    WDTInit(0x200000);
   
    while(1)
    {
        while((IOPIN & KEY1) == 0);
        for(i = 0; i < 0xff; i++);
        FeedDog();
    }
}

 

实验现象,正常情况下:上电后,LED会闪一下。因为定时喂狗,就这样一直不闪了。

我们通过按键来模拟意外事件。

 

当长按住按键时,因为不能定时的喂狗,所以LED就会不停的闪烁。