C51 COMPILER V9.02   MAIN                                                                  12/12/2025 15:11:16 PAGE 1   


C51 COMPILER V9.02, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN .\output\main.obj
COMPILER INVOKED BY: D:\Keil\C51\BIN\C51.EXE source\main.c OMF2 BROWSE DEBUG PRINT(.\lst\main.lst) OBJECT(.\output\main.
                    -obj)

line level    source

   1          
   2          #ifndef _MAIN_C_
   3          #define _MAIN_C_
   4          /*********************************************************************************************************
             -************/
   5          #include "include/ca51f_config.h"               
   6          #include "include/ca51f2sfr.h"
   7          #include "include/ca51f2xsfr.h"
   8          #include "include/gpiodef_f2.h"
   9          #include "include/system_clock.h"
  10          
  11          #include "include/uart.h"
  12          #include "include/pwm.h"
  13          #include "include/delay.h"
  14          #include <intrins.h>
  15          /*********************************************************************************************************
             -************
  16                  本例程设置PWM0输出频率为30KHZ、占空比50%的PWM信号, 并产生PWM上升沿中断
  17          
  18                  备注：
  19                  1、PWM有多种时钟源可以选择，时钟源是以两路PWM为单位进行设置的，
  20                  分别是：PWM0 和 PWM1、PWM2 和 PWM3、PWM4 和 PWM5、PWM6 和 PWM7，
  21                  也就是说，每组PWM的时钟源是共同设置的，时钟源通过 PWM0、PWM2、
  22                  PWM4、PWM6对应的控制寄存器 PWMCON 的PWMCKS来选择。
  23          
  24                  2、PWMCON、PWMCFG、PWMDIVH、PWMDIVL、PWMDUTH、PWMDUTL、PWMCMAX等
  25                  寄存器是带索引的寄存器，设置带索引的寄存器前先设置INDEX寄存器，
  26                  具体操作请参考下面的例子
  27          **********************************************************************************************************
             -***********/
  28          #define PWMDIV_V                                (3686400/30000)         //当PWM时钟为其他时钟频率时，需相应修改参数
  29          #define PWMDUT_V                                (PWMDIV_V/2)            //占空比为50%
  30          
  31          /*********************************************************************************************************
             -**********/
  32          
  33          void INT9_ISR(void) interrupt 14  using 1
  34          {                                         
  35   1              if(PWMAIF & PIF0)               //PWM上升沿中断
  36   1              {       
  37   2                      PWMAIF = PIF0;          //清除中断标志
  38   2      
  39   2              }
  40   1      }
  41          void main(void)
  42          {
  43   1      #ifdef LVD_RST_ENABLE
  44   1              LVDCON = 0xE1;                                  //设置LVD复位电压为2V
  45   1      #endif
  46   1      
  47   1      #if (SYSCLK_SRC == PLL)
                      Sys_Clk_Set_PLL(PLL_Multiple);  //设置系统时钟为PLL，PLL_Multiple为倍频倍数
              #endif
  50   1              
C51 COMPILER V9.02   MAIN                                                                  12/12/2025 15:11:16 PAGE 2   

  51   1      #ifdef UART0_EN
                      Uart0_Initial(UART0_BAUTRATE);  //初始化UART0
              #endif
  54   1              
  55   1      #ifdef UART1_EN
                      Uart1_Initial(UART1_BAUTRATE);  //初始化UART1
              #endif
  58   1      
  59   1      #ifdef UART2_EN
                      Uart2_Initial(UART2_BAUTRATE);  //初始化UART2
              #endif
  62   1              
  63   1              EA = 1;                                                                                                 //开全局中断
  64   1      
  65   1      #ifdef PRINT_EN
                      uart_printf("PWM interrupt Demo Code\n");
              #endif
  68   1      
  69   1      //--------------------------------------------------------------------------------------------- 
  70   1              CKCON |= IHCKE;                         //打开IRCH时钟
  71   1      //      CKCON |= ILCKE;                         //打开IRCL时钟
  72   1      //      CKCON |= TFCKE;                         //打开TFRC时钟
  73   1      
  74   1      //      GPIO_Init(P72F,P72_XOSCL_IN_SETTING);
  75   1      //      GPIO_Init(P71F,P71_XOSCL_OUT_SETTING);
  76   1      //      CKCON |= XLCKE;
  77   1      //      while(!(CKCON & XLSTA));
  78   1      //      CKSEL = (CKSEL&0xF8) | CKSEL_XOSCL;             //打开XSOCL时钟
  79   1      
  80   1      //      PLLCON = PLLON(1) | MULFT(7);
  81   1      //      while(!(PLLCON & PLSTA));
  82   1      //      CKSEL = (CKSEL&0xF8) | CKSEL_PLL;               //打开PLL时钟
  83   1      
  84   1              P50F = P50_PWM0_SETTING;                                                                //设置P50为PWM引脚功能
  85   1      
  86   1              INDEX = PWM_CH0;                                                                                                        //设置INDEX值对应PWM0
  87   1              PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_IH ;             //设置PWM时钟源为IRCH  
  88   1      //      PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_IL ;             //设置PWM时钟源为IRCL
  89   1      //      PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_XL ;             //设置PWM时钟源为XOSCL  
  90   1      //      PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_TF ;             //设置PWM时钟源为TFRC 
  91   1      //      PWMCON = TIE(0) | ZIE(0) | PIE(0) | NIE(0) | MS(0) | CKS_PLL ;          //设置PWM时钟源为PLL  
  92   1              PWMCFG = TOG(0) | 0;                                                                                                                                                                                            
  93   1              
  94   1              //设置PWMDIV、PWMDUT
  95   1              PWMDIVH = (unsigned char)(PWMDIV_V>>8);                 
  96   1              PWMDIVL = (unsigned char)(PWMDIV_V);                    
  97   1              PWMDUTH = (unsigned char)(PWMDUT_V>>8);         
  98   1              PWMDUTL = (unsigned char)(PWMDUT_V);    
  99   1      
 100   1              PWMUPD = (1<<PWM_CH0);                                                                  //PWMDIV、PWMDUT更新使能
 101   1              while(PWMUPD);                                                                                  //等待更新完成
 102   1              PWMEN  = (1<<PWM_CH0);                                                                  //PWM0使能
 103   1      
 104   1              INDEX = PWM_CH0;                                                                                                                //设置INDEX值对应PWM0
 105   1              PWMCON |= TIE(0) | ZIE(0) | PIE(1) | NIE(0);    //使能上升沿中断
 106   1              PWMCMAX = 0;                                                                                                                    //设置每个上升沿都触发
 107   1              INT9EN = 1;                                                                                                                             //使能INT9中断
 108   1      
 109   1              while(1)
 110   1              {
 111   2              }
 112   1      }
C51 COMPILER V9.02   MAIN                                                                  12/12/2025 15:11:16 PAGE 3   

 113          #endif
 114          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =     74    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
   EDATA SIZE       =   ----    ----
   HDATA SIZE       =   ----    ----
   XDATA CONST SIZE =   ----    ----
   FAR CONST SIZE   =   ----    ----
END OF MODULE INFORMATION.


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