代码拉取完成,页面将自动刷新
同步操作将从 dk鲁晓东/STC15库 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include "HiPWM.h"
u16 code T_SinTable[128]={
128,134,140,146,152,158,164,170,
176,182,187,193,198,203,208,213,
217,222,226,230,233,236,240,242,
245,247,249,251,252,253,254,254,
255,254,254,253,252,251,249,247,
245,242,240,236,233,230,226,222,
217,213,208,203,198,193,187,182,
176,170,164,158,152,146,140,134,
128,121,115,109,103,97,91,85,
79,73,68,62,57,52,47,42,
38,33,29,25,22,19,15,13,
10,8,6,4,3,2,1,1,
1,1,1,2,3,4,6,8,
10,13,15,19,22,25,29,33,
38,42,47,52,57,62,68,73,
79,85,91,97,103,109,115,121
};
void HiPWM_config()
{
//引脚初始化
// 打开XSFR XSFR_EN();
////选择PWM引脚 PWM2_Sele(PWM2_Pin_P37);
////初始电平设置 PWM2_PinLevel(Low);
////设置各支路的T1和T2初始值 PWM2_T1(1); PWM2_T2(0);
////支路输出使能 PWM2_PinOutEn(OK);
////设置模块时钟源、周期 PWM_CLK_Source(PWM_CLK_sys);PWM_CLK_sysDIV(0);PWM_CYCLE_Set(PWM_CYCLE);
////最后使能PWM模块 PWM_En(OK);
// 关闭XSFR XSFR_DIS();
// u8 xdata *px;
XSFR_EN(); // 访问XFR
PWM3_Sele(PWM3_Pin_P21);
PWM3_T1(65); PWM3_T2(1220);
PWM3_PinOutEn(OK);
PWM3_PinLevel(Low);
PWM4_Sele(PWM4_Pin_P22);
PWM4_T1(65-PWM_DeadZone); PWM4_T2(1220+PWM_DeadZone);//
PWM4_PinLevel(High);
PWM4_PinOutEn(OK);
PWM_CLK_Source(PWM_CLK_sys);
PWM_CLK_sysDIV(0);
PWM_CYCLE_Set(PWM_CYCLE);//
XSFR_EN(); // 恢复访问XRAM EAXRAM();
PWM_En(OK);//PWMCR |= ENPWM; // 使能PWM波形发生器,PWM计数器开始计数
PWM_IntEN(YES); // 允许PWM计数器归零中断
}
void PWM2_SetPwmWide(unsigned short Wide)
{//p37
if (Wide == 0)
{PWM2_PinOutEn(NO);//关闭输出
PWM2 = 0; //直接输出0
}
else if (Wide == PWM_CYCLE)
{PWM2_PinOutEn(NO);
PWM2 = 1; //直接输出1
}
else
{
XSFR_EN();
PWM2_T1(Wide);PWM2_T2(0) ;
XSFR_DIS();
PWM2_PinOutEn(OK);
}
}
void PWM3_SetPwmWide(unsigned short Wide)
{//p21
if (Wide == 0)
{
PWM3_PinOutEn(NO);//关闭输出
PWM3 = 0;
}
else if (Wide == PWM_CYCLE)
{
PWM3_PinOutEn(NO);//关闭输出
PWM3 = 1;
}
else
{
XSFR_EN();
PWM3_T1(Wide);PWM3_T2(0) ;
XSFR_DIS();
PWM3_PinOutEn(OK);
}
}
void HiPWM_Routine(void) interrupt 22
{
//u8 xdata *px;
static u8 PWM_Index=0;
u16 j;
u8 SW2_tmp;
if(PWMIF & CBIF) //PWM计数器归零中断标志
{
PWMIF &= ~CBIF; //清除中断标志
SW2_tmp = P_SW2; //保存SW2设置
XSFR_EN();
j = T_SinTable[PWM_Index]+65;//因为前面设置T1从65开始的
PWM3_T2(j);
j += PWM_DeadZone; //死区
PWM4_T2(j);
P_SW2 = SW2_tmp; //恢复SW2设置
if(++PWM_Index >= 128) PWM_Index = 0;
}
}
void HiPWMFD_Routine(void) interrupt 23
{
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。