本帖最后由 dely2009 于 2015-6-29 19:12 编辑
刚入手1284 写了个时钟在字显示用了16X32 字模大字显示时间 , 用于清屏时才发现, 绘图模式下汉字不会被清屏, 图形错位打时会出现在汉字的底层, 故此写了个指定汉字可以反白的程序代码(其实就是在打字汉字位置画个白条) 共享给新手,老鸟飞过吧 勿喷
如图所示的代码如下
//*****************************************************************************
// 带字库,汉字区反白打底(画白条)
// 参数:x(0-8) y(0-3) width(0-16) 12864屏是4行每行8个汉字
//
//*****************************************************************************
void Set_Reverse(unsigned char x,unsigned char y,unsigned char width)
{
unsigned char i,j;
Clear_GDRAM();
LCD_Write_Cmd(0x34);
LCD_Write_Cmd(0x36);
switch(y)
{
case 0:y=0X80;break;
case 1:y=0X90;break;
case 2:y=0X88;break;
case 3:y=0X98;break;
}
for(i=0;i<16;i++)
{
if (y==0X80||y==0X88)
{ LCD_Write_Cmd(0X80+i);}
else
{ LCD_Write_Cmd(0x90+i);}
LCD_Write_Cmd(y+x);
for(j=0;j<width;j++)
{
LCD_Write_Data(0XFF);
}
}
LCD_Write_Cmd(0x36);
}
如果想满屏打白底,实现任意 字符反白可参考下面的代码(要区分 奇偶行 和奇偶位的)
//******************************************************************
// 任意位置打白底 ( 反白)
// 参数:x(0 - 15) y(0 - 3),反白长度(1 - 16)
// ******************************************************************/
void Set_Reverse(unsigned char x,unsigned char y,unsigned char width)
{
unsigned char i,j,flag= 0;
unsigned char real_x,real_width;
Clear_GDRAM();
if(y>1)
{
flag=0x08;
y=y-2;
}
LCD_Write_Cmd(0x34);
if(x % 2 == 0 && width % 2 == 0) //开始为偶数,长度偶数
{
real_x = x / 2;
real_width = width / 2;
for(i=0;i<16;i++)
{
LCD_Write_Cmd(0x80+(y<<4)+i);
LCD_Write_Cmd(0x80+flag+real_x);
for(j=0;j<real_width;j++)
{
LCD_Write_Data(0xff);
LCD_Write_Data(0xff); // 全偶数 写2个字符位的白底
}
}
}
if(x % 2 == 0 && width %2 != 0) //开始偶数,长度奇数
{
real_x = x / 2;
real_width = width / 2;
for(i=0;i<16;i++)
{
LCD_Write_Cmd(0x80+(y<<4)+i);
LCD_Write_Cmd(0x80+flag+real_x);
for(j=0;j<real_width;j++)
{
LCD_Write_Data(0xff);
LCD_Write_Data(0xff);
}
LCD_Write_Data(0xff);
LCD_Write_Data(0x00); //这个要在最后面打一竖排 黑底
}
}
if(x % 2 != 0 && width % 2 == 0) //开始奇数,长度偶数
{
real_x = x / 2;
real_width = width / 2 - 1;
for(i=0;i<16;i++)
{
LCD_Write_Cmd(0x80+(y<<4)+i);
LCD_Write_Cmd(0x80+flag+real_x);
LCD_Write_Data(0x00);
LCD_Write_Data(0xff);
for(j=0;j<real_width;j++)
{
LCD_Write_Data(0xff);
LCD_Write_Data(0xff);
}
LCD_Write_Data(0xff);
LCD_Write_Data(0x00); // 前后都要 打一竖排 黑底
}
}
if(x % 2 != 0 && width % 2 != 0) //开始奇数,长度奇数
{
real_x = x / 2;
real_width = width / 2;
for(i=0;i<16;i++)
{
LCD_Write_Cmd(0x80+(y<<4)+i);
LCD_Write_Cmd(0x80+flag+real_x);
LCD_Write_Data(0x00); // 只需要在前面多打一竖排黑底
LCD_Write_Data(0xff);
for(j=0;j<real_width;j++)
{
LCD_Write_Data(0xff);
LCD_Write_Data(0xff);
}
}
}
LCD_Write_Cmd(0x36);
LCD_Write_Cmd(0x30);
}
对于无字库的12864直接使用输出字符时取反就可以, 写在这里与新手共享,老鸟飞过, 请勿喷
|