打印

请教lpc936看门狗配置

[复制链接]
1152|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
六楼的窗户|  楼主 | 2010-1-14 15:59 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
看门狗的初始化、启动、喂狗函数已经写好,已经加入到主程序中具体请见最后代码。
碰到的情况是在minipro 编程器里选中WDT使能,lpc936就无法运行起来。
禁止WDT功能,lpc936就能正常运行(当然没有看门狗功能)。
请问该怎么调整,谢谢。
/***********************************************************************
MODULE:    Watchdog
VERSION:   1.01
CONTAINS:  Routines for controlling the Watchdog on the
           P89LPC922
COPYRIGHT: Embedded Systems Academy, Inc. - www.esacademy.com
LICENSE:   May be freely used in commercial and non-commercial code
           without royalties provided this copyright notice remains
           in this file and unaltered
WARNING:   IF THIS FILE IS REGENERATED BY CODE ARCHITECT ANY CHANGES
           MADE WILL BE LOST. WHERE POSSIBLE USE ONLY CODE ARCHITECT
           TO CHANGE THE CONTENTS OF THIS FILE
GENERATED: On "May 25 2007" at "08:43:39" by Code Architect 2.11
***********************************************************************/

// SFR description needs to be included
#include <reg922.h>
// #include "watchdog.h"

/***********************************************************************
DESC:    Initializes the watchdog as a Watchdog Timer
         Uses Watchdog clock at 400kHz as a clock source
         Resets the device if not fed within 998.888 ms
RETURNS: Nothing
************************************************************************/
void watchdog_init (void)
{
  bit eacopy;

  // init reload value and prescaler
  // select Watchdog clock at 400kHz
  // start watchdog
  WDL = 0xFF;
  eacopy = EA;
  EA = 0;
  WDCON = 0xC1;
  WFEED1 = 0xA5;
  WFEED2 = 0x5A;
  EA = eacopy;
}

/***********************************************************************
DESC:    Feeds the Watchdog to stop the device from resetting
RETURNS: Nothing
CAUTION: watchdog_init must be called first
************************************************************************/
void watchdog_feed  (void)
{
  bit eacopy;

  // disable interrupts
  eacopy = EA;
  EA = 0;
  // feed the watchdog
  WFEED1 = 0xA5;
  WFEED2 = 0x5A;
  // restore interrupts
  EA = eacopy;
}

/***********************************************************************
DESC:    Starts the Watchdog
RETURNS: Nothing
CAUTION: watchdog_init must be called first
************************************************************************/
void watchdog_start (void)
{
  bit eacopy;

  // disable interrupts
  eacopy = EA;
  EA = 0;
  // start the watchdog
  WDCON |= 0x04;
  // feed the watchdog
  WFEED1 = 0xA5;
  WFEED2 = 0x5A;
  // restore interrupts
  EA = eacopy;
}

/***********************************************************************
DESC:    Stops the Watchdog
RETURNS: Nothing
CAUTION: watchdog_init must be called first
************************************************************************/
void watchdog_stop (void)
{
  bit eacopy;

  // disable interrupts
  eacopy = EA;
  EA = 0;
  // stop the watchdog
  WDCON &= ~0x04;
  // feed the watchdog
  WFEED1 = 0xA5;
  WFEED2 = 0x5A;
  // restore interrupts
  EA = eacopy;
}

相关帖子

沙发
6019实验室| | 2010-1-14 16:00 | 只看该作者
看了半天,我也不知道,同问!

使用特权

评论回复
板凳
LPC300| | 2010-1-14 16:01 | 只看该作者
不用启动呀,初始化完就可以在主程中喂狗了,我没有做watchdog_start动作, 不喂就重启。

我和你初始化WDCON有点不同,你查一下。





void init_wdt()
{
   WDL = 0xff; //设置8位倒计时器初值
   WDCON=0xE5;
   WFEED1 = 0xA5; //清零第一部分
   WFEED2 = 0x5A; //清零第二部分
}
void clrwdt() //喂狗
{
  EA = 0; //关闭中断
  WFEED1 = 0xA5; //执行清零第一部分
  WFEED2 = 0x5A; //执行清零第二部分
  EA = 1; //开中断
}

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

102

主题

497

帖子

0

粉丝