C51 COMPILER V9.59.0.0 APP_PWM15BIT 06/10/2021 10:21:40 PAGE 1 C51 COMPILER V9.59.0.0, COMPILATION OF MODULE APP_PWM15BIT OBJECT MODULE PLACED IN .\list\APP_PWM15bit.obj COMPILER INVOKED BY: C:\Keil_v5\C51\BIN\C51.EXE ..\App\src\APP_PWM15bit.c LARGE OMF2 OPTIMIZE(8,SPEED) BROWSE INCDIR(..\ -Driver\inc;..\User;..\App\inc) DEBUG PRINT(.\list\APP_PWM15bit.lst) TABS(2) OBJECT(.\list\APP_PWM15bit.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_GPIO.h" 15 #include "STC8A_PWM15bit.h" 16 17 /************* 功能说明 *************** 18 19 输出4路PWM信号: 20 PWM0 输出"呼吸灯"效果PWM. 21 PWM1 循环输出1秒钟PWM,1秒钟高电平,1秒钟低电平. 22 PWM2,PWM3 固定PWM. 23 24 下载时, 选择时钟 24MHz (用户可在"config.h"修改频率). 25 26 ******************************************/ 27 28 29 //======================================================================== 30 // 本地常量声明 31 //======================================================================== 32 33 34 //======================================================================== 35 // 本地变量声明 36 //======================================================================== 37 38 u16 pwm0,pwm1; 39 bit B_PWM0_Dir; //方向, 0为+, 1为-. 40 41 //======================================================================== 42 // 本地函数声明 43 //======================================================================== 44 45 46 //======================================================================== 47 // 外部函数和变量声明 48 //======================================================================== 49 50 51 //======================================================================== 52 // 函数: PWM15bit_init 53 // 描述: 用户初始化程序. 54 // 参数: None. C51 COMPILER V9.59.0.0 APP_PWM15BIT 06/10/2021 10:21:40 PAGE 2 55 // 返回: None. 56 // 版本: V1.0, 2020-09-28 57 //======================================================================== 58 void PWM15bit_init(void) 59 { 60 1 GPIO_InitTypeDef GPIO_InitStructure; //结构定义 61 1 PWM15_InitTypeDef PWM15_InitStructure; 62 1 63 1 GPIO_InitStructure.Pin = GPIO_Pin_All; //指定要初始化的IO, GPIO_Pin_0 ~ GPIO_Pin_7, 或操作 64 1 GPIO_InitStructure.Mode = GPIO_PullUp; //指定IO的输入或输出方式,GPIO_PullUp,GPIO_HighZ,GPIO_OUT_OD,GPIO -_OUT_PP 65 1 GPIO_Inilize(GPIO_P2,&GPIO_InitStructure); //初始化 66 1 67 1 PWM15_InitStructure.PWM_Enable = ENABLE; //PWM使能, ENABLE, DISABLE 68 1 PWM15_InitStructure.PWM_Period = 0x1000; //PWM周期, 0~0x7fff 69 1 PWM15_InitStructure.PWM_Clock_Sel = PWM_CLK_SYS; //时钟源选择, PWM_CLK_SYS, PWM_CLK_TM2 70 1 PWM15_InitStructure.PWM_Clock_PS = 0; //系统时钟分频参数(PS+1分频), 0~15 71 1 PWM15_InitStructure.PWM_CInt = DISABLE; //计数器归零中断使能, ENABLE, DISABLE 72 1 PWM15_InitStructure.PWM_Counter = ENABLE; //计数器使能, ENABLE, DISABLE 73 1 PWM15_Init(&PWM15_InitStructure); 74 1 75 1 PWM15Duty(PWM15_0,0x000,0x200); //PWM_ID, 输出低电平位置, 输出高电平位置 76 1 PWM15Duty(PWM15_1,0x200,0xc00); //PWM_ID, 输出低电平位置, 输出高电平位置 77 1 PWM15Duty(PWM15_2,0x400,0x800); //PWM_ID, 输出低电平位置, 输出高电平位置 78 1 PWM15Duty(PWM15_3,0x800,0xe00); //PWM_ID, 输出低电平位置, 输出高电平位置 79 1 PWMChannelCtrl(PWM15_0,ENABLE,0,DISABLE,DISABLE,DISABLE); //PWM_ID, 输出使能, 初始电平, PWM中断, 第二个触 -发点中断, 第一触发点中断 80 1 PWMChannelCtrl(PWM15_1,ENABLE,0,DISABLE,DISABLE,DISABLE); //PWM_ID, 输出使能, 初始电平, PWM中断, 第二个触 -发点中断, 第一触发点中断 81 1 PWMChannelCtrl(PWM15_2,ENABLE,0,DISABLE,DISABLE,DISABLE); //PWM_ID, 输出使能, 初始电平, PWM中断, 第二个触 -发点中断, 第一触发点中断 82 1 PWMChannelCtrl(PWM15_3,ENABLE,0,DISABLE,DISABLE,DISABLE); //PWM_ID, 输出使能, 初始电平, PWM中断, 第二个触 -发点中断, 第一触发点中断 83 1 84 1 pwm0 = 0; 85 1 pwm1 = 0; 86 1 B_PWM0_Dir = 0; 87 1 } 88 89 //======================================================================== 90 // 函数: Sample_PWM15bit 91 // 描述: 用户应用程序. 92 // 参数: None. 93 // 返回: None. 94 // 版本: V1.0, 2020-09-28 95 //======================================================================== 96 void Sample_PWM15bit(void) 97 { 98 1 if(B_PWM0_Dir) 99 1 { 100 2 if(--pwm0 <= 0x100) B_PWM0_Dir = 0; //PWM0 101 2 } 102 1 else if(++pwm0 >= 0xf00) B_PWM0_Dir = 1; //PWM0 103 1 PWM15Duty(PWM15_0,0,pwm0); 104 1 105 1 if(pwm1 >= 3000) 106 1 { 107 2 pwm1 = 0; 108 2 } 109 1 else if(pwm1 >= 2000) 110 1 { 111 2 PWMLevelSet(PWM15_1,ENABLE,DISABLE); //PWM_ID, 强制输出低电平, 强制输出高电平 C51 COMPILER V9.59.0.0 APP_PWM15BIT 06/10/2021 10:21:40 PAGE 3 112 2 } 113 1 else if(pwm1 >= 1000) 114 1 { 115 2 PWMLevelSet(PWM15_1,DISABLE,ENABLE); //PWM_ID, 强制输出低电平, 强制输出高电平 116 2 } 117 1 else 118 1 { 119 2 PWMLevelSet(PWM15_1,DISABLE,DISABLE); //PWM_ID, 强制输出低电平, 强制输出高电平 120 2 } 121 1 pwm1++; 122 1 } 123 124 125 MODULE INFORMATION: STATIC OVERLAYABLE CODE SIZE = 334 ---- CONSTANT SIZE = ---- ---- XDATA SIZE = 4 9 PDATA SIZE = ---- ---- DATA SIZE = ---- ---- IDATA SIZE = ---- ---- BIT SIZE = 1 ---- EDATA SIZE = ---- ---- HDATA SIZE = ---- ---- XDATA CONST SIZE = ---- ---- FAR CONST SIZE = ---- ---- END OF MODULE INFORMATION. C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)