⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 watchdogrtc.c

📁 矿工定位系统单端
💻 C
字号:
//watchdogrtc.c - code recommendation for C header file
/***********************************************************************
MODULE:    Watchdog and Real Time Clock Common Code
VERSION:   1.00
CONTAINS:  Routines for controlling the Watchdog and Real Time Clock/
           System Timer common interrupt on the Philips P89LPC932
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 "Feb 24 2004" at "16:21:01" by Code Architect 2.03
***********************************************************************/

// SFR description needs to be included
#include<REG922.h>
extern bit T_flag ;
/***********************************************************************
DESC:    Initializes and enables Watchdog and Real Time Clock interrupt
RETURNS: Nothing
CAUTION: Set EA to 1 to enable interrupts after calling
************************************************************************/
void watchdogrtc_isrinit(void)
{
  // set isr priority to 0
  IP0 &= 0xBF;
  IP0H &= 0xBF;

  // enable interrupt
  EWDRT = 1;
}

/***********************************************************************
DESC:    Watchdog and Real Time Clock Interrupt Service Routine
RETURNS: Nothing
CAUTION: RTC or Watchdog initialization functions must be called and EA
         must be set to 1 to enable interrupts
************************************************************************/
void watchdogrtc_isr(void) interrupt 10 using 1
{
  // check if interrupt caused by real time clock
  if (RTCCON & 0x80)
  {
    // clear RTCF interrupt flag
    RTCCON &= ~0x80;
	T_flag=1;

  }
  // check if interrupt caused by watchdog
  if (WDCON & 0x02)
  {
    // clear WDOTF interrupt flag
    WDCON &= ~0x02;
  }
}



/***********************************************************************
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 = 0xC2;
  eacopy = EA;
  EA = 0;
  WDCON = 0xC5;
  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;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -