本帖最后由 dely2009 于 2015-6-29 19:12 編輯
剛入手1284 寫了個時鐘在字顯示用了16X32 字模大字顯示時間 , 用于清屏時才發現, 繪圖模式下漢字不會被清屏, 圖形錯位打時會出現在漢字的底層, 故此寫了個指定漢字可以反白的程序代碼(其實就是在打字漢字位置畫個白條) 共享給新手,老鳥飛過吧 勿噴
20150629_183529.jpg (2.3 MB, 下載次數: 148)
下載附件
2015-6-29 18:57 上傳
如圖所示的代碼如下
//*****************************************************************************
// 帶字庫,漢字區反白打底(畫白條)
// 參數: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);
}
如果想滿屏打白底,實現任意 字符反白可參考下面的代碼(要區分 奇偶行 和奇偶位的)
20150629_183736.jpg (2.16 MB, 下載次數: 142)
下載附件
2015-6-29 19:01 上傳
//******************************************************************
// 任意位置打白底 ( 反白)
// 參數: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直接使用輸出字符時取反就可以, 寫在這里與新手共享,老鳥飛過, 請勿噴
|