打印
[DemoCode下载]

N79E715系列看门狗定时器例程

[复制链接]
1212|20
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
dongnanxibei|  楼主 | 2017-1-14 20:31 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
/*---------------------------------------------------------------------------------------------------------*/
/*                                                                                                         */
/* Copyright(c) 2015 Nuvoton Technology Corp. All rights reserved.                                         */
/*                                                                                                         */
/*---------------------------------------------------------------------------------------------------------*/

//***********************************************************************************************************
//  Nuvoton Technology Corp.
//  E-mail: MicroC-8bit@nuvoton.com
//***********************************************************************************************************
//  Application: WDT Function
//  Set watch counter and enable WDT interrupt. WDT ISR will be execute when WDT time out.
//
//  Output : P1.4 & P2.1 toggle by WDT interrupt
//***********************************************************************************************************

//========================================= How to set WDT register =========================================
//
//  1.WDT time-out period is 64 /(Fwck + Prescalar);
//
//  2.Fwck is frequency of WDT clock source
//
//  3.Prescalar = WDCON0 & 0x07
//===========================================================================================================

//------------------------- <<< Use Configuration Wizard in Context Menu >>> --------------------------------
//
//<o0.0..2> WDT Prescalar Select
//      <0=> 1/1    <1=> 1/2    <2=> 1/8    <3=> 1/16
//      <4=> 1/32   <5=> 1/64   <6=> 1/128  <7=> 1/256
//     <o1.6> UART pin Select
//         <0=> Select P1.0, P1.1 as UART pin            <1=> Select P2.6, P2.7 as UART pin(28 pin only)
//-------------------------------- <<< end of configuration section >>> -------------------------------------

#define WDT_CLK_DIV     0x01
#define Uart_Port_Sel   0x00

#include <stdio.h>
#include "N79E715.h"
#include "Typedef.h"
#include "Define.h"
#include "Common.h"
#include "Delay.h"
#include "WDT.h"
#include "Version.h"
bit EA_Save_bit;
//-----------------------------------------------------------------------------------------------------------
void main(void)
{
    AUXR1 |= Uart_Port_Sel;             // Select P10/P11 as UART pin(default)
    InitialUART0_Timer1(9600);          // 9600 Baud Rate [url=home.php?mod=space&uid=72445]@[/url] 11.0592MHz
    Show_Version_Number_To_PC();
    printf ("\n*===================================================================");
    printf ("\n*  Name: N79E715 Series WDT Sample Code.");
    printf ("\n*===================================================================");
    printf ("\nWDT Demo Start.");
    printf ("\nP1.4 & P2.1 toggle by polling.\n");

    EA_Save_bit = EA;
    EA = 0;
    TA = 0xAA;
    TA = 0x55;
    WDCON0 &= 0xf8;
    TA = 0xAA;
    TA = 0x55;
    WDCON0 |= WDT_CLK_DIV;              // Select bit length of WDT counter
    EA = EA_Save_bit;

    set_WDCLR;                          // Clear WDT counter
    clr_WDTF;
    set_WDTEN;                          // Enable WDT
    EWDI = 1;                           // Enable WDT interrupt
    EA = 1;                             // Enable interrupt
    while(1);
}
//-----------------------------------------------------------------------------------------------------------
void WDT_ISR(void)  interrupt 10        // Vector @  0x53
{
    clr_WDTF;                           // Clear WDT flag
    P14 = ~P14;                         // P1.4 toggle when interrupt
    P21 = ~P21;                         // P2.1 toggle when interrupt
}
//-----------------------------------------------------------------------------------------------------------


沙发
dongnanxibei|  楼主 | 2017-1-14 20:32 | 只看该作者
我们看,官方提供了很多封装好的头文件。只需要调用里面的宏就行了。
比如看门狗的操作,一看就是通过宏替换实现的。

使用特权

评论回复
板凳
捉虫天师| | 2017-1-16 16:55 | 只看该作者
注释部分也很全面,知道了怎么使用。

使用特权

评论回复
地板
mintspring| | 2017-1-17 11:19 | 只看该作者
void WDT_ISR(void)  interrupt 10        // Vector @  0x53
{
    clr_WDTF;                           // Clear WDT flag
    P14 = ~P14;                         // P1.4 toggle when interrupt
    P21 = ~P21;                         // P2.1 toggle when interrupt
}
在看门狗中断里,进来先清理中断标志,然后反转IO,让对应LED单锁

使用特权

评论回复
5
稳稳の幸福| | 2017-1-17 18:47 | 只看该作者
原来,那个翻转的成为轮休,,当触发中断时候执行。

使用特权

评论回复
6
dongnanxibei|  楼主 | 2017-1-23 20:07 | 只看该作者
看门狗要谨慎使用,使用不当会给系统造成很大的不便。

使用特权

评论回复
7
玛尼玛尼哄| | 2017-1-23 20:46 | 只看该作者
看着手册再看这些例程理解就方便了。

使用特权

评论回复
8
捉虫天师| | 2017-1-24 15:23 | 只看该作者
一般系统用看门狗可以防止系统死机,死机后可以自动重启。

使用特权

评论回复
9
稳稳の幸福| | 2017-1-24 19:42 | 只看该作者
发成套的例程比较好,方便保存使用。

使用特权

评论回复
10
heisexingqisi| | 2017-1-24 20:10 | 只看该作者
我的项目一般不用看门狗,耽误性能。

使用特权

评论回复
11
wahahaheihei| | 2017-1-24 20:46 | 只看该作者
clr_WDTF;                           // Clear WDT flag
这个一般都是通过汇编实现的吧

使用特权

评论回复
12
heisexingqisi| | 2017-1-25 16:00 | 只看该作者
寄存器赋值不理解什么意思不行,想理解意思必须的看好了手册。

使用特权

评论回复
13
598330983| | 2017-1-25 21:33 | 只看该作者
最好各种寄存器值通过宏表示,这个可以更加清楚的知道具体含义。

使用特权

评论回复
14
mintspring| | 2017-1-25 22:30 | 只看该作者
Set watch counter and enable WDT interrupt. WDT ISR will be execute when WDT time out

使用特权

评论回复
15
天灵灵地灵灵| | 2017-1-25 22:38 | 只看该作者
//  1.WDT time-out period is 64 /(Fwck + Prescalar);
//
//  2.Fwck is frequency of WDT clock source
//
//  3.Prescalar = WDCON0 & 0x07

使用特权

评论回复
16
643757107| | 2017-1-26 10:45 | 只看该作者
void WDT_ISR(void)  interrupt 10        // Vector @  0x53
{
    clr_WDTF;                           // Clear WDT flag
    P14 = ~P14;                         // P1.4 toggle when interrupt
    P21 = ~P21;                         // P2.1 toggle when interrupt
}
熟悉的格式。

使用特权

评论回复
17
gejigeji521| | 2017-1-26 20:22 | 只看该作者
时钟的预分频与选择也是一个难点。

使用特权

评论回复
18
gejigeji521| | 2017-1-26 20:25 | 只看该作者
基本上大部分的应用是不需要这个的。

使用特权

评论回复
19
dongnanxibei|  楼主 | 2017-1-27 15:00 | 只看该作者
用看门狗可以唤醒系统。

使用特权

评论回复
20
huangcunxiake| | 2017-1-30 12:49 | 只看该作者
看门狗定时器中断后,系统重启,但是在寄存器里会有记录,是吧

使用特权

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

本版积分规则

187

主题

3481

帖子

16

粉丝