C51 COMPILER V9.54   WTTIMER                                                               12/03/2024 14:58:49 PAGE 1   


C51 COMPILER V9.54, COMPILATION OF MODULE WTTIMER
OBJECT MODULE PLACED IN .\Objects\wttimer.obj
COMPILER INVOKED BY: C:\Keil_v5\C51\BIN\C51.EXE public\wttimer.c OPTIMIZE(8,SPEED) BROWSE INCDIR(.\public) DEBUG OBJECTE
                    -XTEND PRINT(.\Listings\wttimer.lst) OBJECT(.\Objects\wttimer.obj)

line level    source

   1          #include "wttimer.h"
   2          
   3          /*WT_TIME       = Twtclk * (wttime+1) * 16384
   4                                                          = (wdttime+1) * 0.5s
   5          wdttime :0 ~ 63
   6          */
   7          
   8          
   9          void WT_Init(uint8_t wttime)
  10          {
  11   1              WTCON  = wttime << 2;
  12   1              CLKEN1 |= 0x02;  //wt时钟使能
  13   1              INTCTRL |= 0xC0;        //选择P21中断源为WT匹配信号
  14   1              IEN0 |= 0x04;    //使能WT唤醒定时器中断
  15   1              EA = 1;
  16   1              WTCON |= 0x01;
  17   1      //进入STOP前需要清零外部中断标志位IE0/1/2/3，允许STOP模式下ILRC运行
  18   1      //进入STOP模式前确保WTCLR为0，否则可能无法唤醒STOP模式
  19   1      }
  20          
  21          
  22          
  23          void Wake_wt(uint8_t time)//P4.0输出每方波
  24          {
  25   1              WT_Init(time);//(time+1)*0.5s唤醒，time = 0~63
  26   1              while(1)
  27   1              {
  28   2      //              CLKCFG |= 0x10;//复位状态默认允许，必要时可关闭
  29   2                      TCON &= 0xF5;           //清除外部中断1标志位           IE1 = 0;
  30   2      //              TCON = 0x00;
  31   2                      PCON |= 0x02;
  32   2      //              WTCON &= 0xFE;//退出STOP关闭wt使能
  33   2                      if(P4 == 0x01)
  34   2                              P4 = 0x00;
  35   2                      else
  36   2                              P4 = 0x01;
  37   2              }
  38   1      }
  39          
  40          void Wake_wdt(uint8_t count)//count*32ms为唤醒时间
  41          {
  42   1              uint8_t i;
  43   1              WDTTimer_Init(255);//(time+1)* 0.000125s唤醒，time = 0~255
  44   1              while(1)
  45   1              {
  46   2      //              CLKCFG |= 0x10;         //STOP模式下辅时钟使能
  47   2                      TCON &= 0xFD;           //清除外部中断0标志位   IE0 = 0;
  48   2                      for(i=0;i<count;i++)
  49   2                      {
  50   3                              PCON |= 0x02;           //进入STOP停机模式
  51   3      //              IEN0 &= 0xFE;    //退出STOP关闭wdt中断使能，例程会在看门狗计数满时复位
  52   3                              WDT_RLD();//每次唤醒必须喂狗，否则一直计数会触发看门狗复位
  53   3                      }
  54   2                      
C51 COMPILER V9.54   WTTIMER                                                               12/03/2024 14:58:49 PAGE 2   

  55   2                      if(P4 == 0x01)
  56   2                              P4 = 0x00;
  57   2                      else
  58   2                              P4 = 0x01;
  59   2      
  60   2              }
  61   1      }
  62          
  63          
  64          
  65          /*使用外部中断源需保证对应端口为输入模式*/
  66          /*进入STOP前需要清零外部中断标志位IE0/1/2/3*/
  67          void WT_Test(void)
  68          {
  69   1              P4CR |= 0xff;
  70   1              P4 = 0x01;
  71   1              delay_ms(200);
  72   1              P4 = 0x00;
  73   1      //      Wake_wt(1);
  74   1              Wake_wdt(255);
  75   1      
  76   1      
  77   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    112    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----       2
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)
