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

📄 main.c

📁 This example program shows how to configure PCA Module 4 as a watchdog timer. In this example, the
💻 C
字号:
#include <reg51f.h>

/*------------------------------------------------
This function adjusts the watchdog timer compare
value to the current PCA timer value + 0xFF00.

Note that you must write to CCAP4L first, then
write to CCAP4H.
------------------------------------------------*/
void watchdog_reset (void)
{
unsigned int newval;

newval  = (CH << 8) | CL;
newval += 0xFF00;

CCAP4L = newval;
CCAP4H = newval >> 8;
}

/*------------------------------------------------
MAIN C function
------------------------------------------------*/
void main (void)
{
unsigned int i;

/*--------------------------------------
Configure PCA Module 4 as the watchdog
and make sure it doesn't time-out
immediately.
--------------------------------------*/
watchdog_reset ();
CCAPM4 = 0x48;

/*--------------------------------------
Configure the PCA for watchdog timer.
--------------------------------------*/
CMOD = (CMOD & 0x01) | 0x40;

/*--------------------------------------
Start the PCA Timer.

From this point on, we must reset the
watchdog timer every 0xFF00 clock
cycles.  If we don't the watchdog timer
will reset the MCU.
--------------------------------------*/
CR = 1;

/*--------------------------------------
Do something for a while and make sure
that we don't get reset by the watchdog.
--------------------------------------*/
for (i = 0; i < 1000; i++)
  {
  watchdog_reset ();
  }

/*--------------------------------------
Stop updating the watchdog and we should
get reset.
--------------------------------------*/
while (1)
  {
  }
}

⌨️ 快捷键说明

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