C51 COMPILER V9.59.0.0 APP_PCA_PWM 06/10/2021 15:42:34 PAGE 1 C51 COMPILER V9.59.0.0, COMPILATION OF MODULE APP_PCA_PWM OBJECT MODULE PLACED IN .\list\APP_PCA_PWM.obj COMPILER INVOKED BY: C:\Keil_v5\C51\BIN\C51.EXE ..\App\src\APP_PCA_PWM.c LARGE OMF2 OPTIMIZE(8,SPEED) BROWSE INCDIR(..\D -river\inc;..\User;..\App\inc) DEBUG PRINT(.\list\APP_PCA_PWM.lst) TABS(2) OBJECT(.\list\APP_PCA_PWM.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 "APP.h" 14 #include "STC8A_PCA.h" 15 #include "STC8A_GPIO.h" 16 #include "STC8A_NVIC.h" 17 18 /************* 功能说明 *************** 19 20 输出4路变化的PWM信号, 类似"呼吸灯"的驱动. 21 PCA0 P1.7 为8位PWM. 22 PCA1 P1.6 为7位PWM. 23 PCA2 P1.5 为6位PWM, 输出PWM 1秒钟, 输出低电平1秒钟, 输出高电平1秒钟, 反复循环. 24 PCA3 P1.4 为10位PWM. 25 26 下载时, 选择时钟 24MHz (用户可在"config.h"修改频率). 27 28 ******************************************/ 29 30 31 //======================================================================== 32 // 本地常量声明 33 //======================================================================== 34 35 36 //======================================================================== 37 // 本地变量声明 38 //======================================================================== 39 40 static u16 pwm0,pwm1,pwm2,pwm3; 41 static bit B_PWM0_Dir,B_PWM1_Dir,B_PWM2_Dir,B_PWM3_Dir; //方向, 0为+, 1为-. 42 43 //======================================================================== 44 // 本地函数声明 45 //======================================================================== 46 47 48 //======================================================================== 49 // 外部函数和变量声明 50 //======================================================================== 51 52 53 //======================================================================== 54 // 函数: PCA_PWM_init C51 COMPILER V9.59.0.0 APP_PCA_PWM 06/10/2021 15:42:34 PAGE 2 55 // 描述: 用户初始化程序. 56 // 参数: None. 57 // 返回: None. 58 // 版本: V1.0, 2020-09-28 59 //======================================================================== 60 void PCA_PWM_init(void) 61 { 62 1 PCA_InitTypeDef PCA_InitStructure; 63 1 64 1 P1_MODE_IO_PU(GPIO_Pin_HIGH); //P1.4~P1.7 设置为准双向口 65 1 //-------------------------------------------- 66 1 PCA_InitStructure.PCA_PWM_Wide = PCA_PWM_8bit; //PCA_PWM_8bit, PCA_PWM_7bit, PCA_PWM_6bit, PCA_PWM_10bit 67 1 PCA_InitStructure.PCA_Value = 128 << 8; //对于PWM,高8位为PWM占空比 68 1 PCA_Init(PCA0,&PCA_InitStructure); 69 1 70 1 PCA_InitStructure.PCA_PWM_Wide = PCA_PWM_7bit; //PCA_PWM_8bit, PCA_PWM_7bit, PCA_PWM_6bit, PCA_PWM_10bit 71 1 PCA_InitStructure.PCA_Value = 64 << 8; //对于PWM,高8位为PWM占空比 72 1 PCA_Init(PCA1,&PCA_InitStructure); 73 1 74 1 PCA_InitStructure.PCA_PWM_Wide = PCA_PWM_6bit; //PCA_PWM_8bit, PCA_PWM_7bit, PCA_PWM_6bit, PCA_PWM_10bit 75 1 PCA_InitStructure.PCA_Value = 32 << 8; //对于PWM,高8位为PWM占空比 76 1 PCA_Init(PCA2,&PCA_InitStructure); 77 1 78 1 PCA_InitStructure.PCA_PWM_Wide = PCA_PWM_10bit; //PCA_PWM_8bit, PCA_PWM_7bit, PCA_PWM_6bit, PCA_PWM_10bi -t 79 1 PCA_InitStructure.PCA_Value = 256 << 8; //对于PWM,高8位为PWM占空比 80 1 PCA_Init(PCA3,&PCA_InitStructure); 81 1 82 1 PCA_InitStructure.PCA_Clock = PCA_Clock_1T; //PCA_Clock_1T, PCA_Clock_2T, PCA_Clock_4T, PCA_Clock_6T, - PCA_Clock_8T, PCA_Clock_12T, PCA_Clock_Timer0_OF, PCA_Clock_ECI 83 1 PCA_InitStructure.PCA_RUN = ENABLE; //ENABLE, DISABLE 84 1 PCA_Init(PCA_Counter,&PCA_InitStructure); //设置公用Counter 85 1 86 1 NVIC_PCA_Init(PCA_Counter,PCA_Mode_PWM,Priority_0); 87 1 NVIC_PCA_Init(PCA0,PCA_Mode_PWM,Priority_0); 88 1 NVIC_PCA_Init(PCA1,PCA_Mode_PWM,Priority_0); 89 1 NVIC_PCA_Init(PCA2,PCA_Mode_PWM,Priority_0); 90 1 NVIC_PCA_Init(PCA3,PCA_Mode_PWM,Priority_0); 91 1 //-------------------------------------------- 92 1 pwm0 = 128; 93 1 pwm1 = 64; 94 1 pwm2 = 32; 95 1 pwm3 = 512; 96 1 B_PWM0_Dir = 0; 97 1 B_PWM1_Dir = 0; 98 1 B_PWM2_Dir = 0; 99 1 B_PWM3_Dir = 0; 100 1 101 1 UpdatePcaPwm(PCA0,pwm0); 102 1 UpdatePcaPwm(PCA1,pwm1); 103 1 UpdatePcaPwm(PCA2,pwm2); 104 1 UpdatePcaPwm(PCA3,pwm3); 105 1 } 106 107 108 //======================================================================== 109 // 函数: Sample_PCA_PWM 110 // 描述: 用户应用程序. 111 // 参数: None. 112 // 返回: None. 113 // 版本: V1.0, 2020-09-28 114 //======================================================================== C51 COMPILER V9.59.0.0 APP_PCA_PWM 06/10/2021 15:42:34 PAGE 3 115 void Sample_PCA_PWM(void) 116 { 117 1 if(B_PWM0_Dir) 118 1 { 119 2 if(--pwm0 <= 16) B_PWM0_Dir = 0; //8位PWM 120 2 } 121 1 else if(++pwm0 >= 240) B_PWM0_Dir = 1; //8位PWM 122 1 UpdatePcaPwm(PCA0,pwm0); 123 1 124 1 if(B_PWM1_Dir) 125 1 { 126 2 if(--pwm1 <= 8) B_PWM1_Dir = 0; //7位PWM 127 2 } 128 1 else if(++pwm1 >= 120) B_PWM1_Dir = 1; //7位PWM 129 1 UpdatePcaPwm(PCA1,pwm1); 130 1 131 1 // if(B_PWM2_Dir) 132 1 // { 133 1 // if(--pwm2 <= 4) B_PWM2_Dir = 0; //6位PWM 134 1 // } 135 1 // else if(++pwm2 >= 60) B_PWM2_Dir = 1; //6位PWM 136 1 // UpdatePcaPwm(PCA2,pwm2); 137 1 138 1 if(pwm2 >= 300) 139 1 { 140 2 pwm2 = 0; 141 2 } 142 1 else if(pwm2 >= 200) 143 1 { 144 2 PCALevelSet(PCA2,1); //PWM_ID, 强制输出高电平 145 2 } 146 1 else if(pwm2 >= 100) 147 1 { 148 2 PCALevelSet(PCA2,0); //PWM_ID, 强制输出低电平 149 2 } 150 1 else 151 1 { 152 2 UpdatePcaPwm(PCA2,32);//PWM_ID, 输出PWM 153 2 } 154 1 pwm2++; 155 1 156 1 if(B_PWM3_Dir) 157 1 { 158 2 if(--pwm3 <= 24) B_PWM3_Dir = 0; //10位PWM 159 2 } 160 1 else if(++pwm3 >= 1000) B_PWM3_Dir = 1; //10位PWM 161 1 UpdatePcaPwm(PCA3,pwm3); 162 1 } 163 164 165 MODULE INFORMATION: STATIC OVERLAYABLE CODE SIZE = 523 ---- CONSTANT SIZE = ---- ---- XDATA SIZE = 8 5 PDATA SIZE = ---- ---- DATA SIZE = ---- ---- IDATA SIZE = ---- ---- BIT SIZE = 4 ---- EDATA SIZE = ---- ---- C51 COMPILER V9.59.0.0 APP_PCA_PWM 06/10/2021 15:42:34 PAGE 4 HDATA SIZE = ---- ---- XDATA CONST SIZE = ---- ---- FAR CONST SIZE = ---- ---- END OF MODULE INFORMATION. C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)