zigbee CC2530 series of 10 tutorials watchdog experiment

Seeing all links courses:

zigbee CC2530 series of tutorials 0 Courses

 

4.9 Watchdog experiment

4.9.1 Purpose 

1. Learn CC2530 watchdog work;

2. Learning watchdog function operating mechanism in the system;

4.9.2 Introductory Lecture

Have had experience in project development readers should be no stranger to the watchdog, and the watchdog for reliable operation of a system has a vital role, it would in the case of a software program runaway, reset the system, to ensure that the program resumes normal operation, but the premise is timed to feed the dog.

CC2530 watchdog control is simple, involving only the WDCTL to a register, whose function is described below in Table 4-9:

Table 4-9 Watchdog register control-related

System power mode control register PCON (0x87)

Clear the counter value of Bit [7: 4]

 

In watchdog mode, if four successively written within 0xA a watchdog cycle, 0x5, clears the WDT. Referred to feed the dog.

WDT operation mode select register Bit [3: 2]

00

IDLE

01

IDLE (not used)

10

Watchdog mode

11

Timer Mode

Watchdog cycle select register Bit [1: 0]

00

1 second

01

0.25 seconds

10

15.625 ms

11

1.9 ms

The menu related registers described specifically as follows:

Init_Watchdog:

WDCTL = 0x00; // It is necessary to set up a watchdog to open IDLE

WDCTL | = 0x08; // one second time interval, the watchdog mode

FeedDog:

WDCTL = 0xa0; // description by register DOG

WDCTL = 0x50;

Specific procedures are as follows:

#include <ioCC2530.h>



#define uint unsigned int

#define uchar unsigned char



//定义控制LED灯的端口

#define LED1 P1_0

#define LED2 P1_1

//函数声明

void Delayms(uint xms);//延时函数

void InitLed(void);    //初始化P1口

/****************************

//延时函数

*****************************/

void Delayms(uint xms)   //i=xms 即延时i毫秒

{

    uint i,j;

    for(i=xms;i>0;i--)

     for(j=587;j>0;j--);

}

/****************************

//初始化程序

*****************************/

void InitLed(void)

{

    P1DIR |= 0x03; //P1_0、P1_1定义为输出

    LED1 = 1;     //LED1灯熄灭

    LED2 = 1;  //LED2灯熄灭

}

void Init_Watchdog(void)

{

    WDCTL = 0x00; //这是必须的,打开IDLE才能设置看门狗

    WDCTL |= 0x08;

    //时间间隔一秒,看门狗模式  

}

void FeetDog(void)

{

    WDCTL = 0xa0;

    WDCTL = 0x50;

}

/***************************

//主函数

***************************/

void main(void)

{

    InitLed(); //调用初始化函数

    Init_Watchdog();

    LED1=1;

    while(1)

    {         

        LED2=~LED2;           //仅指示作用。

        Delayms(300);

        LED1=0;

        //通过注释测试,观察LED1,系统在不停复位。

        FeetDog();//防止程序跑飞

    }

}

4.8.3 experimental results

In the case where the timing of the dogs, the software program running on D3 (LED1) is powered long bright, D4 (LED2) flashes according delay.

The DOG commented program, the software program will reset the dogs according to a preset frequency, thereby causing D3 (LED1) also flashes at the frequency of the dogs, kept proof system reset.

发布了133 篇原创文章 · 获赞 51 · 访问量 20万+

Guess you like

Origin blog.csdn.net/aa120515692/article/details/104007097