|
本帖最后由 dely2009 于 2015-6-29 19:12 編輯
剛?cè)胧?284 寫了個(gè)時(shí)鐘在字顯示用了16X32 字模大字顯示時(shí)間 , 用于清屏?xí)r才發(fā)現(xiàn), 繪圖模式下漢字不會(huì)被清屏, 圖形錯(cuò)位打時(shí)會(huì)出現(xiàn)在漢字的底層, 故此寫了個(gè)指定漢字可以反白的程序代碼(其實(shí)就是在打字漢字位置畫個(gè)白條) 共享給新手,老鳥飛過吧 勿噴
如圖所示的代碼如下
//*****************************************************************************
// 帶字庫(kù),漢字區(qū)反白打底(畫白條)
// 參數(shù):x(0-8) y(0-3) width(0-16) 12864屏是4行每行8個(gè)漢字
//
//*****************************************************************************
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);
}
如果想滿屏打白底,實(shí)現(xiàn)任意 字符反白可參考下面的代碼(要區(qū)分 奇偶行 和奇偶位的)
//******************************************************************
// 任意位置打白底 ( 反白)
// 參數(shù):x(0 - 15) y(0 - 3),反白長(zhǎng)度(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) //開始為偶數(shù),長(zhǎng)度偶數(shù)
{
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); // 全偶數(shù) 寫2個(gè)字符位的白底
}
}
}
if(x % 2 == 0 && width %2 != 0) //開始偶數(shù),長(zhǎng)度奇數(shù)
{
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); //這個(gè)要在最后面打一豎排 黑底
}
}
if(x % 2 != 0 && width % 2 == 0) //開始奇數(shù),長(zhǎng)度偶數(shù)
{
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) //開始奇數(shù),長(zhǎng)度奇數(shù)
{
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);
}
對(duì)于無字庫(kù)的12864直接使用輸出字符時(shí)取反就可以, 寫在這里與新手共享,老鳥飛過, 請(qǐng)勿噴
|
評(píng)分
-
查看全部評(píng)分
|