【嵌入式】PCtoLCD驱动LCD取模方式及代码

2022-03-31  本文已影响0人  Blue_Well

本文适用于在LCD显示PCtoLCD生成的取模数据(单色图)。

阳码:没有像素点的地方为0,反之为1
高位在前&逐行式:可以用SPI一直往屏幕上刷数据

显示代码:

void lcd_show_bmp(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t * p_bmp, uint16_t front_color, uint16_t back_color)
{
    uint8_t key[8] = {0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
    
    uint16_t bmp_size = 0, width_tmp = 0;
    
    if(width % 8 == 0)
    {
        bmp_size = height*width/8;
        width_tmp = width;
    }
    else
    {
        bmp_size = height*(width/8+1);
        width_tmp = (width/8+1)*8;
    }
    
    lcd_set_pos(x, y, x + width_tmp, y + height);
    
    lcd_dc_data();
    
    lcd_cs_enable();
    
    for(uint16_t i = 0; i < bmp_size; i++)
    {
        for(uint16_t j = 0; j < 8; j++)
        {
            if((p_bmp[i] & key[j]) != 0)
            {
                spi_write_byte(front_color >> 8);
                spi_write_byte(front_color); 
            }
            else
            {
                spi_write_byte(back_color >> 8);
                spi_write_byte(back_color); 
            }
        }
    }

    lcd_cs_disable(); 
}
上一篇下一篇

猜你喜欢

热点阅读