哪位仁兄帮我解决一下,吾不胜感激。
屏蔽掉void WDT_IRQHandler(void)的WDT->WTCR.WTR = 1;这句,代码死循环后WDT没有令其重启。
代码如下
/*---------------------------------------------------------------------------------------------------------*/
/* */
/* Copyright(c) 2009 Nuvoton Technology Corp. All rights reserved. */
/* */
/*---------------------------------------------------------------------------------------------------------*/
#include <stdio.h>
#include <string.h>
#include "NUC1xx.h"
#include "Driver\DrvSYS.h"
#include "Driver\DrvGPIO.h"
#include "Driver\DrvUART.h"
//static uint16_t TimerCounter=0;
//static uint8_t Alarm_E=1;
//static uint32_t WDTCOUN=0;
void Delay(int count);
static uint32_t WDTCOUN=0;
/*------- WDT ----------------------------------------------*/
void InitWDT(void)
{
NVIC_DisableIRQ(WDT_IRQn); //Disable WDT interrupt
outpw(&WDT->WTCR ,0 ); //Disable WDT
UNLOCKREG();
/* Step 1. Enable and Select WDT clock source */
SYSCLK->CLKSEL1.WDT_S =3;//Select 10Khz for WDT clock source
SYSCLK->APBCLK.WDT_EN =1;//Enable WDT clock source
/* Step 2. Select Timeout Interval */
WDT->WTCR.WTIS=5;//Select level 7
/* Step 3. Enable Watchdog Timer Reset function */
WDT->WTCR.WTRE = 1;
/* Step 4. Enable WDT interrupt */
WDT->WTCR.WTIF =1;//Write 1 to clear for safety
WDT->WTCR.WTIE = 1;
NVIC_EnableIRQ(WDT_IRQn);
/* Step 5. Enable WDT module */
//Enable WDT
WDT->WTCR.WTE = 1;
//Clear WDT counter
//WDT->WTCR.WTR = 1;
LOCKREG();
}
void WDT_IRQHandler(void)
{
UNLOCKREG();
WDT->WTCR.WTIF =1;
WDTCOUN++;
if (WDTCOUN<10) WDT->WTCR.WTR=1; //Wait 10 times
WDT->WTCR.WTR = 1;
LOCKREG();
printf("WDT interrupt\n");
}
/*----------------------------------------------------------------------------
MAIN function
----------------------------------------------------------------------------*/
int32_t main (void)
{
STR_UART_T sParam;
UNLOCKREG();
SYSCLK->PWRCON.XTL32K_EN = 1;//Enable 32Khz for RTC clock source
SYSCLK->PWRCON.XTL12M_EN = 1;
SYSCLK->CLKSEL0.HCLK_S = 0;
LOCKREG();
/* Set UART Pin */
DrvGPIO_InitFunction(E_FUNC_UART0);
/* UART Setting */
sParam.u32BaudRate = 115200;
sParam.u8cDataBits = DRVUART_DATABITS_8;
sParam.u8cStopBits = DRVUART_STOPBITS_1;
sParam.u8cParity = DRVUART_PARITY_NONE;
sParam.u8cRxTriggerLevel= DRVUART_FIFO_1BYTES;
/* Set UART Configuration */
if(DrvUART_Open(UART_PORT0,&sParam) != E_SUCCESS)
{
printf("UART0 open failed\n");
return FALSE;
}
printf("\n\n");
printf("+-----------------------------------------------------------+\n");
printf("| Timer_WDT_RTC Sample Program |\n");
printf("+-----------------------------------------------------------+\n");
// InitTIMER0();
// InitRTC();
InitWDT();
/* Synch field transmission & Request Identifier Field transmission*/
while(1);
} |