点阵图形液晶显示模块除信息外,另一个优势是可以显示图形。现在介绍的是单色液晶,只能显示黑白图形,因此需要首先将图片转化为黑白图。图形的点点阵信息可以逐个查看像素点的黑白值。为了更快地得到图像的点阵信息,得到任何一个图形的点阵信息,可以选择一款字模提取程序,从中打开黑白图像即可。
使用液晶显示图形的程序代码示例如下
#include<reg52.h>
#include<stdio.h>
unsigned data i;
unsigned char q;
unsigned char *p2; //建立数组指针
unsigned char wbyte;
unsigned char Column; //定义列
unsigned char Page; //定义页
sbit E=P3^2; //读写使能信号,1有效
sbit R_W=P3^1; //读写选择信号;1为读选通,0为写选通
sbit RS=P3^0;
sbit D_I=P3^0; //数据指令选择信号;1为数据操作,0为写指令或读状态
unsigned char data j;
unsigned char data k;
/********************扩充指令集画图********************/
unsigned char data z; //图形数组的页,为实际点阵行数
unsigned char data y; //图形数组的列,为实际点阵列数除以8
unsigned char data Column; //起始点设定:为在液晶中显示的实际起始列
unsigned char data Page; //起始点设定:为在液晶中显示的实际起始行
char code Tu[64][16]= //图形数组,龙的标志
{
0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x03,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0xF0,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x07,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xFF,0xFC,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x07,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,
0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x0F,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFF,0xC0,
0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,
0x0F,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFF,0xE0,0x00,0x00,
0x00,0x00,0x00,0x00,0x0F,0xFF,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,
0xFF,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFF,0xF8,0x80,0x00,0x00,0x00,
0x00,0x00,0x1F,0xFF,0xFF,0xF8,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,0xF8,
0x80,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFF,0xF8,0x80,0x00,0x00,0x00,0xFF,0x1C,
0x0F,0xFF,0xFF,0xFC,0x80,0x00,0x00,0x07,0xFF,0x1F,0x0F,0xFF,0xFF,0xFC,0x80,0x06,
0x00,0x3F,0xFF,0x1F,0x0F,0xFF,0xFF,0xFE,0x80,0x06,0x03,0xFF,0xFF,0x1F,0x07,0xFF,
0xFF,0xFE,0x80,0x04,0x07,0xFF,0xFF,0x1F,0x07,0xFF,0xFF,0xFE,0xC0,0x1C,0x3F,0xFF,
0xFF,0x1F,0x07,0xFF,0xFF,0xFE,0x60,0x30,0xFF,0xFF,0xFF,0x1F,0x07,0xFF,0xFF,0xFE,
0x20,0xE1,0xFF,0xFF,0xFF,0x1F,0x07,0xFF,0xFF,0xFE,0x23,0x87,0xFF,0xFF,0xFF,0x1F,
0x03,0xFF,0xFF,0xFF,0x26,0x1F,0xFF,0xFF,0xFF,0x1E,0x01,0xFF,0xFF,0xFF,0x24,0x3F,
0xFF,0x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xFC,0x00,0x00,0x00,0x3F,0xFF,0xBB,0xFB,0xFF,0xFF,0xFE,0x00,0x00,0x00,
0x3F,0xFF,0xF7,0x7B,0x9F,0xFF,0xFF,0x00,0x00,0x00,0x07,0xFE,0xCE,0x7B,0xDF,0xFF,
0xFF,0x00,0x00,0x00,0x07,0xFF,0xDE,0x7B,0xDF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x1F,
0xB8,0x62,0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00,0x1E,0x30,0x02,0x7F,0xFF,0xFE,0x00,
0x00,0x00,0x00,0x0F,0xE0,0x02,0x7F,0xFF,0xFF,0x00,0x00,0x00,0x00,0x07,0x80,0x02,
0x7F,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x7F,0xFF,0xFF,0x00,0x00,0x00,
0x00,0x00,0x00,0x03,0x7F,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x3F,0xFF,
0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x3F,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,
0x00,0x03,0x3F,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xBF,0xFF,0xE0,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xC0,0x00,0x00,0x00
};
void WCOM(unsigned char dcode); //指令操作子函数
void Dat(unsigned char ddata); //数据操作子函数
void Imim(); //初始化子函数
void EClearlcd(); //扩充指令集清屏子函数
void Tuxing(); //图形显示子函数
void main()
{
Imim(); //初始化
EClearlcd(); //扩充指令集清屏
z=64; //图形数组的页,为实际点阵行数
y=16; //图形数组的列,为实际点阵列数除以8
Column=0; //起始点设定:为在液晶中显示的实际起始列
Page=0; //起始点设定:为在液晶中显示的实际起始行
p2=Tu; //图形数组
Tuxing(); //蝴蝶图案
while(1)
{
}
}
void WCOM(unsigned char dcode) //写指令程序
{
unsigned char q;
R_W=1;
D_I=0; //设置状态
Loop:
P1=0xFF;
E=1; //使能有效
q=P1; //将P1口状态读入
E=0; //关闭使能信号
if(q&0x80) //判断屏幕是否忙
{
goto Loop; //若忙,循环等待
}
R_W=0;
D_I=0; //写数据指令
P1= dcode; //将数据送入P1口
E=1; //使能信号开
E=0; //使能信号关
}
void Dat(unsigned char ddata)
{
unsigned char q;
R_W=1;
D_I=0; //读状态指令
Loop:
P1=0xFF;
E=1; //使能
q=P1;
E=0;
if(q&0x80) //判忙
{
goto Loop;
}
D_I=1; //送数据指令
R_W=0;
P1= ddata; //写入数据
E=1; //使能信号开
E=0; //使能信号关
}
void Clearlcd()
{
D_I=0;
R_W=0;
P1=0x01;
WCOM(0x01); //清除显示
}
void Imim()
{
P0=0xFF; //初始化单片机端口
P1=0xFF;
P2=0xFF;
P3=0xFF;
E=0;
WCOM(0x38); //功能设定
WCOM(0x08); //关显示指令
WCOM(0x06); //游标右移
Clearlcd(); //清屏
WCOM(0x0c); //开显示指令
}
void Tuxing()
{
unsigned char data v;
unsigned char data w;
unsigned char data x;
unsigned char data h;
unsigned char *pp; //图形数组指针
WCOM(0x34); //功能设定
WCOM(0x36); //扩充功能设定
pp=p2;
pp=pp+16*y*2;
for(h=0;h<z/2;h++) //页循环
{
v=Column|0x80;
w=Page|0x80;
WCOM(w); //送入起始页地址
WCOM(v); //送入起始列地址
Page++; //准备对下一页进行操作
for(x=0;x<2*y;x++) //列循环
{
if(x<y)
{
wbyte=*p2;
Dat(wbyte); //循环送入图形数据
p2=p2+1;
}
else
{
wbyte=*pp;
Dat(wbyte); //循环送入图形数据
pp=pp+1;
}
}
}
}
void EClearlcd()
{
unsigned char data Disp_Page;
unsigned char data i;
unsigned char data j;
for(i=0;i<64;i++) //共32页
{
Disp_Page=i|0x80; //设置页地址
WCOM(Disp_Page); //送入页地址
WCOM(0x80); //送入起始列地址
for(j=0;j<32;j++)
{
Dat(0x00); //清屏
}
}
} |