watchdog.c

来自「This program shows how to configure the 」· C语言 代码 · 共 66 行

C
66
字号
/*------------------------------------------------------------------------------
watchdog.c : Sample Program that demonstrates the watchdog timer for the
following microcontrollers

Atmel Wireless & uC 80C51RA2
Atmel Wireless & uC 80C51RD2
Atmel Wireless & uC 80C54X2
Atmel Wireless & uC 80C58X2
Atmel Wireless & uC 83/87C51RB2
Atmel Wireless & uC 83/87C51RC2
Atmel Wireless & uC 83/87C51RD2
Atmel Wireless & uC T87C5111
Atmel Wireless & uC T87C5112
Atmel Wireless & uC T89C51AC2
Atmel Wireless & uC T89C51CC01
Atmel Wireless & uC T89C51CC02
Atmel Wireless & uC T89C51IB2
Atmel Wireless & uC T89C51IC2
Atmel Wireless & uC T89C51RB2
Atmel Wireless & uC T89C51RC2
Atmel Wireless & uC T89C51RD2

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

sfr  WDTRST  =   0xA6;			 
sfr  WDTPRG  =   0xA7;			 

/*------------------------------------------------------------------------------
rst_Watchdog() : Resets the watchdog timer to avoid microcontroller reset
				   This is done by writing to the WDTRST sfr with 0x1E and 
				   then 0xE1.  This will reset the timer to 0x0.
------------------------------------------------------------------------------*/
void rst_Watchdog( void )
{
	WDTPRG |= 0x07;
	WDTRST  = 0x1E;
    WDTRST  = 0xE1;
}

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

	// Sets the watchdog time to reset after 2^21 - 1 clock cycles 
	

	rst_Watchdog();
	
	//Reset Watchdog to ensure timer doesn't reset
	for( i = 0; i < 500; i++)
	{
		rst_Watchdog();
	}

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

⌨️ 快捷键说明

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