C51 COMPILER V9.59.0.0 MAIN 06/10/2021 15:11:17 PAGE 1 C51 COMPILER V9.59.0.0, COMPILATION OF MODULE MAIN OBJECT MODULE PLACED IN .\list\main.obj COMPILER INVOKED BY: C:\Keil_v5\C51\BIN\C51.EXE main.c OMF2 OPTIMIZE(8,SPEED) BROWSE DEBUG PRINT(.\list\main.lst) TABS(2 -) OBJECT(.\list\main.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 "config.h" 14 #include "STC8A_PCA.h" 15 #include "STC8A_GPIO.h" 16 #include "STC8A_NVIC.h" 17 #include "STC8A_Delay.h" 18 #include "STC8A_Switch.h" 19 20 /************* 功能说明 *************** 21 22 输出3路变化的PWM信号, 类似"呼吸灯"的驱动. 23 24 PCA0, PCA1, PCA2 为16位PWM. 25 26 下载时, 选择时钟 24MHz (用户可在"config.h"修改频率). 27 28 ******************************************/ 29 30 /************* 本地常量声明 **************/ 31 32 //#define PWM_DUTY 6000 //定义PWM的周期,数值为PCA所选择的时钟脉冲个数。 33 //#define PWM_HIGH_MIN 80 //限制PWM输出的最小占空比。 34 //#define PWM_HIGH_MAX (PWM_DUTY - PWM_HIGH_MIN) //限制PWM输出的最大占空比。 35 36 /************* 本地变量声明 **************/ 37 38 //u16 pwm0,pwm1,pwm2,pwm3; 39 //bit B_PWM0_Dir,B_PWM1_Dir,B_PWM2_Dir,B_PWM3_Dir; //方向, 0为+, 1为-. 40 41 /************* 本地函数声明 **************/ 42 43 44 /************* 外部函数和变量声明 *****************/ 45 46 47 /******************** IO口配置 ********************/ 48 void GPIO_config(void) 49 { 50 1 P2_MODE_IO_PU(GPIO_Pin_3 | GPIO_Pin_HIGH); //P2.3~P2.7 设置为准双向口 51 1 PCA_SW(PCA_P22_P23_P24_P25_P26); //PCA_P12_P17_P16_P15_P14,PCA_P22_P23_P24_P25_P26,PCA_P74_P70_P71_P72_P7 -3,PCA_P35_P33_P32_P31_P30 52 1 } 53 C51 COMPILER V9.59.0.0 MAIN 06/10/2021 15:11:17 PAGE 2 54 /******************** PCA配置 ********************/ 55 void PCA_config(void) 56 { 57 1 PCA_InitTypeDef PCA_InitStructure; 58 1 59 1 PCA_InitStructure.PCA_PWM_Wide = 0; //PCA_PWM_8bit, PCA_PWM_7bit, PCA_PWM_6bit, PCA_PWM_10bit 60 1 PCA_InitStructure.PCA_Value = 0xffff; //对于软件定时, 为匹配比较值 61 1 PCA_Init(PCA0,&PCA_InitStructure); 62 1 63 1 PCA_InitStructure.PCA_PWM_Wide = 0; //PCA_PWM_8bit, PCA_PWM_7bit, PCA_PWM_6bit, PCA_PWM_10bit 64 1 PCA_InitStructure.PCA_Value = 0x7fff; //对于软件定时, 为匹配比较值 65 1 PCA_Init(PCA1,&PCA_InitStructure); 66 1 67 1 PCA_InitStructure.PCA_PWM_Wide = 0; //PCA_PWM_8bit, PCA_PWM_7bit, PCA_PWM_6bit, PCA_PWM_10bit 68 1 PCA_InitStructure.PCA_Value = 0x3fff; //对于软件定时, 为匹配比较值 69 1 PCA_Init(PCA2,&PCA_InitStructure); 70 1 71 1 PCA_InitStructure.PCA_PWM_Wide = 0; //PCA_PWM_8bit, PCA_PWM_7bit, PCA_PWM_6bit, PCA_PWM_10bit 72 1 PCA_InitStructure.PCA_Value = 0x1fff; //对于软件定时, 为匹配比较值 73 1 PCA_Init(PCA3,&PCA_InitStructure); 74 1 75 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 76 1 PCA_InitStructure.PCA_RUN = ENABLE; //ENABLE, DISABLE 77 1 PCA_Init(PCA_Counter,&PCA_InitStructure); //设置公用Counter 78 1 79 1 NVIC_PCA_Init(PCA_Counter,PCA_Mode_HighPulseOutput,Priority_0); 80 1 NVIC_PCA_Init(PCA0,PCA_Mode_HighPulseOutput,Priority_0); 81 1 NVIC_PCA_Init(PCA1,PCA_Mode_HighPulseOutput,Priority_0); 82 1 NVIC_PCA_Init(PCA2,PCA_Mode_HighPulseOutput,Priority_0); 83 1 NVIC_PCA_Init(PCA3,PCA_Mode_HighPulseOutput,Priority_0); 84 1 } 85 86 /******************** main **************************/ 87 void main(void) 88 { 89 1 GPIO_config(); 90 1 PCA_config(); 91 1 // pwm0 = (PWM_DUTY / 4 * 1); //给PWM一个初值 92 1 // pwm1 = (PWM_DUTY / 4 * 2); 93 1 // pwm2 = (PWM_DUTY / 4 * 3); 94 1 // pwm3 = (PWM_DUTY); 95 1 // B_PWM0_Dir = 0; 96 1 // B_PWM1_Dir = 0; 97 1 // B_PWM2_Dir = 0; 98 1 // B_PWM3_Dir = 0; 99 1 100 1 // UpdatePcaPwm(PCA0,pwm0); 101 1 // UpdatePcaPwm(PCA1,pwm1); 102 1 // UpdatePcaPwm(PCA2,pwm2); 103 1 // UpdatePcaPwm(PCA3,pwm3); 104 1 EA = 1; 105 1 106 1 while (1) 107 1 { 108 2 // delay_ms(1); 109 2 110 2 // if(B_PWM0_Dir) 111 2 // { 112 2 // if(--pwm0 <= PWM_HIGH_MIN) B_PWM0_Dir = 0; 113 2 // } 114 2 // else if(++pwm0 >= PWM_HIGH_MAX) B_PWM0_Dir = 1; C51 COMPILER V9.59.0.0 MAIN 06/10/2021 15:11:17 PAGE 3 115 2 // UpdatePcaPwm(PCA0,pwm0); 116 2 117 2 // if(B_PWM1_Dir) 118 2 // { 119 2 // if(--pwm1 <= PWM_HIGH_MIN) B_PWM1_Dir = 0; 120 2 // } 121 2 // else if(++pwm1 >= PWM_HIGH_MAX) B_PWM1_Dir = 1; 122 2 // UpdatePcaPwm(PCA1,pwm1); 123 2 124 2 // if(B_PWM2_Dir) 125 2 // { 126 2 // if(--pwm2 <= PWM_HIGH_MIN) B_PWM2_Dir = 0; 127 2 // } 128 2 // else if(++pwm2 >= PWM_HIGH_MAX) B_PWM2_Dir = 1; 129 2 // UpdatePcaPwm(PCA2,pwm2); 130 2 } 131 1 } 132 133 134 MODULE INFORMATION: STATIC OVERLAYABLE CODE SIZE = 163 ---- CONSTANT SIZE = ---- ---- XDATA SIZE = ---- ---- PDATA SIZE = ---- ---- DATA SIZE = ---- 5 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)