szkei 发表于 2020-8-14 18:59

【ESK32-360测评】+LCD库函数BUG测评反馈

本帖最后由 szkei 于 2020-8-14 22:41 编辑

<p><strong>一,上篇使用了LCD库函数显示奥运五色环及合泰测评的图片。<a href="https://bbs.eeworld.com.cn/thread-1136336-1-1.html" target="_blank">帖子链接。</a></strong></p>

<p><strong>二,函数坐标顺序位置对调。</strong></p>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 继续使用后发现上个测评所用到以下的函数的坐标顺序是对调,出来效果是X,Y坐标对调。&nbsp;&nbsp;&nbsp;&nbsp;</p>

<p>&nbsp;&nbsp;&nbsp; 1,void&nbsp; LCD_CircleDraw (u32 X_Location, u32 Y_Location, u32 Radius) ; //画半径参数的圆<br />
&nbsp;&nbsp;&nbsp; 2,void&nbsp; LCD_LineDraw (u32 X_Location, u32 Y_Location, u32 Length, u32 Direction) ;//画线</p>

<p>&nbsp; &nbsp; 3,void&nbsp; LCD_PicDraw (u8 X_Location, u16 Y_Location, u8 Height, u16 Width, uc8 *Pptr) ;//显示图片<br />
&nbsp;&nbsp;&nbsp; 4, void&nbsp; LCD_RectDraw (u32 X_Location, u32 Y_Location, u32 Height, u32 Width) //画方框</p>

<p><strong>三,各个函数输入不同坐标显示。</strong></p>

<p><strong>&nbsp;&nbsp; </strong>1,void&nbsp; LCD_CircleDraw (u32 X_Location, u32 Y_Location, u32 Radius) ; //画半径参数的圆</p>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LCD_CircleDraw (50,50,50);</p>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LCD_CircleDraw (100,50,50);</p>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; LCD_CircleDraw (50,100,50);</p>

<p></p>

<p>以上三个输入坐标,只有第一个不察觉到,第二及第三的从标是Y,X的方向显示了。</p>

<p>&nbsp;2,void&nbsp; LCD_LineDraw (u32 X_Location, u32 Y_Location, u32 Length, u32 Direction) ;//画线</p>

<p>LCD_LineDraw(0,0,100,0);</p>

<p></p>

<p>LCD_LineDraw(100,0,100,0);</p>

<p></p>

<p>LCD_LineDraw(0,100,100,0);</p>

<p></p>

<p>&nbsp;</p>

<p>3,void&nbsp; LCD_PicDraw (u8 X_Location, u16 Y_Location, u8 Height, u16 Width, uc8 *Pptr) ;//显示图片<br />
4, void&nbsp; LCD_RectDraw (u32 X_Location, u32 Y_Location, u32 Height, u32 Width) //画方框</p>

<p>这二个同样显示显示效果坐标同上二个一样,在此省略。</p>

<p><strong>四,void&nbsp; LCD_CircleDraw (u32 X_Location, u32 Y_Location, u32 Radius) ,存在严重的BUG。</strong></p>

<p><strong>&nbsp;&nbsp; </strong>1,当Radius输入为0时,存在以下二种情况。</p>

<p>&nbsp;&nbsp; 2,不在while等循环体内,无法正常显示。屏幕没有显示,白色底图一张。</p>

<p>3,当在循环体内,显示杂乱,成一条条直线,直至布满整个屏幕。</p>

<p></p>

<p>4,进入LCD_CircleDraw函数内,代码如下:</p>

<pre>
<code>/*********************************************************************************************************//**
* <a href="home.php?mod=space&amp;uid=159083" target="_blank">@brief</a>Display a circle.
* @paramX_Location: specify the X position.
* @paramY_Location: specify the Y position.
* @paramRadius: radius of the circle.
* @retval None
***********************************************************************************************************/
void LCD_CircleDraw(u32 X_Location, u32 Y_Location, u32 Radius)
{
s32DV;// Decision Variable
u32X_Value;      // Current X Value
u32Y_Value;      // Current Y Value
       

DV = 3 - (Radius &lt;&lt; 1);
X_Value = 0;
Y_Value = Radius;

while (X_Value &lt;= Y_Value)
{
    LCD_StarterSet(X_Location + X_Value, Y_Location + Y_Value);
    LCD_WriteRAMWord(Color_Text);

    LCD_StarterSet(X_Location + X_Value, Y_Location - Y_Value);
    LCD_WriteRAMWord(Color_Text);

    LCD_StarterSet(X_Location - X_Value, Y_Location + Y_Value);
    LCD_WriteRAMWord(Color_Text);

    LCD_StarterSet(X_Location - X_Value, Y_Location - Y_Value);
    LCD_WriteRAMWord(Color_Text);

    LCD_StarterSet(X_Location + Y_Value, Y_Location + X_Value);
    LCD_WriteRAMWord(Color_Text);

    LCD_StarterSet(X_Location + Y_Value, Y_Location - X_Value);
    LCD_WriteRAMWord(Color_Text);

    LCD_StarterSet(X_Location - Y_Value, Y_Location + X_Value);
    LCD_WriteRAMWord(Color_Text);

    LCD_StarterSet(X_Location - Y_Value, Y_Location - X_Value);
    LCD_WriteRAMWord(Color_Text);

    if (DV &lt; 0)
    {
      DV += (X_Value &lt;&lt; 2) + 6;
    }
    else
    {
      DV += ((X_Value - Y_Value) &lt;&lt; 2) + 10;
      Y_Value--;
    }
    X_Value++;
}
}</code></pre>

<p>5,查看分析,发现是Y_Value--,没有先判断为是否为0。如果是0,执行后Y_Value的值等于 2^32 - 1 = 4294967295,一直不断循环执行下去。只要先判断不为0时,才能执行Y_Value--,这样才不会一直循环执行下去。修改代码如下:</p>

<pre>
<code>/*********************************************************************************************************//**
* @briefDisplay a circle.
* @paramX_Location: specify the X position.
* @paramY_Location: specify the Y position.
* @paramRadius: radius of the circle.
* @retval None
***********************************************************************************************************/
void LCD_CircleDraw(u32 X_Location, u32 Y_Location, u32 Radius)
{
s32DV;// Decision Variable
u32X_Value;      // Current X Value
u32Y_Value;      // Current Y Value
       

DV = 3 - (Radius &lt;&lt; 1);
X_Value = 0;
Y_Value = Radius;

while (X_Value &lt;= Y_Value)
{
    LCD_StarterSet(X_Location + X_Value, Y_Location + Y_Value);
    LCD_WriteRAMWord(Color_Text);

    LCD_StarterSet(X_Location + X_Value, Y_Location - Y_Value);
    LCD_WriteRAMWord(Color_Text);

    LCD_StarterSet(X_Location - X_Value, Y_Location + Y_Value);
    LCD_WriteRAMWord(Color_Text);

    LCD_StarterSet(X_Location - X_Value, Y_Location - Y_Value);
    LCD_WriteRAMWord(Color_Text);

    LCD_StarterSet(X_Location + Y_Value, Y_Location + X_Value);
    LCD_WriteRAMWord(Color_Text);

    LCD_StarterSet(X_Location + Y_Value, Y_Location - X_Value);
    LCD_WriteRAMWord(Color_Text);

    LCD_StarterSet(X_Location - Y_Value, Y_Location + X_Value);
    LCD_WriteRAMWord(Color_Text);

    LCD_StarterSet(X_Location - Y_Value, Y_Location - X_Value);
    LCD_WriteRAMWord(Color_Text);

    if (DV &lt; 0)
    {
      DV += (X_Value &lt;&lt; 2) + 6;
    }
    else
    {
      DV += ((X_Value - Y_Value) &lt;&lt; 2) + 10;
                        if(Y_Value &gt; 0){ //增加Y_Value非0判断
                                Y_Value--;
                        }
    }
    X_Value++;
}
}</code></pre>

<p>6,修正代码后运行正常,如下图。</p>

<p></p>

<p><strong>五,建议逻辑正确性。</strong></p>

<p><strong>&nbsp;</strong>&nbsp; 在进行加减法操作时,一定要加上判断及执行结果界限值,否则容易人为错误引入BUG。</p>

littleshrimp 发表于 2020-8-15 17:05

<p>分析的很好</p>

<p>&nbsp;</p>
页: [1]
查看完整版本: 【ESK32-360测评】+LCD库函数BUG测评反馈