新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 128*64液晶采用“單片機(jī)內(nèi)部顯示緩沖“的程序

128*64液晶采用“單片機(jī)內(nèi)部顯示緩沖“的程序

作者: 時(shí)間:2016-11-17 來(lái)源:網(wǎng)絡(luò) 收藏
/*

*
*文件名稱:
*摘要:讀寫lcd顯示緩沖區(qū)
*
*當(dāng)前版本:v1.0
*作者:laoliu2008
*完成日期:2008年4月12日

*/

#i nclude
#i nclude<全局變量.h>


unsignedcharxx,yy;//全局插入點(diǎn)坐標(biāo)

externconstunsignedcharcharacter_tab[][17];//顯示數(shù)據(jù)庫(kù)
externconstunsignedcharChinese_characters_tab[][34];//顯示數(shù)據(jù)庫(kù)

unsignedcharlcd_bit_buffer[8][128];//顯示緩沖區(qū)

//************************************
//lcd初始化
//7___________________________
//|||
//|||
///||||
//||||
//||||
//||||
//Y|_____________|_____________|
//|
//0----------->數(shù)學(xué)坐標(biāo):x127
//
//文字坐標(biāo):0_____
//||
//||
//|-----|
//||
//|_____|
//可以在任意點(diǎn)顯示漢字字符
//首先調(diào)用w_xx_yy();寫入要顯示的字符在屏幕位置坐標(biāo)(文字坐標(biāo)為左上角)調(diào)用dis_buffer();顯示一個(gè)漢字或英文
//dis_lcd_buffer()顯示字符串Y地址自動(dòng)右移8或16顯示字符串可以自動(dòng)保持一行
//坐標(biāo)自動(dòng)循環(huán)例如你在右下角x=119y=7的地方顯示一個(gè)漢字這個(gè)漢字的3/4將會(huì)出現(xiàn)在屏幕的左上角
//字庫(kù)16*16英文16*8文字的坐標(biāo)參考點(diǎn)選則左上角即所說(shuō)的在x=119y=7所說(shuō)的是字符的左上角坐標(biāo)
//************************************
//***********************************
//初始化緩沖區(qū)
//***********************************
voidlcd_buffer_ini()
{
unsignedcharx,y;
unsignedchartemp;


for(y=8;y>0;y--)//清零緩沖區(qū)
for(x=128;x>0;x--)
lcd_bit_buffer[y-1][x-1]=0;

xx=0;
yy=0;

}
//*******************************
//顯示輸出
//*******************************
voiddis_out_lcd()
{

unsignedcharx0,y0;
unsignedchartemp;
for(y0=8;y0>0;y0--)
{
w_lcd_address(y0-1,0);
for(x0=128;x0>0;x0--)
{

w_lcd_data(lcd_bit_buffer[y0-1][x0-1]);//調(diào)用顯示函數(shù)
}
}

}

//********************************
//到xxyy寫一點(diǎn)
//********************************
unsignedcharwb_lcd_bit_buffer()
{
unsignedchartemp;
unsignedchary1,y2;
//xxyy
{
y1=yy%8;//0-7bie
y2=yy>>3;//0-7行
temp=lcd_bit_buffer[y2][xx];
temp|=(1<lcd_bit_buffer[y2][xx]=temp;
}
}
//********************************
//到xxyy擦一點(diǎn)
//********************************
unsignedcharn_wb_lcd_bit_buffer()
{
unsignedchartemp;
unsignedchary1,y2;
//xxyy
if((yy>63))
return0;
y1=yy%8;//0-7bie
y2=yy>>3;//0-7行
temp=lcd_bit_buffer[y2][xx];
temp&=~(1<lcd_bit_buffer[y2][xx]=temp;

}
//********************************
//寫顯示地址xxyy
//********************************
voidw_xx_yy(unsignedcharx,unsignedchary)
{
xx=x%128;
yy=y%64;
}

//***********************************
//取反一個(gè)點(diǎn)
//***********************************
voidcpl_dian()
{

unsignedchartemp;
unsignedchary1,y2;
//xxyy

y1=yy%8;//0-7bie
y2=yy>>3;//0-7行
temp=lcd_bit_buffer[y2][xx];
temp^=(1<lcd_bit_buffer[y2][xx]=temp;

}
//*******************************
//取反一個(gè)英文字符
//*******************************
voidcpl_asc()
{
unsignedchari,j;
unsignedcharx_x,y_y;
unsignedchartemp_data,y;

unsignedchartemp;
unsignedchary1,y2;
x_x=xx;
y=y_y=yy;//保存y軸

i=8;//顯示字模8*16
while(i--)
{

yy=y;
//------------寫一個(gè)字節(jié)---------------------------
for(j=8;j>0;j--)
{
y1=yy%8;//0-7bie
y2=yy>>3;//0-7行

temp=lcd_bit_buffer[y2][xx];//寫一個(gè)點(diǎn)不調(diào)用函數(shù)減少調(diào)用浪費(fèi)的系統(tǒng)時(shí)間
temp^=(1<lcd_bit_buffer[y2][xx]=temp;

//yy=(yy+64-1)%64;//修正y地址
yy=(yy+63)%64;//修正y地址
}
//-------------------------------------------------
xx=(xx+1)%128;

}

y=yy;//顯示下半個(gè)字

xx=x_x;//寫x_x到xx
i=8;//顯示字模8*16
while(i--)
{

yy=y;
//------------寫一個(gè)字節(jié)---------------------------
for(j=8;j>0;j--)
{
y1=yy%8;//0-7bie
y2=yy>>3;//0-7行

temp=lcd_bit_buffer[y2][xx];
temp^=(1<lcd_bit_buffer[y2][xx]=temp;

//yy=(yy+64-1)%64;//修正y地址
yy=(yy+63)%64;//修正y地址
}
//-------------------------------------------------
xx=(xx+1)%128;
}
yy=y_y;//恢復(fù)原y軸

}

//********************************
//顯示一個(gè)英文字符
//********************************
voiddis_char_buffer(constunsignedchar*sp)
{
unsignedchari,j;
unsignedcharx_x,y_y;
unsignedchartemp_data,y;

unsignedchartemp;
unsignedchary1,y2;
x_x=xx;
y=y_y=yy;//保存y軸

i=8;//顯示字模8*16
while(i--)
{
temp_data=*sp++;
yy=y;
//------------寫一個(gè)字節(jié)---------------------------
for(j=8;j>0;j--)
{
y1=yy%8;//0-7bie
y2=yy>>3;//0-7行
temp=lcd_bit_buffer[y2][xx];
if(temp_data&0x80)//寫點(diǎn)
temp|=(1<
else
temp&=~(1<lcd_bit_buffer[y2][xx]=temp;
temp_data<<=1;
yy=(yy+64-1)%64;//修正y地址
}
//-------------------------------------------------
xx=(xx+1)%128;

}

y=yy;//顯示下半個(gè)字

xx=x_x;//寫x_x到xx
i=8;//顯示字模8*16
while(i--)
{
temp_data=*sp++;
yy=y;
//------------寫一個(gè)字節(jié)---------------------------
for(j=8;j>0;j--)
{
y1=yy%8;//0-7bie
y2=yy>>3;//0-7行
temp=lcd_bit_buffer[y2][xx];
if(temp_data&0x80)//寫點(diǎn)
temp|=(1<
else
temp&=~(1<lcd_bit_buffer[y2][xx]=temp;
temp_data<<=1;
yy=(yy+64-1)%64;//修正y地址
}
//-------------------------------------------------
xx=(xx+1)%128;
}
yy=y_y;//恢復(fù)原y軸

}
//********************************
//顯示一個(gè)漢字
//********************************
voiddis_hz_buffer(constunsignedchar*sp)
{
unsignedchari,j;
unsignedcharx_x,y_y;
unsignedchartemp_data,y;

unsignedchartemp;
unsignedchary1,y2;
x_x=xx;
y=y_y=yy;//保存y軸

i=16;//顯示字模8*16
while(i--)
{
temp_data=*sp++;
yy=y;
//------------寫一個(gè)字節(jié)---------------------------
for(j=8;j>0;j--)
{
y1=yy%8;//0-7bie

y2=yy>>3;//0-7行
temp=lcd_bit_buffer[y2][xx];
if(temp_data&0x80)
temp|=(1<else
temp&=~(1<lcd_bit_buffer[y2][xx]=temp;
temp_data<<=1;
yy=(yy+64-1)%64;//修正y地址
}
//-------------------------------------------------
xx=(xx+1)%128;
}

y=yy;//顯示下半個(gè)字

xx=x_x;//寫x_x到xx
i=16;//顯示字模16*16
while(i--)
{
temp_data=*sp++;
yy=y;
//------------寫一個(gè)字節(jié)---------------------------
for(j=8;j>0;j--)
{
y1=yy%8;//0-7bie
y2=yy>>3;//0-7行
temp=lcd_bit_buffer[y2][xx];
if(temp_data&0x80)//寫點(diǎn)
temp|=(1<else
temp&=~(1<lcd_bit_buffer[y2][xx]=temp;
temp_data<<=1;
yy=(yy+64-1)%64;//修正y地址
}
//-------------------------------------------------
xx=(xx+1)%128;
}
yy=y_y;//恢復(fù)原y軸
}
//*********************************
//顯示一個(gè)漢字字符
//包含自動(dòng)查字庫(kù)
//*********************************
voiddis_buffer(unsignedintdata)
{
unsignedchartemp,data_temp;
unsignedchartemp_h,temp_l;
unsignedchara_temp;
unsignedchari;


if((data>>8)>128)
{
//漢字

i=0;
temp_h=(unsignedchar)(data>>8);
temp_l=(unsignedchar)(data&0x00ff);
while(1)
{
WDR();
if((Chinese_characters_tab[i][0]==0xff)&&(Chinese_characters_tab[i][1]==0xff))//查找失敗失敗顯示黑色方塊
break;

if((Chinese_characters_tab[i][0]==temp_h)&&(Chinese_characters_tab[i][1]==temp_l))//查找成功
break;
i++;
}

dis_hz_buffer(&Chinese_characters_tab[i][2]);

}
else//英文
{
i=0;
data_temp=(unsignedchar)data;
while(1)//查字庫(kù)
{
WDR();
if(character_tab[i][0]==0xff)//查找失敗失敗顯示黑色方塊
break;

if(character_tab[i][0]==data_temp)//查找成功
break;
i++;
}

dis_char_buffer(&character_tab[i][1]);
}

}
//****************************
//顯示字符串ram中
//****************************
voiddis_lcd_buffer(unsignedchar*aa)
{
while(*aa)
{

if(*aa>128)
{
dis_buffer(((*aa<<8)|*(aa+1)));
aa+=2;
}
else
{
dis_buffer(*aa);
aa++;
}
}
}
//****************************
//顯示字符串Rom中
//****************************
voiddis_lcd_buffer_rom(constunsignedchar*aa)
{
while(*aa)
{

if(*aa>128)
{
dis_buffer(((*aa<<8)|*(aa+1)));
aa+=2;
}
else
{
dis_buffer(*aa);
aa++;
}
}
}
//*********************************************************

本文引用地址:http://www.butianyuan.cn/article/201611/315484.htm

-----------------------------------------------------------------------------------------------------------

//字庫(kù)結(jié)構(gòu)

//漢字
typedefconststruct{

constunsignedcharcha[2];
constunsignedchardata[32];

}character_struct;

character_structChinese_characters_tab[]={
{
{"溫"},
{0x08,0x84,0x61,0x0E,0x00,0x7E,0x52,0x52,0x52,0x52,0x52,0x7E,0x00,0x00,0x00,0x00,
0x40,0x7F,0x80,0x02,0xFE,0x82,0x82,0xFE,0x82,0x82,0xFE,0x82,0x82,0xFE,0x02,0x00},
},
{
{"度"},
{0x00,0x00,0x3F,0x20,0x24,0x24,0x3F,0xA5,0x65,0x25,0x3F,0x24,0x24,0x24,0x20,0x00,
0x01,0x06,0xF8,0x01,0x01,0x42,0x62,0x54,0x48,0x48,0x54,0x64,0x42,0x03,0x02,0x00,},
},
//.......................
//結(jié)束標(biāo)志
{
{0xff,0xff},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,}
},

};
//英文
constunsignedcharcharacter_tab[][17]={

/*--文字:!--*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16--*/
!,0x00,0x00,0x00,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xCC,0x0C,0x00,0x00,0x00,
//!,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*--文字:#--*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16--*/
#,0x02,0x03,0x1E,0x02,0x03,0x1E,0x02,0x00,0x20,0xFC,0x20,0x20,0xFC,0x20,0x20,0x00,
//#,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*--文字:%--*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16--*/
%,0x0F,0x10,0x0F,0x00,0x07,0x18,0x00,0x00,0x00,0x84,0x38,0xC0,0x78,0x84,0x78,0x00,

/*--文字:*--*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16--*/
*,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,

/*--文字:---*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16--*/
-,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,

/*--文字:+--*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16--*/
+,0x00,0x00,0x00,0x0F,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0xF8,0x80,0x80,0x80,0x00,

/*--文字:=--*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16--*/
=,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00,

/*--文字:[--*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16--*/
[,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,

/*--文字:]--*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16--*/
],0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,

/*--文字:?--*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16--*/
?,0x00,0x0E,0x12,0x10,0x10,0x10,0x0F,0x00,0x00,0x00,0x00,0x0C,0x6C,0x80,0x00,0x00,

/*--文字:/--*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16--*/
/,0x00,0x00,0x00,0x00,0x01,0x06,0x18,0x20,0x00,0x06,0x18,0x60,0x80,0x00,0x00,0x00,

/*--文字:--*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16--*/
0x5c,0x00,0x30,0x0C,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x1C,0x03,0x00,


/*--文字:空格--*/
/*--NewCenturySchoolbook12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16--*/
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
//攝氏度符號(hào)
0xfe,0x18,0x18,0x03,0x04,0x08,0x08,0x08,0x04,0x00,0x00,0xF0,0x08,0x04,0x04,0x04,0x08,
//結(jié)束標(biāo)志
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,

};



評(píng)論


相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉