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

📄 watchdog.c

📁 这本书里共11章
💻 C
字号:
/*------------------------------------------------------------------------------
watchDog.c : Sample Program that demonstrates the watchdog timer for the
following microcontrollers

Dallas Semiconductor DS80C320
Dallas Semiconductor DS80C323

Copyright (c) 1988-2001 Keil Elektronik GmbH and Keil Software, Inc.
All rights reserved.
--------------------------------------------------------------------------*/

#include <stdio.h>

sfr WDCON  = 0xD8;
sfr CKCON  = 0x8E;
sfr TA     = 0xC7;

sfr SCON0  = 0x98;
sfr TMOD   = 0x89;
sfr TH1    = 0x8D;
sbit TR1   = 0x88^6;
sbit TI    = SCON0^1;


//Set bit WDCON.1 to reset timer 
void reset_Watchdog( void )
{
  WDCON |= 0x02;
}


/*------------------------------------------------------------------------------
main() : Runs a while loop that simulated a condition that will cause the 
		 watchdog timer to reset the microcontroller
------------------------------------------------------------------------------*/
void main( void )
{

  int i;

  /*------------------------------------------------
	Setup the serial port for 1200 baud at 16MHz.
	------------------------------------------------*/
    SCON0 = 0x50;		        /* SCON: mode 1, 8-bit UART, enable rcvr      */
    TMOD |= 0x20;               /* TMOD: timer 1, mode 2, 8-bit reload        */
    TH1   = 221;                /* TH1:  reload value for 1200 baud @ 16MHz   */
    TR1   = 1;                  /* TR1:  timer 1 run                          */
    TI    = 1;                  /* TI:   set TI to send first char of UART    */  

  if(  WDCON & 0x04 )
  {
    printf("Watchdog Reset Occured\n");
	WDCON &= ~0x04;
  }

  WDCON |= 0x01;		//Enable the Watchdog timer
  CKCON |= 0xC0;		//Set rest time to 2684.38ms

  TA = 0xAA;			//Accessing timed access in order to start the watchdog timer
  TA = 0x55;			//

  WDCON |= 0x02;		//Start watch dog timer

  for( i = 0; i < 500; i++)
  {
    reset_Watchdog();
  }

  while(1)
  {
  	//Simulating a error that would cause the watchdog timer to reset processor
  }
}

⌨️ 快捷键说明

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