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

📄 watchdog1.c

📁 ADuC系列芯片的源代码事例
💻 C
字号:
/*********************************************************************

 Author        : ADI - Apps            www.analog.com/MicroConverter

 Date          : Sept. 2005

 File          : Watchdog1.c

 Hardware      : Applicable to ADuC702x rev H or I silicon
                 Currently targetting ADuC7026.

 Description   : This example demonstrates the use of the  Watchdog interrupt.
 				 Note that a software reset is required after watchdog interrupt
				 to resume code execution.
				 - on the four first occurences the timer is refreshed/reloaded on time
				 - on the fifth occurence, code is delayed and the timer creates an
				 interrupt
		
*********************************************************************/
#include<aduc7026.h>

void delay(int);
void My_IRQ_Function(void);

int main(void)				
{

char i;
GP1DAT = 0x01000000;			// P1.0 configured as output.
GP4DAT = 0x04000000;			// P4.2 configured as output. LED is turned on	

IRQ = My_IRQ_Function;			// Specify Interrupt Service Rountine

T3LD = 0x1000;			  		// 0x1000/32768 = 125ms
T3CON = 0xE2;    	  			// IRQ instead of reset, for test purposes only

IRQEN = 0x00000020;				// Timer3 IRQ

while (1)
	{
	for (i=0;i<4;i++){
		delay(0x10000);	  		
		T3CLRI = 0xff;
		GP4DAT ^= 0x00040000;
		}
	
	delay(0x80000);	  			// too long delay => gives a watchdog interrupt
	T3CLRI = 0xff;
	GP4DAT ^= 0x00040000;
 	}				
}

void delay (int length)
{
	while (length >=0)
    	length--;
}

/********************************************************************/
/*                                                                  */
/*		Interrupt Service Rountine									*/
/*                                                                  */
/********************************************************************/

void My_IRQ_Function()							
{				
	if ((IRQSTA & WATCHDOG_TIMER_BIT) != 0)	 	// Timer3 IRQ?
	{											// Watchdog interrupt allows saving...
												//... data before reset if necessary
		GP1DAT ^= 0x00010000;					// Complement P1.0
		RSTSTA = 0x4;							// Software reset
	} 				
	return ;
} 

⌨️ 快捷键说明

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