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

📄 lcd.c

📁 Keil平台
💻 C
📖 第 1 页 / 共 2 页
字号:
    {
        if (text[i] == '\0')
            break;
        if (style & FONT_SMALL)
        {
            Get_ASCA(text[i], &pDZ);
            ty = y;
            for (j = 0; j <  8; j++, ty++)
            {
                value = *pDZ++;
                for (xoffset = 0, maskcode = 0x20; xoffset < 6; xoffset++)
                {
                    if (value & maskcode)
                        LcdPutxy(x + xoffset + i*6, ty, 1);
                    else
                        LcdPutxy(x + xoffset + i*6, ty, 0);
                    maskcode >>= 1;
                }
            }
        }
        else
        {
            Get_ASC(text[i], &pDZ);
            ty = y;
            for (j = 0; j < 16; j++, ty++)
            {
                value = *pDZ++;
                for (xoffset = 0, maskcode = 0x80; xoffset < 8; xoffset++)
                {
                    if (value & maskcode)
                        LcdPutxy(x + xoffset + i*8, ty, 1);
                    else
                        LcdPutxy(x + xoffset + i*8, ty, 0);
                    maskcode >>= 1;
                }
            }
        }
    }
}

/****************************************************************************/
void LcdUpdate(void)
{
     Lcd.flag = 1;
     LcdDisplay();
}
/****************************************************************************/
void LcdDisplayxy(int x, int y, int len)
{
    uchar   *pDZ;
    int i, j, offset;
    offset = y*LCD_WSIZE*2 + 2*x;
    for (i = offset; i < offset+len*2; i += 2)
    {
        if (LcdTextBuf[i] == 0)
            continue;

        x = ((i/2)%LCD_WSIZE)*8;
        y = ((i/2)/LCD_WSIZE)*8;
        if (LcdTextBuf[i] > 0xA0)
        {
            if (LcdTextBuf[i+2] > 0xA0)
            {
                Get_DZ(LcdTextBuf[i], LcdTextBuf[i+2], &pDZ);
                for (j = 0; j < 16; j++)
                {
                    if (LcdTextBuf[i+1] & FONT_BRIGHT)
                    {
                        LcdPutxyb(x, y, ~*(pDZ + 2 * j));
                        LcdPutxyb(x + 8, y++, ~*(pDZ + 2 * j + 1));
                    }
                    else
                    {
                        LcdPutxyb(x, y, *(pDZ + 2 * j));
                        LcdPutxyb(x + 8, y++, *(pDZ + 2 * j + 1));
                    }
                }
                i += 2;
            }
        }
        else
        {
            if (LcdTextBuf[i+1] & FONT_SMALL)
            {
                Get_ASCA(LcdTextBuf[i], &pDZ);
                if (LcdTextBuf[i+1] & FONT_BRIGHT)
                    for (j = 0; j <  8; LcdPutxyb(x, y++, ~*(pDZ+j++)));
                else
                    for (j = 0; j <  8; LcdPutxyb(x, y++, *(pDZ+j++)));
            }
            else
            {
                Get_ASC(LcdTextBuf[i], &pDZ);
                if (LcdTextBuf[i+1] & FONT_BRIGHT)
                    for (j = 0; j < 16; LcdPutxyb(x, y++, ~*(pDZ+j++)));
                else
                    for (j = 0; j < 16; LcdPutxyb(x, y++, *(pDZ+j++)));
            }
        }
    }
}
/****************************************************************************/
void LcdDisplay(void)
{
    int i, j, x, y;
    uchar   *pDZ;
    if (Lcd.flag == 0)
    {
        return;
    }
    Lcd.flag = 0;
    for (i = 0; i < LCD_MEMSIZE; i += 2)
    {
        if (LcdTextBuf[i] == 0)
            continue;
        //
        if ((i%120) == 0)
        {
                //OSTimeDlyHMSM(0,0,0,5);//cxtwAtm(TICK_SIZE);//delay 改为系统延时
				//cxtwatm(5);
        }
        x = ((i/2)%LCD_WSIZE)*8;
        y = ((i/2)/LCD_WSIZE)*8;
        if (LcdTextBuf[i] > 0xA0)
        {
            if (LcdTextBuf[i+2] > 0xA0)
            {
                Get_DZ(LcdTextBuf[i], LcdTextBuf[i+2], &pDZ);
                for (j = 0; j < 16; j++)
                {
                    if (LcdTextBuf[i+1] & FONT_BRIGHT)
                    {
                        LcdPutxyb(x, y, ~*(pDZ + 2 * j));
                        LcdPutxyb(x + 8, y++, ~*(pDZ + 2 * j + 1));
                    }
                    else
                    {
                        LcdPutxyb(x, y, *(pDZ + 2 * j));
                        LcdPutxyb(x + 8, y++, *(pDZ + 2 * j + 1));
                    }
                }
                i += 2;
            }
        }
        else
        {
            if (LcdTextBuf[i+1] & FONT_SMALL)
            {
                Get_ASCA(LcdTextBuf[i], &pDZ);
                if (LcdTextBuf[i+1] & FONT_BRIGHT)
                    for (j = 0; j <  8; LcdPutxyb(x, y++, ~*(pDZ+j++)));
                else
                    for (j = 0; j <  8; LcdPutxyb(x, y++, *(pDZ+j++)));
            }
            else
            {
                Get_ASC(LcdTextBuf[i], &pDZ);
                if (LcdTextBuf[i+1] & FONT_BRIGHT)
                    for (j = 0; j < 16; LcdPutxyb(x, y++, ~*(pDZ+j++)));
                else
                    for (j = 0; j < 16; LcdPutxyb(x, y++, *(pDZ+j++)));
            }
        }
    }
    Lcd.flag = 0;
}
/****************************************************************************/
void DrawCursor(void)
{
    
}
/****************************************************************************/
int TextPick(uchar x, uchar y, int len, uchar *buf)
{
    int offset, i;
    offset = y*LCD_WSIZE*2 + 2*x;
    for (i = 0; i < len; i++)
    {
        buf[i] = LcdPeek(offset);
        if ((buf[i] == 0) || (buf[i] == ' '))
            break;
        offset += 2;
    }
    buf[i] = '\0';
    return i;
}
/****************************************************************************/

/****************************************************************************/
void LcdWinStyle(uchar value)
{
    Lcd.win_style = value;
}
/****************************************************************************/

void TextFocus(uchar x, uchar y, uchar index, uchar style)
{
    uint  offset;
    offset = LCD_WSIZE*2*y;
    if (!(style&FONT_SMALL)) /* font */
    {
        LcdPoke(offset + (x+index)*2+1, style);
        LcdPoke(offset + LCD_WSIZE*2 + (x+index)*2+1, style);
    }
    else
    {
        LcdPoke(offset + (x+index)*2+1, style);
    }
}
/****************************************************************************/
void TextClear(uchar x, uchar y, uchar w, uchar style)
{
    char text[30] = {"                              "};
    text[w] = '\0';
    TextOut(x, y, text, style);
}
/****************************************************************************/
/* include warp */
void TextOut(uchar x, uchar y, const char  *text, uchar style)
{
    uchar i, halfword;
    uchar  tail_x = 0;
    uint  offset;
    if (y > 7)
         return;

    if (Lcd.win_style & BS_NOFOCUS)
         style &= ~FONT_BRIGHT;
    offset = LCD_WSIZE*2*y;
    tail_x = x;
    for (i = 0; i < 124; i++)
    {
        if (text[i] == '\0')
            break;
        if (!(style&FONT_SMALL)) /* font */
        {
            if (text[i] == '\n')
            {
                offset += LCD_WSIZE*4;
                tail_x = 0;
                halfword = 0;
            }
            else
            {
                if (text[i] < 0xA1)
                    halfword = 0;
                else
                {
                    halfword++;
                    halfword %= 2;
                }
                if ((tail_x+1 > LCD_WSIZE-1) && halfword)
                {
                    i--;
                    halfword = 0;
                    /* debug speedup process
                    LcdPoke(offset + tail_x*2, 0);
                    LcdPoke(offset + tail_x*2+1, 0);
                    LcdPoke(offset + LCD_WSIZE*2 + tail_x*2, 0);
                    LcdPoke(offset + LCD_WSIZE*2 + tail_x*2+1, 0);
                    */
                }
                else
                {
                    LcdPoke(offset + tail_x*2, text[i]);
                    LcdPoke(offset + tail_x*2+1, style);
                    LcdPoke(offset + LCD_WSIZE*2 + tail_x*2, 0);
                    LcdPoke(offset + LCD_WSIZE*2 + tail_x*2+1, style);
                }
                tail_x++;
                if (tail_x > LCD_WSIZE-1)    /* 16*16 or 8*16 font warp*/
                {
                    offset += LCD_WSIZE*4;
                    tail_x = 0;
                }
            }
        }
        else
        {
            if (text[i] == '\n')
            {
                offset += LCD_WSIZE*2;
                tail_x = 0;
            }
            else
            {
                LcdPoke(offset + tail_x*2, text[i]);
                LcdPoke(offset + tail_x*2+1, style);
                tail_x++;
                if (tail_x > LCD_WSIZE-1)    /* 8*8 font warp*/
                {
                    offset += LCD_WSIZE*2;
                    tail_x = 0;
                }
            }
        }
    }
}
/****************************************************************************/
void Get_DZ(uchar qu, uchar wei, uchar  **pDZ)
{
    uint code;
    int low = 0, mid = 0, top = MAX_HZ;

    code = bb2i(qu, wei);
    while (low <= top)
    {
        mid = (low + top) / 2;
        if (code == HZMB[mid])
        {
            *pDZ = &HZ[mid * 32];
            return;
        }
        if (code < HZMB[mid])
            top = mid - 1;
        else
            low = mid + 1;
    }
    *pDZ = &HZ[0];
}
/****************************************************************************/
void Get_ASC(uchar code, uchar  **pDZ)
{
    *pDZ = &ASC[code * 16-1];
}
/****************************************************************************/
void Get_ASCA(uchar code, uchar  **pDZ)
{
    *pDZ = &ASCA[code * 8];
}
/****************************************************************************/
void LcdPutxy(int x, int y, uchar value)
{
    LCD_Draw_Dot( x, y, (unsigned char)value);
}
/****************************************************************************/
void LcdPutxyb(int x, int y, uchar value)
{
    LCD_Draw_Byte( x, y, (unsigned char)value, 0);
}
/****************************************************************************/
void  LcdPoke(uint offset, uchar value)
{
    if (offset < LCD_MEMSIZE)
    {
        LcdTextBuf[offset] = value;
    }
}
uchar LcdPeek(uint offset)
{
    return LcdTextBuf[offset];
}

/****************************************************************************/

⌨️ 快捷键说明

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