[DemoCode下载] 看门狗失能操作

[复制链接]
815|2
 楼主| gejigeji521 发表于 2019-6-30 22:57 | 显示全部楼层 |阅读模式
  1. /*---------------------------------------------------------------------------------------------------------*/
  2. /*                                                                                                         */
  3. /* Copyright(c) 2016 Nuvoton Technology Corp. All rights reserved.                                         */
  4. /*                                                                                                         */
  5. /*---------------------------------------------------------------------------------------------------------*/

  6. //***********************************************************************************************************
  7. //  Nuvoton Technoledge Corp.
  8. //  Website: http://www.nuvoton.com
  9. //  E-Mail : MicroC-8bit@nuvoton.com
  10. //  Date   : Apr/21/2016
  11. //***********************************************************************************************************

  12. //***********************************************************************************************************
  13. //  File Function: N76E003 Watch Dog reste functiondemo code
  14. //***********************************************************************************************************

  15. #include "N76E003.h"
  16. #include "Common.h"
  17. #include "Delay.h"
  18. #include "SFR_Macro.h"
  19. #include "Function_define.h"

  20. #define     CFG_READ            0xC0
  21. #define     CFG_ERASE           0xE2
  22. #define     CFG_BYTE_PROGRAM    0xE1

  23. /***********************************************************************
  24.         WDT CONFIG enable
  25.         warning : this macro is only when ICP not enable CONFIG WDT function
  26.         copy this marco code to you code to enable WDT reset.
  27. ************************************************************************/
  28. void Enable_WDT_Reset_Config(void)
  29. {
  30.           set_IAPEN;
  31.     IAPAL = 0x04;
  32.     IAPAH = 0x00;
  33.     IAPFD = 0x0F;
  34.     IAPCN = CFG_BYTE_PROGRAM;
  35.     set_CFUEN;
  36.     set_IAPGO;                                  //trigger IAP
  37.                 while((CHPCON&SET_BIT6)==SET_BIT6);          //check IAPFF (CHPCON.6)
  38.     clr_CFUEN;
  39.     clr_IAPEN;
  40. }
  41. /***********************************************************************
  42.         WDT CONFIG disable
  43.         warning : this macro is for CONFIG already enable WDT Reset to disable.
  44.         Since erase CONFIG is full page
  45.         step 1. storage CONFIG value in RAM
  46.         step 2. modify RAM CONFIG4 WDT value to disable
  47.         step 3. erase CONFIG page
  48.         step 4. re writer CONFIG.
  49. ************************************************************************/
  50. void Disable_WDT_Reset_Config(void)
  51. {
  52.         UINT8 cf0,cf1,cf2,cf3,cf4;
  53.        
  54.           set_IAPEN;
  55.     IAPAL = 0x00;
  56.     IAPAH = 0x00;
  57.     IAPCN = CFG_READ;
  58.     set_IAPGO;                                  //Storage CONFIG0 data
  59.                 cf0 = IAPFD;
  60.                 IAPAL = 0x01;
  61.                 set_IAPGO;                                  //Storage CONFIG1 data
  62.                 cf1 = IAPFD;
  63.                 IAPAL = 0x02;
  64.           set_IAPGO;                                  //Storage CONFIG2 data
  65.                 cf2 = IAPFD;
  66.                 IAPAL = 0x03;
  67.           set_IAPGO;                                  //Storage CONFIG3 data
  68.                 cf3 = IAPFD;
  69.                 IAPAL = 0x04;
  70.           set_IAPGO;                                  //Storage CONFIG4 data
  71.                 cf4 = IAPFD;
  72.                 cf4 |= 0xF0;                                                                                                                                //Moidfy Storage CONFIG4 data disable WDT reset
  73.                
  74.                 set_CFUEN;       
  75.                 IAPCN = CFG_ERASE;                                                                                                        //Erase CONFIG all
  76.                 IAPAH = 0x00;
  77.                 IAPAL = 0x00;
  78.                 IAPFD = 0xFF;
  79.                 set_IAPGO;
  80.                
  81.                 IAPCN = CFG_BYTE_PROGRAM;                                                                                //Write CONFIG
  82.                 IAPFD = cf0;
  83.                 set_IAPGO;
  84.                 IAPAL = 0x01;
  85.                 IAPFD = cf1;
  86.                 set_IAPGO;
  87.                 IAPAL = 0x02;
  88.                 IAPFD = cf2;
  89.                 set_IAPGO;
  90.                 IAPAL = 0x03;
  91.                 IAPFD = cf3;
  92.                 set_IAPGO;
  93.                 IAPAL = 0x04;
  94.                 IAPFD = cf4;
  95.                 set_IAPGO;

  96.     clr_CFUEN;
  97.     clr_IAPEN;
  98. }

  99. /************************************************************************************************************
  100. *    Main function
  101. ************************************************************************************************************/
  102. void main (void)
  103. {

  104.   Set_All_GPIO_Quasi_Mode;

  105.         clr_GPIO1;
  106.         Timer0_Delay1ms(50);                                        //toggle I/O to show MCU Reset
  107.         set_GPIO1;
  108.         Timer0_Delay1ms(50);
  109.         clr_GPIO1;
  110.         Timer0_Delay1ms(50);
  111.         set_GPIO1;
  112.         Timer0_Delay1ms(50);

  113.        
  114. //----------------------------------------------------------------------------------------------
  115. // WDT Init !!! ENABLE CONFIG WDT FIRST !!!
  116. // Warning:
  117. // Always check CONFIG WDT enable first, CONFIG not enable, SFR can't enable WDT reset
  118. // Please call Enable_WDT_Reset_Config() function to enable CONFIG WDT reset
  119. //----------------------------------------------------------------------------------------------

  120. //        Enable_WDT_Reset_Config();                                                        //Software enable WDT reset CONFIG setting
  121.           TA=0xAA;TA=0x55;WDCON|=0x07;                                                //Setting WDT prescale
  122.                 set_WDCLR;                                                                                                                        //Clear WDT timer
  123.                 while((WDCON|~SET_BIT6)==0xFF);                                        //confirm WDT clear is ok before into power down mode
  124. //                EA = 1;
  125.                 set_WDTR;                                                                                                                                //WDT run
  126.                 Disable_WDT_Reset_Config();                                                //Software disable WDT reset CONFIG setting

  127.     while (1)
  128.                 {
  129.                         clr_GPIO1;
  130.                         Timer0_Delay1ms(100);
  131.                         set_GPIO1;
  132.                         Timer0_Delay1ms(100);
  133.                         clr_GPIO1;
  134.                         Timer0_Delay1ms(100);
  135.                         set_GPIO1;
  136.                         Timer0_Delay1ms(100);
  137.                         clr_GPIO1;
  138.                         set_PD;
  139.                 }
  140. }



 楼主| gejigeji521 发表于 2019-6-30 22:57 | 显示全部楼层
/ WDT Init !!! ENABLE CONFIG WDT FIRST !!!
// Warning:
// Always check CONFIG WDT enable first, CONFIG not enable, SFR can't enable WDT reset
// Please call Enable_WDT_Reset_Config() function to enable CONFIG WDT reset
 楼主| gejigeji521 发表于 2019-6-30 22:58 | 显示全部楼层
一定要注意上面的文字,或者仔细阅读手册相关内容
您需要登录后才可以回帖 登录 | 注册

本版积分规则

196

主题

2465

帖子

8

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