打印
[DemoCode下载]

看门狗定时器做中断定时器使用

[复制链接]
515|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
huangcunxiake|  楼主 | 2019-6-30 22:47 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
/*---------------------------------------------------------------------------------------------------------*/
/*                                                                                                         */
/* Copyright(c) 2017 Nuvoton Technology Corp. All rights reserved.                                         */
/*                                                                                                         */
/*---------------------------------------------------------------------------------------------------------*/

//***********************************************************************************************************
//  Nuvoton Technoledge Corp.
//  Website: http://www.nuvoton.com
//  E-Mail : MicroC-8bit@nuvoton.com
//  Date   : Apr/21/2017
//***********************************************************************************************************

//***********************************************************************************************************
//  File Function: N76E003 Watch Dog as pure timer with interrupt demo code
//***********************************************************************************************************
#include "N76E003.h"
#include "Common.h"
#include "Delay.h"
#include "SFR_Macro.h"
#include "Function_define.h"


/************************************************************************************************************
*    WDT interrupt sub-routine
************************************************************************************************************/
void WDT_ISR (void)   interrupt 10
{

                                        //---------toggle GPIO1---------       
                                                clr_GPIO1;
                                                Timer2_Delay500us(5);
                                                set_GPIO1;
                                                Timer2_Delay500us(5);
                                                clr_GPIO1;
                                                Timer2_Delay500us(5);
                                                set_GPIO1;
                                                Timer2_Delay500us(5);
                                        //---------end toggle GPIO2--------
                clr_WDTF;
                set_WDCLR;
}

/************************************************************************************************************
*    Main function
************************************************************************************************************/
void main (void)
{
/* Note
  WDT timer base is LIRC 10Khz
*/
   
  Set_All_GPIO_Quasi_Mode;
       
                                                clr_GPIO1;
                                                Timer0_Delay1ms(500);
                                                set_GPIO1;
                                                Timer0_Delay1ms(500);
                                                clr_GPIO1;
                                                Timer0_Delay1ms(500);
                                                set_GPIO1;
                                                Timer0_Delay1ms(500);
       
//WDT init
//--------------------------------------------------------
//Warning:
//Pleaes always check CONFIG WDT disable first
//only when WDT reset disable, WDT use as pure timer
//--------------------------------------------------------
          TA=0xAA;TA=0x55;WDCON=0x07;                  //Setting WDT prescale
                set_WDTR;                       //WDT run
                set_WDCLR;                                                                                        //Clear WDT timer
                set_EWDT;
                EA =1;

#if 0
    while(1);
#else
                set_WIDPD;                                                                                         //WDT run in POWER DOWM mode setting if needed
                while (1)
                {
                        set_PD;
                                        //---------toggle GPIO1---------       
                                                clr_P04;
                                                Timer1_Delay10ms(5);
                                                set_P04;
                                                Timer1_Delay10ms(5);
                                                clr_P04;
                                                Timer1_Delay10ms(5);
                                                set_P04;
                                                Timer1_Delay10ms(5);
                                        //---------end toggle GPIO1---------
                }
#endif
}


使用特权

评论回复
沙发
huangcunxiake|  楼主 | 2019-6-30 22:48 | 只看该作者
没想到吧,看门狗定时器其实还可以作为一个普通的中断定时器使用,因为看门狗定时器非常特别,所以可以有其他定时器做不到的效果。

使用特权

评论回复
板凳
huangcunxiake|  楼主 | 2019-6-30 22:48 | 只看该作者
那就是使用低频时钟作为时钟源。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

189

主题

3407

帖子

9

粉丝