我在主函数中调用了
void spot_spot(float x_next,float y_next) 函数,为什么这个函数需要很长时间才执行完,后面显示函数很久才执行一次,明显感觉刷新速率下来了。
这是怎么回事?是不是float定义参数的问题?这个应该怎么处理呢,这个函数在C8051上运行就很正常,希望大家指正一下错误,谢谢。
float Quick_Sqrt( float number )
{
long int i;
unsigned char j;
float x2, y;
const float threehalfs = 1.5F;
x2=number*0.5F;
y=number;
i=*(long*) &y; // 浮点数按BIT强行赋给长整形
i=0x5f3759df-(i>>1); // 没天理!!!!!
y=*(float*)&i;
for(j=0;j<1;j++)
{
y=y*(threehalfs-(x2*y*y)); // 第1次叠代
}
return (1/y);
}
//点点微小运动函数
void spot_spot(float x_next,float y_next)
{
float mtor_a_leth_next,mtor_b_leth_next;
float a_change,b_change;
int count_l,count_r;
mtor_a_leth_next=(x_next+15)*(x_next+15)+(115-y_next)*(115-y_next);
mtor_b_leth_next=(95-x_next)*(95-x_next)+(115-y_next)*(115-y_next);
mtor_a_leth_next=Quick_Sqrt(mtor_a_leth_next);//将要前进的那点的线段a的长度
mtor_b_leth_next=Quick_Sqrt(mtor_b_leth_next);
a_change=mtor_a_leth_next-mtor_a_leth_last;
b_change=mtor_b_leth_next-mtor_b_leth_last;
mtor_a_leth_last=mtor_a_leth_next;
mtor_b_leth_last=mtor_b_leth_next;
count_l=a_change/step_l+(a_change>=0?0.5:-0.5);
count_r=b_change/step_r+(b_change>=0?0.5:-0.5);
drive_motor(count_l,count_r);
x_last=x_next;
y_last=y_next;//将要走到的那个点的新坐标
} |