|
多看幾遍12864的說(shuō)明書DATASHEET,將引腳功能、數(shù)據(jù)、控制 代碼記熟,先排除硬件問題。再仔細(xì)校對(duì)控制時(shí)序。
static void lcd12864_write_command(uint8 cmd)/*寫命令*/
{
while(lcd12864_chek_busy());
LCD12864_RS = 0;
LCD12864_RW = 0;
LCD12864_EN = 0;
delay1us();
LCD12864_DATA = cmd;
delay50us();
LCD12864_EN = 1;
delay50us();
LCD12864_EN = 0;
return temp1;
}
// 描述: lcd12864寫數(shù)據(jù)
// 參數(shù): dat:寫入的數(shù)據(jù).
// 返回: none.
//========================================================================
static void lcd12864_write_data(uint8 dat)
{
while(lcd12864_chek_busy());
LCD12864_RS = 1;
LCD12864_RW = 0;
LCD12864_EN = 0;
LCD12864_DATA = dat;
delay50us();
LCD12864_EN = 1;
delay50us();
LCD12864_EN = 0;
}
//========================================================================
// 描述: lcd12864初始化
// 參數(shù): none.
// 返回: none.
//========================================================================
void lcd12864_init()
{
//引腳配置
LCD12864_RS_OUT;
LCD12864_RW_OUT;
LCD12864_E_OUT;
LCD12864_RST_OUT;
LCD12864_DATA_OUT;
LCD12864_RST = 1;
LCD12864_RST = 0;
LCD12864_RST = 1; //復(fù)位RST=1
lcd12864_write_command(0x34); //34H--擴(kuò)充指令操作
delay5us();
lcd12864_write_command(0x30); //功能設(shè)置,一次送8位數(shù)據(jù),基本指令集
delay5us();
lcd12864_write_command(0x0C); //顯示狀態(tài)開關(guān):整體顯示開,光標(biāo)顯示關(guān),光標(biāo)顯示反白關(guān)
delay5us();
lcd12864_write_command(0x01); //清DDRAM
delay5us();
lcd12864_write_command(0x02); //DDRAM地址歸位
delay5us();
lcd12864_write_command(0x80); //設(shè)定DDRAM 7位地址000,0000到地址計(jì)數(shù)器AC
delay5us();
}
//========================================================================
// 描述: lcd12864設(shè)定顯示位置
// 參數(shù): X,Y:坐標(biāo).
// 返回: none.
//========================================================================
void lcd12864_display_pos(uint8 X,uint8 Y)
{
uint8 pos;
if (Y==0)
{Y=0x80;}
else if (Y==1)
{Y=0x90;}
else if (Y==2)
{Y=0x88;}
else if (Y==3)
{Y=0x98;}
pos = X+Y ;
lcd12864_write_command(pos); //顯示地址
}
//========================================================================
// 描述: lcd12864清屏
// 參數(shù): none.
// 返回: none.
//========================================================================
void lcd12864_clear()
{
lcd12864_write_command(0x30);//
lcd12864_write_command(0x01);//清除顯示
delay(1);
}
//========================================================================
// 描述: lcd12864寫單個(gè)字符
// 參數(shù): X,Y;坐標(biāo); sig:要顯示的字符.
// 返回: none.
//========================================================================
void lcd12864_show_char(uint8 X,uint8 Y,uint8 sig)
{
lcd12864_display_pos(X,Y);
lcd12864_write_data(sig); //輸出單個(gè)字符
}
//========================================================================
// 描述: lcd12864寫字符串
// 參數(shù): X(0~3)行,Y(0~7)個(gè)字符; str:要顯示的字符串;
// 返回: none.
//========================================================================
void lcd12864_show_string(uint8 X,uint8 Y,uint8 *str)
{
uint8 i = 0;
lcd12864_display_pos(X,Y);
while(str[i] != '\0')
{
lcd12864_write_data(str[i]);
i++;
}
}
//========================================================================
// 描述: lcd12864寫數(shù)字()
// 參數(shù): X(0~3)行,Y(0~7)個(gè)字符; num:要顯示的數(shù)字;
// 返回: none.
//========================================================================
void lcd12864_show_num(uint8 x,uint8 y,int num)
{
char men[8];
char *str = men;
sprintf(str,"%d",num);
lcd12864_show_string(x,y,str);
}
//========================================================================
// 描述: lcd12864顯示圖像
// 參數(shù): p:要顯示的圖像.
// 返回: none.
//========================================================================
void lcd12864_show_image(uint8 *p)
{
int ygroup,x,y,i;
int temp;
int tmp;
for(ygroup=0;ygroup<64;ygroup++) //寫入液晶上半圖象部分
{ //寫入坐標(biāo)
if(ygroup<32)
{
x=0x80;
y=ygroup+0x80;
}else
{
x=0x88;
y=ygroup-32+0x80;
}
lcd12864_write_command(0x34); //寫入擴(kuò)充指令命令
lcd12864_write_command(y); //寫入y軸坐標(biāo)
lcd12864_write_command(x); //寫入x軸坐標(biāo)
lcd12864_write_command(0x30); //寫入基本指令命令
tmp=ygroup*16;
for(i=0;i<16;i++)
{
temp=p[tmp++];
lcd12864_write_data(temp);
}
}
lcd12864_write_command(0x34); //寫入擴(kuò)充指令命令
lcd12864_write_command(0x36); //顯示圖象
}
|
|