代码拉取完成,页面将自动刷新
同步操作将从 dk鲁晓东/STC15库 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#ifndef __HiPWM_H
#define __HiPWM_H
#include "config.h"
#define PWM_CYCLE 24000L //定义PWM周期(最大值为32767,实际为0即32768)
#define PWM_DeadZone 12 //
//增强型PWM输出引脚
sbit PWM2 = P3^7; //P2^7
sbit PWM3 = P2^1; //P4^5
sbit PWM4 = P2^2; //P4^4
sbit PWM5 = P2^3; //P4^2
sbit PWM6 = P1^7; //P0^7
sbit PWM7 = P1^6; //P0^6
#define PWM2_Pin_P37 0
#define PWM2_Pin_P27 1
#define PWM3_Pin_P21 0
#define PWM3_Pin_P45 1
#define PWM4_Pin_P22 0
#define PWM4_Pin_P44 1
#define PWM5_Pin_P23 0
#define PWM5_Pin_P42 1
#define PWM6_Pin_P17 0
#define PWM6_Pin_P07 1
#define PWM7_Pin_P16 0
#define PWM7_Pin_P06 1
#define CBIF 0X40
#define ECBI 0x40
//打开关闭XSFR的操作 P_SW2
#define XSFR_EN() P_SW2|=0X80
#define XSFR_DIS() P_SW2&=0X7F
//选择PWM输出引脚 PWMnCR XFSR
#define PWM2_Sele(Pin) PWM2CR=Pin? PWM2CR|((1<<3)):PWM2CR&(~(1<<3)) //
#define PWM3_Sele(Pin) PWM3CR=Pin? PWM3CR|((1<<3)):PWM3CR&(~(1<<3)) //
#define PWM4_Sele(Pin) PWM4CR=Pin? PWM4CR|((1<<3)):PWM4CR&(~(1<<3)) //
#define PWM5_Sele(Pin) PWM5CR=Pin? PWM5CR|((1<<3)):PWM5CR&(~(1<<3)) //
#define PWM6_Sele(Pin) PWM6CR=Pin? PWM6CR|((1<<3)):PWM6CR&(~(1<<3)) //
#define PWM7_Sele(Pin) PWM7CR=Pin? PWM7CR|((1<<3)):PWM7CR&(~(1<<3)) //
//初始电平设定 PWMCFG FSR
#define PWM2_PinLevel(v) PWMCFG=v? PWMCFG|(1<<0):PWMCFG&(~(1<<0))
#define PWM3_PinLevel(v) PWMCFG=v? PWMCFG|(1<<1):PWMCFG&(~(1<<1))
#define PWM4_PinLevel(v) PWMCFG=v? PWMCFG|(1<<2):PWMCFG&(~(1<<2))
#define PWM5_PinLevel(v) PWMCFG=v? PWMCFG|(1<<3):PWMCFG&(~(1<<3))
#define PWM6_PinLevel(v) PWMCFG=v? PWMCFG|(1<<4):PWMCFG&(~(1<<4))
#define PWM7_PinLevel(v) PWMCFG=v? PWMCFG|(1<<5):PWMCFG&(~(1<<5))
//使能PWM模块工作 PWMCR.7 SFR
#define PWM_En(Flag) PWMCR=Flag? PWMCR|(1<<7):PWMCR&(~(1<<7)) //yes no
//使能各支路PWM输出 PWMCR FSR
#define PWM2_PinOutEn(Flag) PWMCR=Flag? PWMCR|(1<<0):PWMCR&(~(1<<0)) //yes no
#define PWM3_PinOutEn(Flag) PWMCR=Flag? PWMCR|(1<<1):PWMCR&(~(1<<1)) //yes no
#define PWM4_PinOutEn(Flag) PWMCR=Flag? PWMCR|(1<<2):PWMCR&(~(1<<2)) //yes no
#define PWM5_PinOutEn(Flag) PWMCR=Flag? PWMCR|(1<<3):PWMCR&(~(1<<3)) //yes no
#define PWM6_PinOutEn(Flag) PWMCR=Flag? PWMCR|(1<<4):PWMCR&(~(1<<4)) //yes no
#define PWM7_PinOutEn(Flag) PWMCR=Flag? PWMCR|(1<<5):PWMCR&(~(1<<5)) //yes no
//PWM模块CLK 选择 PWMCKS xsfr
#define PWM_CLK_sys 0
#define PWM_CLK_T2 1
#define PWM_CLK_Source(S) PWMCKS=S? PWMCKS|(1<<4):PWMCKS&(~(1<<4))
#define PWM_CLK_sysDIV(n) PWMCKS=(PWMCKS&0xf0)|(n%16)
//PWMC =PWM_CYCLE; //设置模块PWM周期 XSFR
#define PWM_CYCLE_Set(value) PWMC =value%0x8000
//PWMnTx设置支路PWM的T1 T2 XSFR
#define PWM2_T1(value) PWM2T1 = value%0x8000
#define PWM2_T2(value) PWM2T2 = value%0x8000
#define PWM3_T1(value) PWM3T1 = value%0x8000
#define PWM3_T2(value) PWM3T2 = value%0x8000
#define PWM4_T1(value) PWM4T1 = value%0x8000
#define PWM4_T2(value) PWM4T2 = value%0x8000
#define PWM5_T1(value) PWM5T1 = value%0x8000
#define PWM5_T2(value) PWM5T2 = value%0x8000
#define PWM6_T1(value) PWM6T1 = value%0x8000
#define PWM6_T2(value) PWM6T2 = value%0x8000
#define PWM7_T1(value) PWM7T1 = value%0x8000
#define PWM7_T2(value) PWM7T2 = value%0x8000
//PWMnTx设置支路PWM的中断是否需要 XSFR
//#define PWM2_IntEN(Flag) PWM2CR=Flag? PWM2CR|0x04:PWM2CR&~0x04 //屏蔽支路的中断EPWM2I EC2T1SI
//#define PWM2_T2_IntEN(Flag) PWM2CR=Flag? PWM2CR|0x02:PWM2CR&~0x02 //屏蔽支路的中断EPWM2I EC2T2SI
#define PWM_T_ALL 0
#define PWM_T1 1
#define PWM_T2 2
//Flag=0,都关闭中断;Flag=1,分T_ALL,T1,T2
#define PWM2_IntEN(Flag,t) PWM2CR=Flag? ((t<1)? PWM2CR|0x07:((PWM2CR&0xF8)+0x04+t)):PWM2CR&~0x04 //屏蔽支路的中断EPWM2I EC2T1SI
#define PWM3_IntEN(Flag,t) PWM3CR=Flag? ((t<1)? PWM3CR|0x07:((PWM3CR&0xF8)+0x04+t)):PWM3CR&~0x04
#define PWM4_IntEN(Flag,t) PWM4CR=Flag? ((t<1)? PWM4CR|0x07:((PWM4CR&0xF8)+0x04+t)):PWM4CR&~0x04
#define PWM5_IntEN(Flag,t) PWM5CR=Flag? ((t<1)? PWM5CR|0x07:((PWM5CR&0xF8)+0x04+t)):PWM5CR&~0x04
#define PWM6_IntEN(Flag,t) PWM6CR=Flag? ((t<1)? PWM6CR|0x07:((PWM6CR&0xF8)+0x04+t)):PWM6CR&~0x04
#define PWM7_IntEN(Flag,t) PWM7CR=Flag? ((t<1)? PWM7CR|0x07:((PWM7CR&0xF8)+0x04+t)):PWM7CR&~0x04
#define PWM_IntEN(Flag) PWMCR=Flag? PWMCR|(1<<6): PWMCR&~(1<<6)
void HiPWM_config(void);
void PWM2_SetPwmWide(unsigned short Wide); //u16
void PWM3_SetPwmWide(unsigned short Wide);
//void PWM4_SetPwmWide(unsigned short Wide);
//void PWM5_SetPwmWide(unsigned short Wide);
//void PWM6_SetPwmWide(unsigned short Wide);
//void PWM7_SetPwmWide(unsigned short Wide);
#endif
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。