12864程序,字库与自定义字符的显示
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
}
w_cmd(0x30);//基本指令
delay(1);
w_cmd(0x02);//允许修改CG地址
delay(1);
w_cmd(z);//CG地址
delay(1);
for(i=0;i<16;i++)
{
w_dat(*s++);
w_dat(*s++);
}
}
/*----------------------------------------------
delay(1);
RES=1;
delay(10);
w_cmd(0x30);//功能设置,选着8位元模式
delay(1);
w_cmd(0x30);//选择基本指令集,因为DL与RE不能同时改变需要两个指令
delay(1);
w_cmd(0x0c);//开显示(无游标、不反白)
delay(1);
w_cmd(0x01);//clear print
case 3:z=0x04;break;
case 4: z=0x06;break;
default:break;
}
w_dat(0x00);
w_dat(z);
}
/*-------------------------
----------------------------*/
void main()
{ uint i=0;
delay(13);
w_cmd(0x06);//指定在资料的读取及写入时,设定游标的移动方向及指定显示的移位,光标从右向左加1位移动,屏幕不移动
delay(1);
}
/*------------------------------------------------
显示字符串
x:横坐标值,范围0~8
y:纵坐标值,范围1~4
/*------------------------------------
12864并口输入,在输入输出数据是注意时序
之前由于忙检测时序写错,而无法显示字库文字
自定义字符注意地址与编码方式对应,不然会
显示乱码
--------------------------------------*/
#include<reg52.h>
显示自定义字符
x为x轴方向取值0~8;
y为Y方向取值1~4;
z为四种编码,与地址一一对应;
-----------------------------------------------*/
void displaycgram(uchar x,uchar y,uchar z)
{
switch(y)
{
case 1: w_cmd(0x80+x);break;
void cgram(uchar *s,uchar z)
{ uchar i;
check_busy();
switch(z)//选着地址
{
case 1: z=0x40;break;
case 2:z=0x50;break;
case 3:z=0x60;break;
case 4: z=0x70;break;
default:break;
delay(1);
E=0;
delay(1);
}
void w_dat(uint dat)
{check_busy();
RS=1;
RW=0;
E=1;
data_portHale Waihona Puke Baidudat;
delay(1);
E=0;
delay(1);
}
void init_lcd(void)
{
delay(40);
PSB=1;
RES=0;
{
RW=1;
RS=0;
E=1;
data_port=0xff;
while((data_port&&0x80)==0x80);//data_port&&0x80必须加上括号
E=0;
}
void w_cmd(uint dat)
{check_busy();
RS=0;
RW=0;
E=1;
data_port=dat;
uchar code user[]={
/*--文字:我--*/
/*--宋体12;此字体下对应的点阵为:宽x高=16x16 --*/
0x06,0x40,0x38,0x50,0x08,0x48,0x08,0x48,0x08,0x40,0xFF,0xFE,0x08,0x40,0x08,0x48,
0x0E,0x28,0x38,0x30,0xC8,0x20,0x08,0x50,0x09,0x92,0x08,0x0A,0x28,0x06,0x10,0x02
0x90,0x40,0x12,0x50,0x12,0x4C,0x14,0x44,0x11,0x40,0x10,0xC0,0x00,0x00,0x00,0x00
};
void delay(uint xms)
{
uint i,j;
for(i=0;i<xms;i++)
for(j=0;j<125;j++);
}
void check_busy(void)
------------------------------------------------*/
void post(uchar x,uchar y)
{ uchar add;
switch(y)
{case 1:add=0x80;break;
case 2:add=0x90;break;
case 3:add=0x88;break;
init_lcd();
post(1,1);
while(display[i]!='\0')
{
w_dat(display[i]);
i++;
}
cgram(user,1);
displaycgram(0,4,1);
cgram(user1,2);
displaycgram(0,2,2);
while(1)
{
}
}
};
uchar code user1[]={
/*--文字:你--*/
/*--楷体_GB231212;此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0x08,0x80,0x08,0x80,0x08,0x80,0x11,0x38,0x11,0xC8,0x32,0x10,0x50,0x40,
case 4:add=0x98;break;
default:break;
}
add+=x;
w_cmd(add);
}
/*---------------------------------
写入自定义字符
四种编码与写入的地址是一一对应关系;
若不对应,则出现乱码,及z的取值必须相同
-------------------------------------*/
sbit RS = P2^4;
sbit RW = P2^5;
sbit E = P2^6;
sbit RES = P2^3;
sbit PSB = P2^1;
#define data_port P0
#define uchar unsigned char
#define uint unsigned int
uchar code display[]={"西华"};
case 2: w_cmd(0x90+x);break;
case 3: w_cmd(0x88+x);break;
case 4: w_cmd(0x98+x);break;
default:break;
}
switch(z)
{
case 1: z=0x00;break;
case 2:z=0x02;break;
w_cmd(0x30);//基本指令
delay(1);
w_cmd(0x02);//允许修改CG地址
delay(1);
w_cmd(z);//CG地址
delay(1);
for(i=0;i<16;i++)
{
w_dat(*s++);
w_dat(*s++);
}
}
/*----------------------------------------------
delay(1);
RES=1;
delay(10);
w_cmd(0x30);//功能设置,选着8位元模式
delay(1);
w_cmd(0x30);//选择基本指令集,因为DL与RE不能同时改变需要两个指令
delay(1);
w_cmd(0x0c);//开显示(无游标、不反白)
delay(1);
w_cmd(0x01);//clear print
case 3:z=0x04;break;
case 4: z=0x06;break;
default:break;
}
w_dat(0x00);
w_dat(z);
}
/*-------------------------
----------------------------*/
void main()
{ uint i=0;
delay(13);
w_cmd(0x06);//指定在资料的读取及写入时,设定游标的移动方向及指定显示的移位,光标从右向左加1位移动,屏幕不移动
delay(1);
}
/*------------------------------------------------
显示字符串
x:横坐标值,范围0~8
y:纵坐标值,范围1~4
/*------------------------------------
12864并口输入,在输入输出数据是注意时序
之前由于忙检测时序写错,而无法显示字库文字
自定义字符注意地址与编码方式对应,不然会
显示乱码
--------------------------------------*/
#include<reg52.h>
显示自定义字符
x为x轴方向取值0~8;
y为Y方向取值1~4;
z为四种编码,与地址一一对应;
-----------------------------------------------*/
void displaycgram(uchar x,uchar y,uchar z)
{
switch(y)
{
case 1: w_cmd(0x80+x);break;
void cgram(uchar *s,uchar z)
{ uchar i;
check_busy();
switch(z)//选着地址
{
case 1: z=0x40;break;
case 2:z=0x50;break;
case 3:z=0x60;break;
case 4: z=0x70;break;
default:break;
delay(1);
E=0;
delay(1);
}
void w_dat(uint dat)
{check_busy();
RS=1;
RW=0;
E=1;
data_portHale Waihona Puke Baidudat;
delay(1);
E=0;
delay(1);
}
void init_lcd(void)
{
delay(40);
PSB=1;
RES=0;
{
RW=1;
RS=0;
E=1;
data_port=0xff;
while((data_port&&0x80)==0x80);//data_port&&0x80必须加上括号
E=0;
}
void w_cmd(uint dat)
{check_busy();
RS=0;
RW=0;
E=1;
data_port=dat;
uchar code user[]={
/*--文字:我--*/
/*--宋体12;此字体下对应的点阵为:宽x高=16x16 --*/
0x06,0x40,0x38,0x50,0x08,0x48,0x08,0x48,0x08,0x40,0xFF,0xFE,0x08,0x40,0x08,0x48,
0x0E,0x28,0x38,0x30,0xC8,0x20,0x08,0x50,0x09,0x92,0x08,0x0A,0x28,0x06,0x10,0x02
0x90,0x40,0x12,0x50,0x12,0x4C,0x14,0x44,0x11,0x40,0x10,0xC0,0x00,0x00,0x00,0x00
};
void delay(uint xms)
{
uint i,j;
for(i=0;i<xms;i++)
for(j=0;j<125;j++);
}
void check_busy(void)
------------------------------------------------*/
void post(uchar x,uchar y)
{ uchar add;
switch(y)
{case 1:add=0x80;break;
case 2:add=0x90;break;
case 3:add=0x88;break;
init_lcd();
post(1,1);
while(display[i]!='\0')
{
w_dat(display[i]);
i++;
}
cgram(user,1);
displaycgram(0,4,1);
cgram(user1,2);
displaycgram(0,2,2);
while(1)
{
}
}
};
uchar code user1[]={
/*--文字:你--*/
/*--楷体_GB231212;此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0x08,0x80,0x08,0x80,0x08,0x80,0x11,0x38,0x11,0xC8,0x32,0x10,0x50,0x40,
case 4:add=0x98;break;
default:break;
}
add+=x;
w_cmd(add);
}
/*---------------------------------
写入自定义字符
四种编码与写入的地址是一一对应关系;
若不对应,则出现乱码,及z的取值必须相同
-------------------------------------*/
sbit RS = P2^4;
sbit RW = P2^5;
sbit E = P2^6;
sbit RES = P2^3;
sbit PSB = P2^1;
#define data_port P0
#define uchar unsigned char
#define uint unsigned int
uchar code display[]={"西华"};
case 2: w_cmd(0x90+x);break;
case 3: w_cmd(0x88+x);break;
case 4: w_cmd(0x98+x);break;
default:break;
}
switch(z)
{
case 1: z=0x00;break;
case 2:z=0x02;break;