首页 > 其他分享 >LCD12864单色屏任意位置显示文字图片功能,不在受限于8bit的分行

LCD12864单色屏任意位置显示文字图片功能,不在受限于8bit的分行

时间:2023-06-30 16:23:46浏览次数:41  
标签:Draw LCD12864 SCREEN 受限于 uint8 LCD 8bit byte Pixel

/*
取模软件image2Lcd v2.9
液晶取模方式:
扫描方式:数据水平,字节垂直

输出灰度:单色
最大宽度和高度:128*64
字节内像素数据反序
*/
#define LCD_REVERSE_FLAG 0
#define LCD_DISPLAY_NORMAL 0
#define LCD_DISPLAY_REVERSE 1
#define LCD_BUFF_BYTE_MAX 1024

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

uint8_t ucLCd_Dara_Buffer[LCD_BUFF_BYTE_MAX];
uint8_t LCD_DisplayBuff[SCREEN_WIDTH * SCREEN_HEIGHT / 8]={0};
static uint8_t ucLcdDisplayShowFlag = 0;

void LcdShowPicture(uint8_t x,
                    uint8_t y,
                    uint8_t w,
                    uint8_t h,
                    uint32_t ulPictureAddress,
                    uint16_t uiPictureSize,
                    uint8_t ucLCD_Write_Display_Reverse)
{
    if(uiPictureSize>sizeof(ucLCd_Dara_Buffer))return;
    W25qxx_ReadBytes(ucLCd_Dara_Buffer,ulPictureAddress,uiPictureSize);

    LCD_WriteDataToBuff(x,y,w,h,ucLCd_Dara_Buffer,uiPictureSize,ucLCD_Write_Display_Reverse);
    

    
    


}
//清显示缓存区数据
void LCD_BuffClear(void)
{
    memset(LCD_DisplayBuff,0,(SCREEN_WIDTH*SCREEN_HEIGHT/8));
}
//打点函数
void LCD_Draw_Pixel(uint8_t x,uint8_t y,uint8_t color)
{
    if (x >= SCREEN_WIDTH || y >= SCREEN_HEIGHT ) return;

    uint16_t array_pos = x + ((y / 8) * SCREEN_WIDTH );


    if ( color ) 
    {
        LCD_DisplayBuff[array_pos] |= 0x01 << (y % 8);
    } 
    else 
    {
        LCD_DisplayBuff[array_pos] &= 0xFF ^ 0x01 << (y % 8);
    }
}

//数据写入缓存区
void LCD_WriteDataToBuff(uint8_t x,uint8_t y,uint8_t width,uint8_t height,uint8_t *databuff,uint16_t datalen,uint8_t ucLCD_Write_Display_Reverse)
{
    uint8_t byte = 0;
    uint16_t i,j,k;
    uint8_t height_int,height_mod;
    if((x + width) > 128 || (y + height) > 64)return;
    height_int = height/8;
    height_mod = height%8;
    for(j = 0;j < (height_int + 1);j++)
    {
        for(i = 0;i < width;i++)
        {    
            if((i + j * width) >= datalen)break;
            byte = *(databuff + i + j * width );
            if(j != height_int)
            {
                for(k = 0;k < 8;k++)
                {
                    if(byte & 0x01)
                    {
                        if(ucLCD_Write_Display_Reverse == 0)LCD_Draw_Pixel(x + i,y + j * 8 + k,1);
                        else LCD_Draw_Pixel(x + i,y + j * 8 + k,0);
                    }
                    else
                    {
                        if(ucLCD_Write_Display_Reverse == 0)LCD_Draw_Pixel(x + i,y + j* 8 + k,0);
                        else LCD_Draw_Pixel(x + i,y + j * 8 + k,1);
                    }
                    byte = byte >> 1;
                }
            }
            else
            {
                for(k = 0;k < height_mod;k++)
                {
                    if(byte & 0x01)
                    {
                        if(ucLCD_Write_Display_Reverse == 0)LCD_Draw_Pixel(x + i,y + j * 8 + k,1);
                        else LCD_Draw_Pixel(x + i,y + j * 8 + k,0);
                    }
                    else
                    {
                        if(ucLCD_Write_Display_Reverse == 0)LCD_Draw_Pixel(x + i,y + j * 8 + k,0);
                        else LCD_Draw_Pixel(x + i,y + j * 8 + k,1);
                    }
                    byte = byte >> 1;
                }
            }
        }
    }
    ucLcdDisplayShowFlag = 1;
}


//刷新液晶显示
void LCD_DisplayBuffShow(void)
{
    uint8_t i;
    if(ucLcdDisplayShowFlag == 1)
    {
        //依次清除LCD的8个显示行
        for(i = 0; i < 8; i++)
        {
            LCD_Data_Write(i, 0, 128, (LCD_DisplayBuff + 128 * i), 128, LCD_DISPLAY_NORMAL);
        }
        ucLcdDisplayShowFlag = 0;
    }

    
    
    
    
    
    
    
}

 

标签:Draw,LCD12864,SCREEN,受限于,uint8,LCD,8bit,byte,Pixel
From: https://www.cnblogs.com/jeremy2016/p/17517109.html

相关文章