C51 COMPILER V9.59.0.0 STC8A_PCA 06/10/2021 14:41:23 PAGE 1 C51 COMPILER V9.59.0.0, COMPILATION OF MODULE STC8A_PCA OBJECT MODULE PLACED IN .\list\STC8A_PCA.obj COMPILER INVOKED BY: C:\Keil_v5\C51\BIN\C51.EXE STC8A_PCA.c OMF2 OPTIMIZE(8,SPEED) BROWSE DEBUG PRINT(.\list\STC8A_PCA.l -st) TABS(2) OBJECT(.\list\STC8A_PCA.obj) line level source 1 /*---------------------------------------------------------------------*/ 2 /* --- STC MCU Limited ------------------------------------------------*/ 3 /* --- STC 1T Series MCU Demo Programme -------------------------------*/ 4 /* --- Mobile: (86)13922805190 ----------------------------------------*/ 5 /* --- Fax: 86-0513-55012956,55012947,55012969 ------------------------*/ 6 /* --- Tel: 86-0513-55012928,55012929,55012966 ------------------------*/ 7 /* --- Web: www.STCMCU.com --------------------------------------------*/ 8 /* --- Web: www.STCMCUDATA.com ---------------------------------------*/ 9 /* --- QQ: 800003751 -------------------------------------------------*/ 10 /* 如果要在程序中使用此代码,请在程序中注明使用了STC的资料及程序 */ 11 /*---------------------------------------------------------------------*/ 12 13 #include "STC8A_PCA.h" 14 15 bit B_Capture0,B_Capture1,B_Capture2,B_Capture3; 16 u8 PCA0_mode,PCA1_mode,PCA2_mode,PCA3_mode; 17 u16 CCAP0_tmp,PCA_Timer0; 18 u16 CCAP1_tmp,PCA_Timer1; 19 u16 CCAP2_tmp,PCA_Timer2; 20 u16 CCAP3_tmp,PCA_Timer3; 21 22 //======================================================================== 23 // 函数: UpdatePcaPwm(u8 PCA_id, u16 pwm_value) 24 // 描述: 更新PWM值. 25 // 参数: PCA_id: PCA序号. 取值 PCA0,PCA1,PCA2,PCA_Counter 26 // pwm_value: pwm值, 这个值是输出低电平的时间. 27 // 返回: none. 28 // 版本: V1.0, 2012-11-22 29 //======================================================================== 30 void UpdatePcaPwm(u8 PCA_id, u16 pwm_value) 31 { 32 1 if(PCA_id == PCA0) 33 1 { 34 2 PCA_PWM0 = (PCA_PWM0 & ~0x32) | (u8)((pwm_value & 0x0300) >> 4) | (u8)((pwm_value & 0x0400) >> 9); 35 2 CCAP0H = (u8)pwm_value; 36 2 } 37 1 else if(PCA_id == PCA1) 38 1 { 39 2 PCA_PWM1 = (PCA_PWM1 & ~0x32) | (u8)((pwm_value & 0x0300) >> 4) | (u8)((pwm_value & 0x0400) >> 9); 40 2 CCAP1H = (u8)pwm_value; 41 2 } 42 1 else if(PCA_id == PCA2) 43 1 { 44 2 PCA_PWM2 = (PCA_PWM2 & ~0x32) | (u8)((pwm_value & 0x0300) >> 4) | (u8)((pwm_value & 0x0400) >> 9); 45 2 CCAP2H = (u8)pwm_value; 46 2 } 47 1 else if(PCA_id == PCA3) 48 1 { 49 2 EAXSFR(); /* MOVX A,@DPTR/MOVX @DPTR,A指令的操作对象为扩展SFR(XSFR) */ 50 2 PCA_PWM3 = (PCA_PWM3 & ~0x32) | (u8)((pwm_value & 0x0300) >> 4) | (u8)((pwm_value & 0x0400) >> 9); 51 2 CCAP3H = (u8)pwm_value; 52 2 EAXRAM(); /* MOVX A,@DPTR/MOVX @DPTR,A指令的操作对象为扩展RAM(XRAM) */ 53 2 } 54 1 } C51 COMPILER V9.59.0.0 STC8A_PCA 06/10/2021 14:41:23 PAGE 2 55 56 //======================================================================== 57 // 函数: void PCALevelSet(u8 PCA_id, u8 PCA_Level) 58 // 描述: 更新PWM值. 59 // 参数: PCA_id: PCA序号. 取值 PCA0,PCA1,PCA2,PCA3 60 // PCA_Level: PWM固定输出高电平, 0: 低电平, 1: 高电平. 61 // 返回: none. 62 // 版本: V1.0, 2021-6-10 63 //======================================================================== 64 void PCALevelSet(u8 PCA_id, u8 PCA_Level) 65 { 66 1 if(PCA_id == PCA0) 67 1 { 68 2 if(PCA_Level == 1) 69 2 { 70 3 PCA_PWM0 &= ~0x32; //PWM固定输出高电平 71 3 CCAP0H = 0x00; 72 3 } 73 2 else 74 2 { 75 3 PCA_PWM0 |= 0x32; //PWM固定输出低电平 76 3 CCAP0H = 0xff; 77 3 } 78 2 } 79 1 else if(PCA_id == PCA1) 80 1 { 81 2 if(PCA_Level == 1) 82 2 { 83 3 PCA_PWM1 &= ~0x32; //PWM固定输出高电平 84 3 CCAP1H = 0x00; 85 3 } 86 2 else 87 2 { 88 3 PCA_PWM1 |= 0x32; //PWM固定输出低电平 89 3 CCAP1H = 0xff; 90 3 } 91 2 } 92 1 else if(PCA_id == PCA2) 93 1 { 94 2 if(PCA_Level == 1) 95 2 { 96 3 PCA_PWM2 &= ~0x32; //PWM固定输出高电平 97 3 CCAP2H = 0x00; 98 3 } 99 2 else 100 2 { 101 3 PCA_PWM2 |= 0x32; //PWM固定输出低电平 102 3 CCAP2H = 0xff; 103 3 } 104 2 } 105 1 else if(PCA_id == PCA3) 106 1 { 107 2 EAXSFR(); /* MOVX A,@DPTR/MOVX @DPTR,A指令的操作对象为扩展SFR(XSFR) */ 108 2 if(PCA_Level == 1) 109 2 { 110 3 PCA_PWM3 &= ~0x32; //PWM固定输出高电平 111 3 CCAP3H = 0x00; 112 3 } 113 2 else 114 2 { 115 3 PCA_PWM3 |= 0x32; //PWM固定输出低电平 116 3 CCAP3H = 0xff; C51 COMPILER V9.59.0.0 STC8A_PCA 06/10/2021 14:41:23 PAGE 3 117 3 } 118 2 EAXRAM(); /* MOVX A,@DPTR/MOVX @DPTR,A指令的操作对象为扩展RAM(XRAM) */ 119 2 } 120 1 } 121 122 //======================================================================== 123 // 函数: void PCA_Init(PCA_id, PCA_InitTypeDef *PCAx) 124 // 描述: PCA初始化程序. 125 // 参数: PCA_id: PCA序号. 取值 PCA0,PCA1,PCA2,PCA_Counter 126 // PCAx: 结构参数,请参考PCA.h里的定义. 127 // 返回: none. 128 // 版本: V1.0, 2012-11-22 129 //======================================================================== 130 void PCA_Init(u8 PCA_id, PCA_InitTypeDef *PCAx) 131 { 132 1 if(PCA_id == PCA_Counter) //设置公用Counter 133 1 { 134 2 CR = 0; 135 2 CH = 0; 136 2 CL = 0; 137 2 CMOD = (CMOD & ~(7<<1)) | PCAx->PCA_Clock; //选择时钟源 138 2 if(PCAx->PCA_RUN == ENABLE) CR = 1; 139 2 return; 140 2 } 141 1 142 1 if(PCA_id == PCA0) 143 1 { 144 2 PCA_PWM0 = (PCA_PWM0 & ~(3<<6)) | PCAx->PCA_PWM_Wide; //PWM宽度 145 2 146 2 PCA_Timer0 = PCAx->PCA_Value; 147 2 B_Capture0 = 0; 148 2 CCAP0_tmp = PCA_Timer0; 149 2 CCAP0L = (u8)CCAP0_tmp; //将影射寄存器写入捕获寄存器,先写CCAPxL 150 2 CCAP0H = (u8)(CCAP0_tmp >> 8); //后写CCAPxH 151 2 } 152 1 if(PCA_id == PCA1) 153 1 { 154 2 PCA_PWM1 = (PCA_PWM1 & ~(3<<6)) | PCAx->PCA_PWM_Wide; 155 2 156 2 PCA_Timer1 = PCAx->PCA_Value; 157 2 B_Capture1 = 0; 158 2 CCAP1_tmp = PCA_Timer1; 159 2 CCAP1L = (u8)CCAP1_tmp; //将影射寄存器写入捕获寄存器,先写CCAPxL 160 2 CCAP1H = (u8)(CCAP1_tmp >> 8); //后写CCAPxH 161 2 } 162 1 if(PCA_id == PCA2) 163 1 { 164 2 PCA_PWM2 = (PCA_PWM2 & ~(3<<6)) | PCAx->PCA_PWM_Wide; 165 2 166 2 PCA_Timer2 = PCAx->PCA_Value; 167 2 B_Capture2 = 0; 168 2 CCAP2_tmp = PCA_Timer2; 169 2 CCAP2L = (u8)CCAP2_tmp; //将影射寄存器写入捕获寄存器,先写CCAPxL 170 2 CCAP2H = (u8)(CCAP2_tmp >> 8); //后写CCAPxH 171 2 } 172 1 if(PCA_id == PCA3) 173 1 { 174 2 EAXSFR(); /* MOVX A,@DPTR/MOVX @DPTR,A指令的操作对象为扩展SFR(XSFR) */ 175 2 PCA_PWM3 = (PCA_PWM3 & ~(3<<6)) | PCAx->PCA_PWM_Wide; 176 2 177 2 PCA_Timer3 = PCAx->PCA_Value; 178 2 B_Capture3 = 0; C51 COMPILER V9.59.0.0 STC8A_PCA 06/10/2021 14:41:23 PAGE 4 179 2 CCAP3_tmp = PCA_Timer3; 180 2 CCAP3L = (u8)CCAP3_tmp; //将影射寄存器写入捕获寄存器,先写CCAPxL 181 2 CCAP3H = (u8)(CCAP3_tmp >> 8); //后写CCAPxH 182 2 EAXRAM(); /* MOVX A,@DPTR/MOVX @DPTR,A指令的操作对象为扩展RAM(XRAM) */ 183 2 } 184 1 } MODULE INFORMATION: STATIC OVERLAYABLE CODE SIZE = 493 ---- CONSTANT SIZE = ---- ---- XDATA SIZE = ---- ---- PDATA SIZE = ---- ---- DATA SIZE = 20 ---- IDATA SIZE = ---- ---- BIT SIZE = 4 ---- EDATA SIZE = ---- ---- HDATA SIZE = ---- ---- XDATA CONST SIZE = ---- ---- FAR CONST SIZE = ---- ---- END OF MODULE INFORMATION. C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)