-1

嗨,我正在研究 arm 控制器 lm3s8962,我无法根据我的理解理解下面的代码,它正在检查字符是否来自数组,这是他使用 ascii 字符创建的{即在 while 循环中:while(* pcStr != 0) },我无法在“构建并显示字符缓冲区”行之后的代码中得到他在做什么,请谁能解释一下

void
    RIT128x96x4StringDraw(const char *pcStr, unsigned long ulX,
                          unsigned long ulY, unsigned char ucLevel)
    {
        unsigned long ulIdx1, ulIdx2;
        unsigned char ucTemp;

        //
        // Check the arguments.
        //
        ASSERT(ulX < 128);
        ASSERT((ulX & 1) == 0);
        ASSERT(ulY < 96);
        ASSERT(ucLevel < 16);

        //
        // Setup a window starting at the specified column and row, ending
        // at the right edge of the display and 8 rows down (single character row).
        //
        g_pucBuffer[0] = 0x15;
        g_pucBuffer[1] = ulX / 2;
        g_pucBuffer[2] = 63;
        RITWriteCommand(g_pucBuffer, 3);
        g_pucBuffer[0] = 0x75;
        g_pucBuffer[1] = ulY;
        g_pucBuffer[2] = ulY + 7;
        RITWriteCommand(g_pucBuffer, 3);
        RITWriteCommand(g_pucRIT128x96x4VerticalInc,
                        sizeof(g_pucRIT128x96x4VerticalInc));

        //
        // Loop while there are more characters in the string.
        //
        while(*pcStr != 0)
        {
            //
            // Get a working copy of the current character and convert to an
            // index into the character bit-map array.
            //
            ucTemp = *pcStr++ & 0x7f;
            if(ucTemp < ' ')
            {
                ucTemp = 0;
            }
            else
            {
                ucTemp -= ' ';
            }

            //
            // Build and display the character buffer.
            //
            for(ulIdx1 = 0; ulIdx1 < 6; ulIdx1 += 2)
            {
                //
                // Convert two columns of 1-bit font data into a single data
                // byte column of 4-bit font data.
                //
                for(ulIdx2 = 0; ulIdx2 < 8; ulIdx2++)
                {
                    g_pucBuffer[ulIdx2] = 0;
                    if(g_pucFont[ucTemp][ulIdx1] & (1 << ulIdx2))
                    {
                        g_pucBuffer[ulIdx2] = (ucLevel << 4) & 0xf0;
                    }
                    if((ulIdx1 < 4) &&
                       (g_pucFont[ucTemp][ulIdx1 + 1] & (1 << ulIdx2)))
                    {
                        g_pucBuffer[ulIdx2] |= (ucLevel << 0) & 0x0f;
                    }
                }

                //
                // Send this byte column to the display.
                //
                RITWriteData(g_pucBuffer, 8);
                ulX += 2;

                //
                // Return if the right side of the display has been reached.
                //
                if(ulX == 128)
                {
                    return;
                }
            }
        }
    }
4

1 回答 1

1

他正在做一些位操作来建立字节。

x |= y与 相同x = x | y,它保留 x 中的所有 1,并且如果 y 在同一位置有 1,也将一些 0 更改为 1。

1 << i是一个在右边第 i 个位置有一个 1 位的字节。

x = y & 0xf0仅将 y 的左 4 位复制到 x 中。

所以他在一个数组中查找值,检查这些值的特定位,然后用这些位创建的数字填充另一个数组。您必须自己制定详细信息。

于 2013-03-13T17:27:11.493 回答