(基础外围设备)WatchDog

2018-08-31  本文已影响4人  昨天剩下的一杯冷茶

#include "watchdog.h"

void InitWatchDog(void)
{
  WDCTL = 0x00;
  WDCTL |= BV(3);
  WDCTL &= ~ ((BV(0)|BV(1)));
  
}



void FeetDog(void)
{
  WDCTL = 0xa0;
  WDCTL = 0x50;
  
}


//头文件===============================
#ifndef __WATCH_DOG_H__
#define __WATCH_DOG_H__

#include "all.h"

void InitWatchDog(void);
void FeetDog(void);

#endif

//例子=================================

#include "all.h" 
#include "uart.h"
#include "watchdog.h"

typedef unsigned char uint8;
typedef unsigned short int  uint16;

void DelayMS(uint16 msec)
{ 
    uint16 i,j;
    
    for (i=0; i<msec; i++)
        for (j=0; j<536; j++);
}
void main(void)
{   
  char p_buf[]="hello world\r\n\r\n";

  CLKCONCMD &= ~0x40;               //设置系统时钟源为32MHZ晶振
  while(CLKCONSTA & 0x40);          //等待晶振稳定
  CLKCONCMD &= ~0x47;               //设置系统主时钟频率为32MHZ   

  InitLed();
  InitKey();
  Uart_Init(UART_BAUDRATE_115200);
  Uart_String(p_buf);
  SemEmpty();
  InitWatchDog();
  FeetDog();
  Uart_String("InitWatchDog\r\n");
  DelayMS(500);
  
  FeetDog();
  Uart_String("FeetDog\r\n");
  DelayMS(500);
  
  FeetDog();
  Uart_String("FeetDog\r\n");
  DelayMS(500);
  while(1)                     //死循环
  {
  
  }

      
}






TICC2541喂狗时间最长只能设置为1S,喂狗有点平凡。

上一篇下一篇

猜你喜欢

热点阅读