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