永发信息网

求LCD12232显示汉字的程序

答案:1  悬赏:20  手机版
解决时间 2021-07-18 20:05
求LCD12232显示汉字的程序
最佳答案

硬件:TG12232B (122*32)模拟口线接线方式
连接线图:
--------------------------------------------------|
|DB0-----P0.0 | DB4-----P0.4 | RW-------P1.1 | A0--------P1.0 |
|DB1-----P0.1 | DB5-----P0.5 | RS-------P2.1 | V0接1K电阻到GND |
|DB2-----P0.2 | DB6-----P0.6 | E1-------P1.3 |
|DB3-----P0.3 | DB7-----P0.7 | E2-------P1.2 |
---------------------------------------------------



[注:AT89x52使用22.1184M或11.0592M晶振,实测使用22.1184M或11.0592都可以]
编译平台:Keil uV2 7.08



//可能看起来有点乱,不过效果还是不错的,显示图形总的来说比显示汉字要简单,当然显示汉字也不难。
希望此程序能给你一些帮助。
=============================================================*/



#include <AT89X52.H>


#define uchar unsigned char
#define uint unsigned int


#define E1 P1_3 //块1 左边
#define E2 P1_2 //块2 右边
#define RW P1_1
#define A0 P1_0 //A0为1时是数据,0时为指令数据
#define DATA P0 //数据


extern unsigned char code Bmpt1[];
extern unsigned char code Bmpt2[];
extern unsigned char code Bmpt3[];
extern unsigned char code Bmpt4[];
extern unsigned char code Bmpt5[];
extern unsigned char code Bmpt6[];
extern unsigned char code Bmpt7[];
extern unsigned char code Bmptc[];
extern unsigned char code bmp001[];
extern unsigned char code Bmp08[];
extern unsigned char code Bmp07[];
extern unsigned char code Bmp06[];
extern unsigned char code Bmp05[];
extern unsigned char code Bmp04[];
extern unsigned char code Bmp03[];
extern unsigned char code Bmp02[];
extern unsigned char code Bmp01[];
extern unsigned char code Bmp012[];
extern unsigned char code Bmp003[];
extern unsigned char code Bmp002[];



//延时
void delay(unsigned int i)
{
unsigned char k=200;
while(i>0)
{
i--;
}
while(k>1)k--;
}


//左页
//发送数据
void OUTMD(unsigned char i)
{
A0=1; //写数据
//delay(5);
E1=1;
//delay(10);
DATA=i;
//delay(5);
E1=0;


}
//左页
//发送命令
void OUTMI(unsigned char i)
{
A0=0; //写指令
//delay(5);
E1=1;
//delay(10);
DATA=i;
//delay(5);
E1=0;


}
//右页
//发送数据
void OUTSD(unsigned char i)
{
A0=1; //写数据
//delay(5);
E2=1;
//delay(10);
DATA=i;
//delay(5);
E2=0;


}
//右页
//发送命令
void OUTSI(unsigned char i)
{
A0=0; //写指令
//delay(5);
E2=1;
//delay(10);
DATA=i;
//delay(5);
E2=0;


}



//初始化
void lcdini(void)
{
RW=0;
OUTMI(0xE2);
OUTSI(0xE2);//复位
OUTMI(0xAE);
OUTSI(0xAE);//POWER SAVE
OUTMI(0xA4);
OUTSI(0xA4);//动态驱动
OUTMI(0xA9);
OUTSI(0xA9);//1/32占空比
OUTMI(0xA0);
OUTSI(0xA0);//时钟线输出
OUTMI(0xEE);
OUTSI(0xEE);//写模式


OUTMI(0x00);
OUTMI(0xC0);
OUTSI(0x00);
OUTSI(0xC0);


OUTMI(0xAF);
OUTSI(0xAF);


}

void SetPage(uchar page0,uchar page1)
{
OUTMI(0xB8|page1);OUTSI(0xB8|page0);
}



void SetAddress(uchar address0,uchar address1)
{
OUTMI(address1);OUTSI(address0);
}



void PutCharR(uchar ch)
{
OUTSD(ch);
}



void PutCharL(uchar ch)
{
OUTMD(ch);
}



void DrawBmp(bit layer,uchar width,uchar *bmp)
{
uchar x,address,i=0; //address表示显存的物理地址
uchar page=0; //page表示上下两页
bit window=0; //window表示左右两页
//putcharR //右边
//putcharL //左边


for (x=width;x>1;x--)
{
if (i>60) {window=1;address=i%61;}
else address=i;


if(layer==0) //显示一行八个字
{
SetPage(0,0);
SetAddress(address,address);
if(window==1)PutCharR(bmp[i]);
else PutCharL(bmp[i]);
SetPage(1,1);
SetAddress(address,address);
if(window==1)PutCharR(bmp[i+width]);
else PutCharL(bmp[i+width]);
}
else
{ //显示第二行八个汉字
SetPage(2,2);
SetAddress(address,address);
if(window==1)PutCharR(bmp[i]);
else PutCharL(bmp[i]);
SetPage(3,3);
SetAddress(address,address);
if(window==1)PutCharR(bmp[i+width]);
else PutCharL(bmp[i+width]);
}
i++;


}
}




void clrscr(void)
{
uchar i;
uchar page;
for (page=0;page<4;page++)
{
SetPage(page,page);
SetAddress(0,0);
for (i=0;i<61;i++){PutCharR(0);PutCharL(0);}
}
}


//-----------------------------------------------------------
//图片显示
//采用字模2生成或字模3生成的都可以.
//-----------------------------------------------------------
void DrawBmp1(uint x_add, uchar width,uchar *bmp)
{
uchar x,address,i=0; //address表示显存的物理地址
uchar page=0; //page表示上下两页
bit window=0; //window表示左右两页
//putcharR //右边
//putcharL //左边
for (x=width;x>1;x--)
{
if (x_add>60) {window=1;address=x_add%61;}
else address=x_add;



SetPage(0,0);
SetAddress(address,address);
if(window==1)PutCharR(bmp[i]);
else PutCharL(bmp[i]);
SetPage(1,1);
SetAddress(address,address);
if(window==1)PutCharR(bmp[i+width]);
else PutCharL(bmp[i+width]);



SetPage(2,2);
SetAddress(address,address);
if(window==1)PutCharR(bmp[i+width+width]);
else PutCharL(bmp[i+width+width]);
SetPage(3,3);
SetAddress(address,address);
if(window==1)PutCharR(bmp[i+width+width+width]);
else PutCharL(bmp[i+width+width+width]);
i++;
x_add++;


}
}


//---------------------------------------------------------------
//---------------------------------------------------------------
//采用zimo2 显示汉字,以汉字的显示方式
//void Draw_word(uchar d_where,uint x_add,bit layer,uchar width)
//d_where表示在码表中第几个汉字,x_add横坐标位置,layer显示的层, width显示的宽度。
//---------------------------------------------------------------



void Draw_word(uchar d_where,uint x_add,bit layer,uchar width)
{
uchar x,i=0,address; //address表示显存的物理地址
uchar page=0; //page表示上下两页
bit window=0; //window表示左右两页
//putcharR //右边
//putcharL //左边
d_where=d_where*32;


for (x=width;x>1;x--)
{
if (x_add>60) {window=1;address=x_add%61;}
else address=x_add;


if(layer==0) //显示一行八个字
{


SetPage(0,0);
SetAddress(address,address);
if(window==1)PutCharR(bmp001[d_where]);//右边
else PutCharL(bmp001[d_where]);//左边
SetPage(1,1);
SetAddress(address,address);
if(window==1)PutCharR(bmp001[d_where+width]);
else PutCharL(bmp001[d_where+width]);


}
else
{ //显示第二行八个汉字
SetPage(2,2);
SetAddress(address,address);
if(window==1)PutCharR(bmp001[d_where]);//右边
else PutCharL(bmp001[d_where]);//左边
SetPage(3,3);
SetAddress(address,address);
if(window==1)PutCharR(bmp001[d_where+width]);
else PutCharL(bmp001[d_where+width]);


}
x_add++;
d_where++;
}
}



//液晶显示规则
// M(左) S(右)
// page page
// 0 | 0
// 1 | 1
// 2 | 2
// 3 | 3


void delay1s(unsigned char i)
{
while(i>1)
{
i--;


delay(65530);
}
}


//显示动态的等待图标
void wait1(unsigned char i)
{
for(;i>1;i--)
{delay1s(2);
clrscr(); //
DrawBmp1(0,60,Bmptc); //
DrawBmp1(76,19,Bmpt1); //
delay1s(2);
clrscr(); //
DrawBmp1(0,60,Bmptc); //
DrawBmp1(76,19,Bmpt2); //
delay1s(2);
clrscr(); //
DrawBmp1(0,60,Bmptc); //
DrawBmp1(76,19,Bmpt3); //
delay1s(2);
clrscr(); //
DrawBmp1(0,60,Bmptc); //
DrawBmp1(76,19,Bmpt4); //
delay1s(2);
clrscr(); //
DrawBmp1(0,60,Bmptc); //
DrawBmp1(76,19,Bmpt5); //
delay1s(2);
clrscr(); //
DrawBmp1(0,60,Bmptc); //
DrawBmp1(76,19,Bmpt6); //
delay1s(2);
clrscr(); //
DrawBmp1(0,60,Bmptc); //
DrawBmp1(76,19,Bmpt7); //
}


}



//演示程序
void main()
{


lcdini(); //reset
clrscr(); //clr



Draw_word(0,0,0,16); //
Draw_word(1,16,0,16); //
Draw_word(2,32,0,16); //
Draw_word(3,48,0,16); //
Draw_word(0,64,0,16); //
Draw_word(1,80,0,16); //
Draw_word(2,96,0,16); //


DrawBmp(1,120,Bmp002); //
clrscr(); //
delay1s(3);
DrawBmp1(0,122,Bmp012); //LOGO
while(1)
{
delay1s(3);


clrscr(); //
DrawBmp1(10,101,Bmp07); //


delay1s(8);
clrscr(); //
wait1(3);
DrawBmp1(0,122,Bmp04); //
delay1s(8);
clrscr(); //
wait1(3);
DrawBmp1(0,122,Bmp03); //超前科技
delay1s(8);
clrscr(); //
wait1(3);
clrscr(); //
DrawBmp1(10,101,Bmp05); //
delay1s(8);
clrscr(); //
wait1(3);
clrscr(); //
DrawBmp1(10,101,Bmp06); //
delay1s(8);
clrscr(); //
wait1(3);
clrscr(); //
DrawBmp1(10,101,Bmp08); //
delay1s(8);
clrscr(); //
wait1(3);
clrscr(); //
DrawBmp1(0,122,Bmp01); //这仿真器真不错,用过都说好.
wait1(8);
}
}

我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
如何笑着看别人堕落?
黑名單有意思么、
梦幻西游45J跑商从哪里跑上可以跑的最省时间
我开了个网店,卖点卡的,生意不是很好,怎么
深渊LS和深渊无头 那个好打点
有哪些有推荐力的书本,并说出你将如何推荐这
一块条形磁铁.一块马蹄形磁铁,如何确定N极、S
诺基亚N95到哪买好?
为什么N85一接上数据线就会充电啊?怎么取消
某车间加工一批零件,原计划每天加工260个,25
qq飞车怎么点亮啊????
(520+1314)×10是什么意思
网页视频不能看 像优酷,土豆 优酷上说是配置
天天早晨洗头对身体有坏处嘛?
税控盘丢了怎么处理,国税报税盘丢了怎么办?
推荐资讯
求高人解梦?!
湖南6区45级DNF中魔道用的紫扫把能卖多少金币
网上有没有玩游戏加速的软件~~免费的
情人太熟悉了是不是就会开始淡了?
诺基亚手机除了按*#06#之外,还有别的可以查
怎么好好爱一个女人呢?
矢加隹是什么字?
现在电脑流行裸奔?还是装杀毒的好?nod32对
DNFPK怎么我打他们怎么不会倒地的?
给我介绍下淘宝哪些商家卖手机的信誉高!
诛仙2 75级到105级值得做的任务
差等初中生自评评语,我的教室400字说明文(要
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?