C51 COMPILER V9.54   TIMER2                                                                12/03/2024 14:58:48 PAGE 1   


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

line level    source

   1          #include "timer2.h"
   2          
   3          //#define TIMER2_MODE0  //16位自动重载模式
   4          #define TIMER2_MODE1    //16位捕获模式
   5          //#define TIMER2_MODE2  //可编程时钟输出
   6          //#define TIMER2_MODE3  //递增/递减计数器
   7          
   8          
   9          void T2_Init(void)
  10          {
  11   1              #ifdef TIMER2_MODE0             //16位自动重载模式
                      //配置定时器初值
                      TH2 = 0xFC;
                      TL2 = 0x18;     
                      T2CPH = 0xFC;           //配置定时器重载值
                      T2CPL = 0x18;    //
                      T2MOD = 0x80;  //选择系统时钟 系统不分频
                      T2CON = 0x04;    // timer2 16位自动重载模式             TR2=1
                      #endif
  20   1              
  21   1              #ifdef TIMER2_MODE1             //16位捕获模式
  22   1              P2CR &= 0xDF;
  23   1              ALFSEL1 |= 0x20;                //复用P25为T2外部捕获输入
  24   1              TH2 = 0xFC;
  25   1              TL2 = 0x18;     
  26   1              T2MOD = 0x80;           //选择系统时钟
  27   1              T2CON = 0x09;           //16位带捕获检测T2EX引脚上的下降沿
  28   1              T2CPH = 0xFC;           //存储计数器的高8位
  29   1              T2CPL = 0x18;    //
  30   1              T2CON |= 0x04;          //TR2 = 1       CP/RL2 = 1
  31   1              #endif
  32   1              
  33   1              #ifdef TIMER2_MODE2             //可编程时钟输出
                      T2MOD = 0x82;           //选择系统时钟，T2作为可编程时钟输出
                      P2CR |= 0x10;
                      ALFSEL1 |= 0x10;        //P24配置为T2时钟输出
                      TH2 = 0xFF;
                      TL2 = 0x9C;     
                      T2CPH = 0xFF;           //T2CP1 存放波形周期数据
                      T2CPL = 0x9C;
                      T2CON |= 0x04;  //TR2 = 1               C/T2=0下可以做可编程时钟
                      #endif
  43   1              
  44   1              #ifdef TIMER2_MODE3             //递增/递减计数器
                      //配置定时器初值
                      TH2 = 0xFC;
                      TL2 = 0x18;     
                      T2CPH = 0xFC;           //配置定时器重载值
                      T2CPL = 0x18;    //
                      T2MOD = 0x81;  //选择系统时钟 系统不分频;DCEN置1作为递增递减计数器
                      P2CR &= 0xDF;
                      P2PCR |= 0x20;
                      ALFSEL1 |= 0x20;//P25输入为1则递减
                      T2CON = 0x04;    // timer2 16位自动重载模式             TR2=1
C51 COMPILER V9.54   TIMER2                                                                12/03/2024 14:58:48 PAGE 2   

                      #endif
  56   1      }
  57          
  58          
  59          void Timer2_Test()
  60          {
  61   1              
  62   1              #ifdef TIMER2_MODE0                     //P10输出频率为1kHz的方波
                      EA = 1;
                      IEN1 = 0x03;
                      T2_Init();
                GPIO_OUTPUT(P1, 0, 0);                //设置IO为输出[P1.0=0]：
                      #endif
  68   1              
  69   1              #ifdef TIMER2_MODE1                     //P25捕获
  70   1              EA = 1;
  71   1              IEN1 = 0x03;    
  72   1              T2_Init();
  73   1              #endif
  74   1              
  75   1              #ifdef TIMER2_MODE2                     //可编程时钟 P24输出5kHz
                      EA = 1;
                      IEN1 = 0x03;    
                      T2_Init();
                      #endif
  80   1              
  81   1              #ifdef TIMER2_MODE3
                      EA = 1;
                      IEN1 = 0x03;    
                      T2_Init();
                      GPIO_OUTPUT(P1, 0, 0);          //设置IO为输出[P1.0=0]：
                      #endif
  87   1              while(1);
  88   1      }
  89          


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


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