⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcd.c

📁 Cirrus Logic EP7312处理器部分控制程序。
💻 C
📖 第 1 页 / 共 2 页
字号:

        lXpos++;
    }
}

void
LCDColorCircle(long lX, long lY, long lRadius, CPixel sColor)
{
    long lXpos, lYpos, lD;

    lXpos = 0;
    lYpos = lRadius;

    lD = 3 - (2 * lYpos);

    while(lYpos >= lXpos)
    {
        LCDColorSetPixel(lX + lXpos, lY + lYpos, sColor);
        LCDColorSetPixel(lX + lYpos, lY + lXpos, sColor);
        LCDColorSetPixel(lX + lXpos, lY - lYpos, sColor);
        LCDColorSetPixel(lX - lYpos, lY + lXpos, sColor);
        LCDColorSetPixel(lX - lXpos, lY - lYpos, sColor);
        LCDColorSetPixel(lX - lYpos, lY - lXpos, sColor);
        LCDColorSetPixel(lX - lXpos, lY + lYpos, sColor);
        LCDColorSetPixel(lX + lYpos, lY - lXpos, sColor);

        if(lD < 0)
        {
            lD += (4 * lXpos) + 6;
        }
        else
        {
            lD += 10 + (4 * (lXpos - lYpos));
            lYpos--;
        }

        lXpos++;
    }
}

//****************************************************************************
//
// LCDFillCircle and LCDColorFillCircle draw a filled circle at the specified
// location.  This is an implementation of Bresenham's circle drawing
// algorithm; for details, see any reputable graphics book.
//
//****************************************************************************
void
LCDFillCircle(long lX, long lY, long lRadius, char cColor)
{
    long lXpos, lYpos, lD;

    lXpos = 0;
    lYpos = lRadius;

    lD = 3 - (2 * lYpos);

    while(lYpos >= lXpos)
    {
        LCDLine(lX - lXpos, lY + lYpos, lX + lXpos, lY + lYpos, cColor);
        LCDLine(lX - lYpos, lY + lXpos, lX + lYpos, lY + lXpos, cColor);
        LCDLine(lX - lXpos, lY - lYpos, lX + lXpos, lY - lYpos, cColor);
        LCDLine(lX - lYpos, lY - lXpos, lX + lYpos, lY - lXpos, cColor);

        if(lD < 0)
        {
            lD += (4 * lXpos) + 6;
        }
        else
        {
            lD += 10 + (4 * (lXpos - lYpos));
            lYpos--;
        }

        lXpos++;
    }
}

void
LCDColorFillCircle(long lX, long lY, long lRadius, CPixel sColor)
{
    long lXpos, lYpos, lD;

    lXpos = 0;
    lYpos = lRadius;

    lD = 3 - (2 * lYpos);

    while(lYpos >= lXpos)
    {
        LCDColorLine(lX - lXpos, lY + lYpos, lX + lXpos, lY + lYpos, sColor);
        LCDColorLine(lX - lYpos, lY + lXpos, lX + lYpos, lY + lXpos, sColor);
        LCDColorLine(lX - lXpos, lY - lYpos, lX + lXpos, lY - lYpos, sColor);
        LCDColorLine(lX - lYpos, lY - lXpos, lX + lYpos, lY - lXpos, sColor);

        if(lD < 0)
        {
            lD += (4 * lXpos) + 6;
        }
        else
        {
            lD += 10 + (4 * (lXpos - lYpos));
            lYpos--;
        }

        lXpos++;
    }
}

//****************************************************************************
//
// LCDPrintChar and LCDColorPrintChar print a character at the specified
// location.
//
//****************************************************************************
void
LCDPrintChar(char cChar, long lX, long lY, char cColor)
{
    long lIdx1, lIdx2;
    char cFontLine;

    //
    // The character font is 8x8, so loop through each row of the font.
    //
    for(lIdx1 = 0; lIdx1 < 8; lIdx1++)
    {
        //
        // Read the byte which describes this row of the font.
        //
        cFontLine = FontData[(cChar << 3) + lIdx1];

        //
        // Loop through each column of this row.
        //
        for(lIdx2 = 0; lIdx2 < 8; lIdx2++)
        {
            //
            // Set the pixel for this row,column based on the value of this
            // bit of the font.
            //
            LCDSetPixel(lX + lIdx2, lY + lIdx1,
                        cFontLine & 1 << (7 - lIdx2) ? cColor : 0);
        }
    }
}

void
LCDColorPrintChar(char cChar, long lX, long lY, CPixel sColor)
{
    long lIdx1, lIdx2;
    char cFontLine;

    //
    // The character font is 8x8, so loop through each row of the font.
    //
    for(lIdx1 = 0; lIdx1 < 8; lIdx1++)
    {
        //
        // Read the byte which describes this row of the font.
        //
        cFontLine = FontData[(cChar << 3) + lIdx1];

        //
        // Loop through each column of this row.
        //
        for(lIdx2 = 0; lIdx2 < 8; lIdx2++)
        {
            //
            // Set the pixel for this row,column based on the value of this
            // bit of the font.  If it's a 0, leave the pixel as it is,
            // if it's a 1, set the pixel to sColor.
            //
            if(cFontLine & 1 << (7 -lIdx2))
            {
               LCDColorSetPixel(lX + lIdx2, lY + lIdx1, sColor);
            }
        }
    }
}

//****************************************************************************
//
// LCDPrintString and LCDColorPrintString print a string at the specified
// location.
//
//****************************************************************************
void
LCDPrintString(char *pcBuffer, long lX, long lY, char cColor)
{
    //
    // Loop through each character in the string.
    //
    while(*pcBuffer)
    {
        //
        // Print this character.
        //
        LCDPrintChar(*pcBuffer++, lX, lY, cColor);

        //
        // Advance horizontally past this character.
        //
        lX += 8;
    }
}

void
LCDColorPrintString(char *pcBuffer, long lX, long lY, CPixel sColor)
{
    //
    // Loop through each character in the string.
    //
    while(*pcBuffer)
    {
        //
        // Print this character.
        //
        LCDColorPrintChar(*pcBuffer++, lX, lY, sColor);

        //
        // Advance horizontally past this character.
        //
        lX += 8;
    }
}

//****************************************************************************
//
// LCDPrintCharX and LCDColorPrintCharX2 print a double-sized character at
// the specified location.
//
//****************************************************************************
void
LCDPrintCharX2(char cChar, long lX, long lY, char cColor)
{
    long lIdx1, lIdx2;
    char cFontLine, cPixelColor;

    //
    // The character font is 8x8, so loop through each row of the font.
    //
    for(lIdx1 = 0; lIdx1 < 8; lIdx1++)
    {
        //
        // Read the byte which describes this row of the font.
        //
        cFontLine = FontData[(cChar << 3) + lIdx1];

        //
        // Loop through each column of this row.
        //
        for(lIdx2 = 0; lIdx2 < 8; lIdx2++)
        {
            //
            // Determine the color of this pixel block.
            //
            cPixelColor = cFontLine & (1 << (7 - lIdx2)) ? cColor : 0;

            //
            // Set the pixel block for this row,column of the font.
            //
            LCDSetPixel(lX + (lIdx2 << 1), lY + (lIdx1 << 1), cPixelColor);
            LCDSetPixel(lX + (lIdx2 << 1) + 1, lY + (lIdx1 << 1), cPixelColor);
            LCDSetPixel(lX + (lIdx2 << 1), lY + (lIdx1 << 1) + 1, cPixelColor);
            LCDSetPixel(lX + (lIdx2 << 1) + 1, lY + (lIdx1 << 1) + 1,
                        cPixelColor);
        }
    }
}

void
LCDColorPrintCharX2(char cChar, long lX, long lY, CPixel sColor)
{
    long lIdx1, lIdx2;
    char cFontLine;

    //
    // The character font is 8x8, so loop through each row of the font.
    //
    for(lIdx1 = 0; lIdx1 < 8; lIdx1++)
    {
        //
        // Read the byte which describes this row of the font.
        //
        cFontLine = FontData[(cChar << 3) + lIdx1];

        //
        // Loop through each column of this row.
        //
        for(lIdx2 = 0; lIdx2 < 8; lIdx2++)
        { 
            //
            // Set the pixel for this row,column based on the value of this
            // bit of the font.  If it's a 0, leave the pixel as it is,
            // if it's a 1, set the pixel to sColor.
            //
            if(cFontLine & 1 << (7 -lIdx2))
            {
               LCDColorSetPixel(lX + (lIdx2 << 1), lY + (lIdx1 << 1), sColor);
               LCDColorSetPixel(lX + (lIdx2 << 1) + 1, lY + (lIdx1 << 1), sColor);
               LCDColorSetPixel(lX + (lIdx2 << 1), lY + (lIdx1 << 1) + 1, sColor);
               LCDColorSetPixel(lX + (lIdx2 << 1) + 1, lY + (lIdx1 << 1) + 1,
                        sColor);
            }
        }
    }
}

//****************************************************************************
//
// LCDPrintStringX2 and LCDColorPrintStringX2 print a string of double-sized
// characters at the specified location.
//
//****************************************************************************
void
LCDPrintStringX2(char *pcBuffer, long lX, long lY, char cColor)
{
    //
    // Loop through each character in the string.
    //
    while(*pcBuffer)
    {
        //
        // Print this character.
        //
        LCDPrintCharX2(*pcBuffer++, lX, lY, cColor);

        //
        // Advance horizontally past this character.
        //
        lX += 16;
    }
}

void
LCDColorPrintStringX2(char *pcBuffer, long lX, long lY, CPixel sColor)
{
    //
    // Loop through each character in the string.
    //
    while(*pcBuffer)
    {
        //
        // Print this character.
        //
        LCDColorPrintCharX2(*pcBuffer++, lX, lY, sColor);

        //
        // Advance horizontally past this character.
        //
        lX += 16;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -