C51 COMPILER V9.59.0.0 PCA 03/09/2021 14:07:06 PAGE 1 C51 COMPILER V9.59.0.0, COMPILATION OF MODULE PCA OBJECT MODULE PLACED IN .\list\PCA.obj COMPILER INVOKED BY: C:\Keil_v5\C51\BIN\C51.EXE PCA.c OPTIMIZE(8,SPEED) BROWSE DEBUG OBJECTEXTEND PRINT(.\list\PCA.lst) -TABS(2) OBJECT(.\list\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 "PCA.h" 14 15 bit B_Capture0,B_Capture1,B_Capture2; 16 u8 PCA0_mode,PCA1_mode,PCA2_mode; 17 u16 CCAP0_tmp,PCA_Timer0; 18 u16 CCAP1_tmp,PCA_Timer1; 19 u16 CCAP2_tmp,PCA_Timer2; 20 u16 CAP0_Old,CAP1_Old,CAP2_Old; //记录上一次的捕获值 21 u16 CAP0_New,CAP1_New,CAP2_New; //记录本次的捕获值 22 23 /************* 功能说明 ************** 24 25 26 ******************************************/ 27 28 29 //======================================================================== 30 // 函数: UpdatePwm(u8 PCA_id, u16 pwm_value) 31 // 描述: 更新PWM值. 32 // 参数: PCA_id: PCA序号. 取值 PCA0,PCA1,PCA2,PCA_Counter 33 // pwm_value: pwm值, 这个值是输出低电平的时间. 34 // 返回: none. 35 // 版本: V1.0, 2012-11-22 36 //======================================================================== 37 void UpdatePwm(u8 PCA_id, u16 pwm_value) 38 { 39 1 if(PCA_id == PCA0) 40 1 { 41 2 PCA_PWM0 = (PCA_PWM0 & ~0x32) | (u8)((pwm_value & 0x0300) >> 4) | (u8)((pwm_value & 0x0400) >> 9); 42 2 CCAP0H = (u8)pwm_value; 43 2 } 44 1 else if(PCA_id == PCA1) 45 1 { 46 2 PCA_PWM1 = (PCA_PWM1 & ~0x32) | (u8)((pwm_value & 0x0300) >> 4) | (u8)((pwm_value & 0x0400) >> 9); 47 2 CCAP1H = (u8)pwm_value; 48 2 } 49 1 else if(PCA_id == PCA2) 50 1 { 51 2 PCA_PWM2 = (PCA_PWM2 & ~0x32) | (u8)((pwm_value & 0x0300) >> 4) | (u8)((pwm_value & 0x0400) >> 9); 52 2 CCAP2H = (u8)pwm_value; 53 2 } 54 1 } C51 COMPILER V9.59.0.0 PCA 03/09/2021 14:07:06 PAGE 2 55 56 //======================================================================== 57 // 函数: void PCA_Init(PCA_id, PCA_InitTypeDef *PCAx) 58 // 描述: PCA初始化程序. 59 // 参数: PCA_id: PCA序号. 取值 PCA0,PCA1,PCA2,PCA_Counter 60 // PCAx: 结构参数,请参考PCA.h里的定义. 61 // 返回: none. 62 // 版本: V1.0, 2012-11-22 63 //======================================================================== 64 void PCA_Init(u8 PCA_id, PCA_InitTypeDef *PCAx) 65 { 66 1 if(PCA_id > PCA_Counter) return; //id错误 67 1 68 1 if(PCA_id == PCA_Counter) //设置公用Counter 69 1 { 70 2 CR = 0; 71 2 CH = 0; 72 2 CL = 0; 73 2 P_SW1 = (P_SW1 & ~(3<<4)) | PCAx->PCA_IoUse; //切换IO口 74 2 CMOD = (CMOD & ~(7<<1)) | PCAx->PCA_Clock; //选择时钟源 75 2 CMOD = (CMOD & ~1) | (PCAx->PCA_Interrupt_Mode & 1); //ECF 76 2 if(PCAx->PCA_Polity > Polity_3) return; //错误 77 2 PCA_Polity(PCAx->PCA_Polity); //指定中断优先级(低到高) Polity_0,Polity_1,Polity_2,Polity_3 78 2 if(PCAx->PCA_RUN == ENABLE) CR = 1; 79 2 return; 80 2 } 81 1 82 1 PCAx->PCA_Interrupt_Mode &= (3<<4) + 1; 83 1 if(PCAx->PCA_Mode >= PCA_Mode_SoftTimer) PCAx->PCA_Interrupt_Mode &= ~(3<<4); 84 1 85 1 if(PCA_id == PCA0) 86 1 { 87 2 CCAPM0 = PCAx->PCA_Mode | PCAx->PCA_Interrupt_Mode; //工作模式, 中断模式 88 2 PCA_PWM0 = (PCA_PWM0 & ~(3<<6)) | PCAx->PCA_PWM_Wide; //PWM宽度 89 2 90 2 PCA_Timer0 = PCAx->PCA_Value; 91 2 B_Capture0 = 0; 92 2 PCA0_mode = PCAx->PCA_Mode; 93 2 CCAP0_tmp = PCA_Timer0; 94 2 CCAP0L = (u8)CCAP0_tmp; //将影射寄存器写入捕获寄存器,先写CCAP0L 95 2 CCAP0H = (u8)(CCAP0_tmp >> 8); //后写CCAP0H 96 2 } 97 1 if(PCA_id == PCA1) 98 1 { 99 2 CCAPM1 = PCAx->PCA_Mode | PCAx->PCA_Interrupt_Mode; 100 2 PCA_PWM1 = (PCA_PWM1 & ~(3<<6)) | PCAx->PCA_PWM_Wide; 101 2 102 2 PCA_Timer1 = PCAx->PCA_Value; 103 2 B_Capture1 = 0; 104 2 PCA1_mode = PCAx->PCA_Mode; 105 2 CCAP1_tmp = PCA_Timer1; 106 2 CCAP1L = (u8)CCAP1_tmp; //将影射寄存器写入捕获寄存器,先写CCAP0L 107 2 CCAP1H = (u8)(CCAP1_tmp >> 8); //后写CCAP0H 108 2 } 109 1 if(PCA_id == PCA2) 110 1 { 111 2 CCAPM2 = PCAx->PCA_Mode | PCAx->PCA_Interrupt_Mode; 112 2 PCA_PWM2 = (PCA_PWM2 & ~(3<<6)) | PCAx->PCA_PWM_Wide; 113 2 114 2 PCA_Timer2 = PCAx->PCA_Value; 115 2 B_Capture2 = 0; 116 2 PCA2_mode = PCAx->PCA_Mode; C51 COMPILER V9.59.0.0 PCA 03/09/2021 14:07:06 PAGE 3 117 2 CCAP2_tmp = PCA_Timer2; 118 2 CCAP2L = (u8)CCAP2_tmp; //将影射寄存器写入捕获寄存器,先写CCAP0L 119 2 CCAP2H = (u8)(CCAP2_tmp >> 8); //后写CCAP0H 120 2 } 121 1 122 1 CAP0_Old = 0; 123 1 CAP1_Old = 0; 124 1 CAP2_Old = 0; 125 1 CAP0_New = 0; 126 1 CAP1_New = 0; 127 1 CAP2_New = 0; 128 1 } 129 130 //======================================================================== 131 // 函数: void PCA_Handler (void) interrupt PCA_VECTOR 132 // 描述: PCA中断处理程序. 133 // 参数: None 134 // 返回: none. 135 // 版本: V1.0, 2012-11-22 136 //======================================================================== 137 void PCA_Handler (void) interrupt PCA_VECTOR 138 { 139 1 if(CCF0) //PCA模块0中断 140 1 { 141 2 CCF0 = 0; //清PCA模块0中断标志 142 2 if(PCA0_mode >= PCA_Mode_SoftTimer) //PCA_Mode_SoftTimer and PCA_Mode_HighPulseOutput 143 2 { 144 3 CCAP0_tmp += PCA_Timer0; 145 3 CCAP0L = (u8)CCAP0_tmp; //将影射寄存器写入捕获寄存器,先写CCAP0L 146 3 CCAP0H = (u8)(CCAP0_tmp >> 8); //后写CCAP0H 147 3 } 148 2 else if(PCA0_mode == PCA_Mode_Capture) 149 2 { 150 3 CAP0_Old = CAP0_New; 151 3 CAP0_New = CCAP0H; //读CCAP0H 152 3 CAP0_New = (CAP0_New << 8) + CCAP0L; 153 3 CCAP0_tmp = CAP0_New - CAP0_Old; 154 3 B_Capture0 = 1; 155 3 } 156 2 } 157 1 158 1 if(CCF1) //PCA模块1中断 159 1 { 160 2 CCF1 = 0; //清PCA模块1中断标志 161 2 if(PCA1_mode >= PCA_Mode_SoftTimer) //PCA_Mode_SoftTimer and PCA_Mode_HighPulseOutput 162 2 { 163 3 CCAP1_tmp += PCA_Timer1; 164 3 CCAP1L = (u8)CCAP1_tmp; //将影射寄存器写入捕获寄存器,先写CCAP0L 165 3 CCAP1H = (u8)(CCAP1_tmp >> 8); //后写CCAP0H 166 3 } 167 2 else if(PCA1_mode == PCA_Mode_Capture) 168 2 { 169 3 CAP1_Old = CAP1_New; 170 3 CAP1_New = CCAP1H; //读CCAP1H 171 3 CAP1_New = (CAP1_New << 8) + CCAP1L; 172 3 CCAP1_tmp = CAP1_New - CAP1_Old; 173 3 B_Capture1 = 1; 174 3 } 175 2 } 176 1 177 1 if(CCF2) //PCA模块2中断 178 1 { C51 COMPILER V9.59.0.0 PCA 03/09/2021 14:07:06 PAGE 4 179 2 CCF2 = 0; //清PCA模块1中断标志 180 2 if(PCA2_mode >= PCA_Mode_SoftTimer) //PCA_Mode_SoftTimer and PCA_Mode_HighPulseOutput 181 2 { 182 3 CCAP2_tmp += PCA_Timer2; 183 3 CCAP2L = (u8)CCAP2_tmp; //将影射寄存器写入捕获寄存器,先写CCAP0L 184 3 CCAP2H = (u8)(CCAP2_tmp >> 8); //后写CCAP0H 185 3 } 186 2 else if(PCA2_mode == PCA_Mode_Capture) 187 2 { 188 3 CAP2_Old = CAP2_New; 189 3 CAP2_New = CCAP2H; //读CCAP2H 190 3 CAP2_New = (CAP2_New << 8) + CCAP2L; 191 3 CCAP2_tmp = CAP2_New - CAP2_Old; 192 3 B_Capture2 = 1; 193 3 } 194 2 } 195 1 196 1 if(CF) //PCA溢出中断 197 1 { 198 2 CF = 0; //清PCA溢出中断标志 199 2 } 200 1 201 1 } MODULE INFORMATION: STATIC OVERLAYABLE CODE SIZE = 849 ---- CONSTANT SIZE = ---- ---- XDATA SIZE = ---- ---- PDATA SIZE = ---- ---- DATA SIZE = 27 3 IDATA SIZE = ---- ---- BIT SIZE = 3 ---- END OF MODULE INFORMATION. C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)