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

📄 wdt.c

📁 CC1110 CC2510 看门狗应用实例工程
💻 C
字号:
/*-------------------------------------*
 *	             头文件               *
 *---------------------------------------------------------------------------*/
 
#include "ioCC1110.h"
#include <stdbool.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#include "Hal.h"

/*-------------------------------------*
 *	             宏定义               *
 *---------------------------------------------------------------------------*/
#define LED_OFF 		 0
#define LED_ON  		 1

#define GLED         	P1_0
#define RLED         	P1_3

#define INIT_LED()  	RLED=1;GLED=1; 	\
  						P1DIR |= 0x09;	\
						P1SEL &=~0x09;	\
                            
#define SET_GLED()   	(GLED = LED_ON )
#define CLR_GLED()   	(GLED = LED_OFF)
#define SET_RLED()   	(RLED = LED_ON )
#define CLR_RLED()   	(RLED = LED_OFF)

// Where _timeout_ is one of
#define SEC_1          0x00     // after 1 second
#define M_SEC_250      0x01     // after 250 ms
#define M_SEC_15       0x02     // after 15 ms
#define M_SEC_2        0x03     // after 2 ms

// Macro for setting the WDT timeout interval.
#define WDT_SET_TIMEOUT_PERIOD(timeout) \
do {  WDCTL &= ~0x03; WDCTL |= timeout; } while (0)

// Macro for resetting the WDT. If this is not done before the WDT times out,
// the system is reset.
#define WDT_RESET() do {           \
   WDCTL = (WDCTL & ~0xF0) | 0xA0; \
   WDCTL = (WDCTL & ~0xF0) | 0x50; \
} while (0)

// Macro for turning on the WDT
#define WDT_ENABLE()   WDCTL |= 0x08
#define WDT_DISABLE()  WDCTL &= ~0x08

/*-------------------------------------*
 *	           函数定义               *
 *---------------------------------------------------------------------------*/
void Reset(void)
{
    // do reset by setting the WDT and waiting for it to timeout
    DISABLE_ALL_INTERRUPTS();  // prevent petting the dog...
    WDT_SET_TIMEOUT_PERIOD(SEC_1);
	WDT_ENABLE(); 
    // enable watchdog and wait for timeout...
    while (1)  {
      asm("NOP");
    }
}

void main(void)
{
	unsigned int i,j;
    
	SET_MAIN_CLOCK_SOURCE(CRYSTAL);
    
	INIT_LED();
    
    for (i=5; i!=0; i--)
    {
      	GLED ^= 1;
		RLED ^= 1; 
      	for (j=50000; j!=0; j--);
    }	
    
	INIT_LED(); 
        
    Reset();
    
   	while(1)
   	{
		; 	
   	}
}

/*------------------------------------------------------------------------------
										  0ooo
								ooo0     (   )
								(   )     ) /
								 \ (     (_/
	    				          \_)        By:cuiqingwei [gary]
------------------------------------------------------------------------------*/

⌨️ 快捷键说明

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