[DemoCode下载] N79E715系列看门狗定时器例程

[复制链接]
1938|20
 楼主| dongnanxibei 发表于 2017-1-14 20:31 | 显示全部楼层 |阅读模式
  1. /*---------------------------------------------------------------------------------------------------------*/
  2. /*                                                                                                         */
  3. /* Copyright(c) 2015 Nuvoton Technology Corp. All rights reserved.                                         */
  4. /*                                                                                                         */
  5. /*---------------------------------------------------------------------------------------------------------*/

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

  15. //========================================= How to set WDT register =========================================
  16. //
  17. //  1.WDT time-out period is 64 /(Fwck + Prescalar);
  18. //
  19. //  2.Fwck is frequency of WDT clock source
  20. //
  21. //  3.Prescalar = WDCON0 & 0x07
  22. //===========================================================================================================

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

  31. #define WDT_CLK_DIV     0x01
  32. #define Uart_Port_Sel   0x00

  33. #include <stdio.h>
  34. #include "N79E715.h"
  35. #include "Typedef.h"
  36. #include "Define.h"
  37. #include "Common.h"
  38. #include "Delay.h"
  39. #include "WDT.h"
  40. #include "Version.h"
  41. bit EA_Save_bit;
  42. //-----------------------------------------------------------------------------------------------------------
  43. void main(void)
  44. {
  45.     AUXR1 |= Uart_Port_Sel;             // Select P10/P11 as UART pin(default)
  46.     InitialUART0_Timer1(9600);          // 9600 Baud Rate [url=home.php?mod=space&uid=72445]@[/url] 11.0592MHz
  47.     Show_Version_Number_To_PC();
  48.     printf ("\n*===================================================================");
  49.     printf ("\n*  Name: N79E715 Series WDT Sample Code.");
  50.     printf ("\n*===================================================================");
  51.     printf ("\nWDT Demo Start.");
  52.     printf ("\nP1.4 & P2.1 toggle by polling.\n");

  53.     EA_Save_bit = EA;
  54.     EA = 0;
  55.     TA = 0xAA;
  56.     TA = 0x55;
  57.     WDCON0 &= 0xf8;
  58.     TA = 0xAA;
  59.     TA = 0x55;
  60.     WDCON0 |= WDT_CLK_DIV;              // Select bit length of WDT counter
  61.     EA = EA_Save_bit;

  62.     set_WDCLR;                          // Clear WDT counter
  63.     clr_WDTF;
  64.     set_WDTEN;                          // Enable WDT
  65.     EWDI = 1;                           // Enable WDT interrupt
  66.     EA = 1;                             // Enable interrupt
  67.     while(1);
  68. }
  69. //-----------------------------------------------------------------------------------------------------------
  70. void WDT_ISR(void)  interrupt 10        // Vector @  0x53
  71. {
  72.     clr_WDTF;                           // Clear WDT flag
  73.     P14 = ~P14;                         // P1.4 toggle when interrupt
  74.     P21 = ~P21;                         // P2.1 toggle when interrupt
  75. }
  76. //-----------------------------------------------------------------------------------------------------------


 楼主| 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单锁
稳稳の幸福 发表于 2017-1-17 18:47 | 显示全部楼层
原来,那个翻转的成为轮休,,当触发中断时候执行。
 楼主| dongnanxibei 发表于 2017-1-23 20:07 | 显示全部楼层
看门狗要谨慎使用,使用不当会给系统造成很大的不便。
玛尼玛尼哄 发表于 2017-1-23 20:46 | 显示全部楼层
看着手册再看这些例程理解就方便了。
捉虫天师 发表于 2017-1-24 15:23 | 显示全部楼层
一般系统用看门狗可以防止系统死机,死机后可以自动重启。
稳稳の幸福 发表于 2017-1-24 19:42 | 显示全部楼层
发成套的例程比较好,方便保存使用。
heisexingqisi 发表于 2017-1-24 20:10 | 显示全部楼层
我的项目一般不用看门狗,耽误性能。
wahahaheihei 发表于 2017-1-24 20:46 | 显示全部楼层
clr_WDTF;                           // Clear WDT flag
这个一般都是通过汇编实现的吧
heisexingqisi 发表于 2017-1-25 16:00 | 显示全部楼层
寄存器赋值不理解什么意思不行,想理解意思必须的看好了手册。
598330983 发表于 2017-1-25 21:33 | 显示全部楼层
最好各种寄存器值通过宏表示,这个可以更加清楚的知道具体含义。
mintspring 发表于 2017-1-25 22:30 | 显示全部楼层
Set watch counter and enable WDT interrupt. WDT ISR will be execute when WDT time out
天灵灵地灵灵 发表于 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
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
}
熟悉的格式。
gejigeji521 发表于 2017-1-26 20:22 | 显示全部楼层
时钟的预分频与选择也是一个难点。
gejigeji521 发表于 2017-1-26 20:25 | 显示全部楼层
基本上大部分的应用是不需要这个的。
 楼主| dongnanxibei 发表于 2017-1-27 15:00 | 显示全部楼层
用看门狗可以唤醒系统。
huangcunxiake 发表于 2017-1-30 12:49 | 显示全部楼层
看门狗定时器中断后,系统重启,但是在寄存器里会有记录,是吧
您需要登录后才可以回帖 登录 | 注册

本版积分规则

225

主题

3870

帖子

18

粉丝
快速回复 在线客服 返回列表 返回顶部