STM8S 窗口看门狗

.h文件如下:
 


#ifndef __WWDG_H
#define __WWDG_H
#include "stm8s.h"
void Delay(); 
void WWDG_Configuration(void) ;

void Refresh_WWDG_Window(void);
#endif

.c文件如下:


 

#include "wwdg.h"
#include "stm8s_wwdg.h"

#define CounterInit 0x7f
#define window      0x77

void Delay()   //延迟函数
{
    int i,j;
        for(i=0;i<100;i++)
      {
    for(j=0;j<1000;j++);
          }
}


void WWDG_Configuration(void) 
{
    /* WWDG Configuration */
    /* Watchdog Window= 0x7F step to 0x3F step
    = (0x7F-0x3F) * 1 step
    = 64 * 1 step
    = 64 * (12288/2Mhz)
    = 393.216ms
    */
    /* Allowed Window = (0x7F-window) * 1 step
    = (0x7F-0x77) * 1 step
    = 7 * 1 step 
    = 7 * (12288/2Mhz) 
    = 43.008ms 
    */
    /* So the non allowed window starts from 0.0ms to 43.008ms
    and the alowed window starts from 43.008ms to 393.216ms */
    WWDG_Init(CounterInit,window);
}


void Refresh_WWDG_Window(void)//喂狗
{
  u8 CounterValue;
  CounterValue = (u8)(WWDG_GetCounter() & 0x7F);
  
  if(CounterValue < window)
  {
    WWDG_SetCounter(CounterInit);
  }
}

 

你可能感兴趣的:(STM8)