使用的是杭州一家公司的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); /* 基本指令集 */
简单的测试了下,这个屏不太适合用GUI,刷屏有明显的卡顿感。