HG1286412-LYH液晶屏(ST7920控制器)描点函数

使用的是杭州一家公司的12864液晶屏,控制器型号为ST7920。

第一种方法,使用回读液晶屏数据的方式实现

/*
*@brief     lcd点操作
*
*@param     x   点横坐标
*@param     y   点纵坐标
*@param     c   黑(白)点选择
*
*@return    \
*
*@note      \
*/
void Lcd_Draw_Pixel(s16 x, s16 y, u32 c)
{
    unsigned char x_byte, x_bit;
    unsigned char y_byte, y_bit;
    unsigned char tmph, tmpl;
    

    x_byte = x >> 4;    /* 等效于x/16 */
    x_bit = x & 0x0F;   /* 等效于x%16 */

    y_byte = y >> 5;    /* 等效于y/32 */
    y_bit = y & 0x1F;   /* 等效于y%32 */

    Lcd_Write_Cmd(0x34);            /* 扩展指令集 */
    Lcd_Write_Cmd(0x80 + y_bit);
    Lcd_Write_Cmd(0x80 + 8 * y_byte + x_byte);

    Lcd_Read_Data();                /* 空读一次 */
    tmph = Lcd_Read_Data();         /* 读高位 */
    tmpl = Lcd_Read_Data();         /* 读低位 */

    Lcd_Write_Cmd(0x80 + y_bit);
    Lcd_Write_Cmd(0x80 + (y_byte << 3) + x_byte);   /* 等效于Lcd_Write_Cmd(0x80 + 8 * y_byte + x_byte); */

    if (x_bit < 8)
    {
        if(1 == c)
        {
            tmph |= (0x01 << (7 - x_bit));
            
        }
        else
        {
            tmph &= (~(0x01 << (7 - x_bit)));
        }
    }
    else
    {
        if(1 == c)
        {
            tmpl |= (0x01 << (15 - x_bit));
        }
        else
        {
            tmpl &= (~(0x01 << (15 - x_bit)));
        }
    }
    Lcd_Write_Data(tmph);
    Lcd_Write_Data(tmpl);
    
    Lcd_Write_Cmd(0x36);            /* 打开绘图显示 */
    Lcd_Write_Cmd(0x30);            /* 基本指令集 */
}


第二种方法,不回读液晶屏数据,为lcd开辟一个缓存ram

/*
*@brief     lcd点操作
*
*@param     x   点横坐标
*@param     y   点纵坐标
*@param     c   黑(白)点选择
*
*@return    \
*
*@note      \
*/
unsigned short int lcdram[512];
void Lcd_Draw_Pixel(s16 x, s16 y, u32 c)
{
    unsigned char x_byte, x_bit;
    unsigned char y_byte, y_bit;
    unsigned char tmph, tmpl;
    unsigned int idx = 0;
 
    x_byte = x >> 4;    /* 等效于x/16 */
    x_bit = x & 0x0F;   /* 等效于x%16 */
 
    y_byte = y >> 5;    /* 等效于y/32 */
    y_bit = y & 0x1F;   /* 等效于y%32 */
 
    idx = (y_byte << 3) + x_byte + (y_bit << 4);
    tmph = lcdram[idx] >> 8;
    tmpl = lcdram[idx] & 0xFF;


    Lcd_Write_Cmd(0x34);            /* 扩展指令集 */
    Lcd_Write_Cmd(0x80 + y_bit);    /* 垂直地址 */
    Lcd_Write_Cmd(0x80 + (y_byte << 3) + x_byte);   /* 水平地址,等效于Lcd_Write_Cmd(0x80 + 8 * y_byte + x_byte); */
 
    if (x_bit < 8)
    {
        if(1 == c)
        {
            tmph |= (0x01 << (7 - x_bit));
            
        }
        else
        {
            tmph &= (~(0x01 << (7 - x_bit)));
        }
    }
    else
    {
        if(1 == c)
        {
            tmpl |= (0x01 << (15 - x_bit));
        }
        else
        {
            tmpl &= (~(0x01 << (15 - x_bit)));
        }
    }
    Lcd_Write_Data(tmph);
    Lcd_Write_Data(tmpl);
 
    lcdram[idx] = (tmph << 8) | tmpl;
    
    Lcd_Write_Cmd(0x36);            /* 打开绘图显示 */
    Lcd_Write_Cmd(0x30);            /* 基本指令集 */


第一种方法因为有回读液晶屏数据的操作,会多耗一点时间。第二种方法不需要回读,相当于牺牲了一部分ram备份整个液晶屏的数据。


简单的测试了下,这个屏不太适合用GUI,刷屏有明显的卡顿感。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值