📄 c_softpwm.h
字号:
//左右轮占空比计数
unsigned char Left_SoftPwmCount;
unsigned char Right_SoftPwmCount;
unsigned char Car_run_Drection_L;
unsigned char Car_run_Drection_R;
//左右轮占空比设置
unsigned char Left_Pwm;
unsigned char Right_Pwm;
//1mS微时间临时
unsigned char TimeUsTmp;
/*
小车运行方向 1 前 2后
#define Car_Stop 0
#define Car_Goahead 1
#define Car_GoBack 2
*/
//小车控制初始化
void init_CarCtrl()
{
LightUpdates=1;
SETUP_TIMER_2(T2_DIV_BY_1,100,1);
}
#INT_TIMER2
void Soft_isr(void)
{
if (Left_SoftPwmCount==100)
{
Left_SoftPwmCount=0;
}
if (Right_SoftPwmCount==100)
{
Right_SoftPwmCount=0;
}
//右轮控制
if(Right_SoftPwmCount==0)
{
//前进
if (Car_run_Drection_R==Car_Goahead)
{
CC_Goahead_R();
}
if (Car_run_Drection_R==Car_GoBack)
{
CC_GoBack_R();
}
}
if(Right_SoftPwmCount==Right_Pwm)
{
CC_Stop_R();
}
//左轮控制
if(Left_SoftPwmCount==0)
{
CC_Stop_L();
}
if(Left_SoftPwmCount==Left_Pwm)
{
if (Car_run_Drection_L==Car_Goahead)
{
//前进
CC_Goahead_L();
}
if (Car_run_Drection_L==Car_GoBack)
{
CC_GoBack_L();
}
}
Left_SoftPwmCount++;
Right_SoftPwmCount++;
//1ms定时器
TimeUsTmp++;
if(TimeUsTmp==10)
{
TimeUsTmp=0;
TimeUs++;
};
}
//PWM有效比设置
void PWM_SetDuty(unsigned int16 Left_Pwm_Tmp,unsigned int16 Right_Pwm_Tmp)
{
//成比例
Left_Pwm_Tmp=(unsigned char)((StandedV*Left_Pwm_Tmp)/NowV);
Right_Pwm=(unsigned char)((StandedV*Right_Pwm_Tmp)/NowV);
//错开电流峰值
Left_Pwm=100-Left_Pwm_Tmp;
//防止超出范围
if (Left_Pwm>100)
{
Left_Pwm=100;
}
if (Right_Pwm>100)
{
Right_Pwm=100;
}
}
//PWM启动
void PWM_Start()
{
enable_interrupts(INT_TIMER2);
}
//PWM停止
void PWM_Stop()
{
disable_interrupts(INT_TIMER2);
CC_CarStop();
}
void PWM_SetDRC(unsigned char Left_Drection,unsigned char Right_Drection)
{
Car_run_Drection_L=Left_Drection;
Car_run_Drection_R=Right_Drection;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -