arm cortex m3 display

2019-09-20 02:59发布

hi i am working on arm controller lm3s8962 i m not able to understand the code below as per my understanding it is checking if the character is from the array or not, which he created using the ascii characters{i.e in the while loop : while(*pcStr != 0) }, i am not able to get what he is doing in the code after the line "Build and display the character buffer" plz can anyone explain this

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;
                }
            }
        }
    }

1条回答
Viruses.
2楼-- · 2019-09-20 03:39

He is doing some bit manipulations to build up bytes.

x |= y is the same as x = x | y, which keeps all the 1s in x and also changes some of the 0s to 1 if y has a 1 in the same position.

1 << i is a byte with a single 1 bit in the ith position from the right.

x = y & 0xf0 copies only the left 4 bits of y into x.

So he is looking up values in an array, checking particular bits of those values, then filling up another array with number created from those bits. You will have to work out the particulars for yourself.

查看更多
登录 后发表回答