while(1)
{
KEY = key_scan(0);
if (KEY == KEY2_PRES)
{
pwm_duty_temp += 500; //°´ÏÂkey2¼üÉèÖñȽÏֵΪ+500
[color=Red]if(pwm_duty_temp > 0) [/color] //ÅжÏÕý¸ººÅÉèÖÃÐýת·½Ïò
{
g_bldc_motor1.pwm_duty = pwm_duty_temp;
g_bldc_motor1.dir = CW; //˳ʱÕë Õýת
}
else
{
g_bldc_motor1.pwm_duty = -pwm_duty_temp;
g_bldc_motor1.dir = CCW;
}
g_bldc_motor1.run_flag = RUN;
start_motor();
}
else if(KEY == KEY3_PRES)
{
pwm_duty_temp -=500;
[color=Red]if(pwm_duty_temp <= -MAX_PWM_DUTY/2)
pwm_duty_temp = -MAX_PWM_DUTY/2;[/color]
if(pwm_duty_temp < 0)
{
g_bldc_motor1.pwm_duty = -pwm_duty_temp;
g_bldc_motor1.dir = CCW;
}
else
{
g_bldc_motor1.pwm_duty = pwm_duty_temp;
g_bldc_motor1.dir =CW;
}
g_bldc_motor1.run_flag = RUN;
start_motor();
}
[color=Red]else if((pwm_duty_temp > MAX_PWM_DUTY/2)&&(pwm_duty_temp < -MAX_PWM_DUTY/2)) //Èç¹ûÕ¼¿Õ±È´óÓÚ»òСÓÚÉ趨µÄÖµ£¬¾ÍÖ±½Ó¹Ø±Õµç»ú
{
stop_motor();
g_bldc_motor1.pwm_duty = 0;
g_bldc_motor1.run_flag = STOP;
pwm_duty_temp = 0;
}[/color]
Ddl_Delay1ms(10);
}
}
标红的代码注释掉之后就可以正常进主函数了,但是无法跳转到循环里面的按键扫描函数 |