在12864液晶上显示任何图像

一,所需软件:

Any to Icon

作用:用来把随意彩图,转化成黑白2色图。

windows画图软件



作用:用来编辑DIY2色图片,并可改属性改成128X64像素

字模提取软件

作用:把128X64像素的图片,生成编程所需要的十六进制代码。 

二,自己完全DIY一副图画(就像在一张白纸上画自己想画的),或修改一副2色的BMP图,然后在让它在液晶上显示。

步骤如下:

1,双击打开windows画图软件

2,点击 图像->属性,设置如下,确定



3.点击 查看-> 缩放-> 自定义

选择缩放到600%,确定

4.点击 查看-> 缩放-> 显示网格

5.通过画图工具可在网格内自己写字和画图



6.如果已有一幅2色的BMP图,但不是128X64,用同样方法把图用画图软件打开,放大,加上网格,再进行编辑



编辑成自己想要的,



7.保存,退出画图。

8.双击打开取字模软件软件,点击“打开图像图标”按钮



9.点击‘参数设置’->其他选项,设置如下,

10.取模方式用C51格式,把点阵生成区的代码复制到程序中即可。

如果是彩图,先用Any to Icon软件转化成2色黑白图,重复以上步骤即可。 

C语言代码:

#include "AT89X52.h"
#include "intrins.h"

#define uint unsigned int
#define uchar unsigned char
#define lcddata P0               //宏定义lcddata为P0口数据

sbit rs=P2^0;      //定义数据,命令端
sbit rw=P2^1;      //定义读写端
sbit e=P2^2;      //定义使能端
sbit busy=P0^7; 

uchar code tab[]=
{
0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x20,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,
0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0x00,0x40,
0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0x00,0x40,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x00,0x00,0x00,0x01,0xC2,0x40,
0x00,0x00,0x00,0x06,0x30,0x01,0xE0,0x00,0x00,0x2A,0x00,0x00,0xD8,0x01,0xC6,0x40,
0x00,0x00,0x00,0x0F,0x7B,0x63,0xE0,0x00,0x00,0x22,0x00,0x01,0x24,0x00,0x04,0x40,
0x00,0x00,0x00,0x0F,0xFB,0x63,0x07,0x34,0x00,0x14,0x00,0x01,0x04,0x00,0x08,0xF8,
0x00,0x00,0x00,0x0D,0xDB,0x63,0x01,0xBC,0x00,0x08,0x00,0x00,0x88,0x00,0x1F,0x40,
0x00,0x04,0x00,0x0C,0x1B,0x63,0x07,0xB0,0x00,0x00,0x00,0x00,0x50,0x00,0x30,0x40,
0x00,0x06,0x00,0x0C,0x1B,0x63,0xED,0xB0,0xDB,0x00,0x01,0x00,0x20,0x00,0x00,0x40,
0x00,0x02,0x00,0x0C,0x19,0xE1,0xE7,0xB0,0xDB,0x00,0x02,0x00,0x00,0x00,0x00,0x40,
0x00,0x02,0x00,0x0C,0x19,0xE1,0xE7,0xB0,0xDB,0x00,0x02,0x00,0x00,0x00,0x00,0x40,
0x00,0x02,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x42,
0x00,0x02,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x03,0xFF,0xFE,
0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x05,0x00,0x00,0x00,0x40,
0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x0A,0x80,0x00,0x00,0x40,
0x00,0x02,0x20,0x00,0x00,0x0A,0x00,0x00,0xFF,0xF8,0xE0,0x05,0x00,0x00,0x00,0x40,
0x00,0x82,0x20,0x06,0xC0,0x15,0x00,0x1F,0xFF,0xFF,0xC0,0x02,0x00,0x00,0x00,0x40,
0x00,0x82,0x30,0x09,0x20,0x11,0x00,0xFB,0xFF,0xE1,0xF8,0x00,0x00,0x00,0x00,0x40,
0x01,0x82,0x10,0x08,0x20,0x0A,0x03,0x9F,0x00,0x9E,0x3E,0x00,0x00,0x00,0x00,0x40,
0x01,0x02,0x10,0x04,0x40,0x04,0x0E,0x70,0x00,0x81,0xC7,0x80,0x01,0x40,0x00,0x40,
0x01,0x02,0x08,0x02,0x80,0x00,0x1D,0x80,0x00,0xE0,0x61,0xE0,0x02,0xA0,0x00,0x40,
0x02,0x02,0x08,0x01,0x00,0x00,0x77,0x9F,0xFC,0xF0,0x18,0xF8,0x02,0x20,0x00,0x40,
0x06,0x02,0x08,0x00,0x00,0x01,0xDF,0x00,0x00,0xF3,0x0C,0x3C,0x01,0x40,0x00,0x00,
0x0C,0x06,0x0C,0x00,0x00,0x03,0x9E,0x00,0x00,0xF8,0x06,0x1E,0x00,0x80,0x00,0x00,
0x00,0x44,0x04,0x00,0x00,0x07,0x0E,0x30,0x01,0xFC,0x7F,0x07,0x00,0x00,0x00,0x00,
0x00,0x6C,0x06,0x00,0x00,0x07,0x0E,0x30,0x01,0xFC,0x7F,0x07,0x00,0x00,0x00,0x00,
0x00,0x38,0x03,0x00,0x00,0x7E,0xFF,0xFF,0xFF,0xFF,0xFF,0x83,0xC0,0x00,0x00,0x00,
0x00,0x18,0x00,0x00,0x0F,0xFD,0xFF,0xFF,0xFF,0xFF,0xFC,0x01,0xF0,0x00,0x78,0x00,
0x00,0x00,0x00,0x00,0x3F,0x81,0xFF,0x00,0x00,0x00,0x00,0x1F,0xF0,0x00,0x48,0x00,
0x00,0x00,0x00,0x00,0xFE,0xF0,0x00,0x00,0x01,0x00,0x00,0xC0,0x1C,0x00,0x44,0x00,
0x00,0x03,0x00,0x03,0xC0,0x07,0x80,0x00,0x03,0xE2,0x07,0x00,0x1C,0x00,0x46,0x00,
0x00,0x06,0x00,0x03,0x80,0x03,0x40,0x00,0x03,0xE0,0x0C,0x00,0x0E,0x00,0x42,0x00,
0x00,0x1C,0x00,0x07,0x00,0x00,0xC0,0x00,0x00,0x20,0x18,0x00,0x07,0x00,0x42,0x00,
0x00,0xF0,0x00,0x09,0x01,0x80,0x60,0x00,0x00,0x20,0x73,0x9F,0x03,0x80,0x42,0x00,
0x00,0x10,0x00,0x1E,0x0F,0xF2,0x20,0x00,0x00,0x20,0x67,0xFF,0xC1,0xC0,0x46,0x00,
0x00,0x10,0x00,0x1E,0x1F,0xF9,0x30,0x00,0x00,0x20,0xEF,0xFF,0xE0,0xE0,0x7C,0x00,
0x03,0xFC,0x00,0x38,0x3F,0xFC,0x90,0x00,0x00,0x20,0xCB,0xFF,0xF9,0xF0,0xFF,0x00,
0x00,0x10,0x00,0x7F,0x7F,0xFE,0x10,0x00,0x00,0x20,0xDB,0xFF,0xFF,0xF0,0x41,0xC0,
0x00,0x10,0x00,0x6E,0xF9,0xBF,0x10,0x00,0x00,0x20,0xF7,0xED,0xFF,0xF0,0x40,0x60,
0x00,0x11,0x00,0x7C,0xFC,0x3F,0x10,0x00,0x00,0x20,0x67,0xE1,0xFD,0xE0,0x40,0x30,
0x03,0xFF,0x00,0x7C,0xFC,0x3F,0x10,0x00,0x00,0x20,0x67,0xE1,0xFD,0xE0,0xC0,0x10,
0x00,0x10,0x00,0x38,0xFC,0x3F,0x18,0x00,0x00,0x20,0x87,0xE0,0xFD,0xC0,0x80,0x08,
0x00,0x20,0x00,0x38,0xF1,0x8F,0x18,0x00,0x1F,0xE7,0x87,0x9C,0x7D,0xC0,0x80,0x08,
0x00,0x60,0x00,0x1C,0xFE,0x1F,0x81,0xFF,0xFF,0xC0,0x0F,0xE0,0xFF,0x80,0x80,0x04,
0x00,0x40,0x00,0x0C,0xFC,0x3F,0x80,0x00,0x00,0x00,0x0F,0xE1,0xF8,0x00,0x80,0x04,
0x01,0x80,0x00,0x00,0xF9,0xBF,0xE0,0x00,0x00,0x00,0x03,0xEC,0xF6,0x01,0x80,0x0C,
0x01,0xC3,0x00,0x00,0xF9,0xBF,0x00,0x00,0x00,0x00,0x00,0xFF,0xCC,0x01,0x80,0x18,
0x00,0x3F,0x80,0x00,0x7F,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x00,0x81,0xF0,
0x00,0x00,0xC0,0x00,0x07,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,
0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x20,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,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,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,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,

};


void delaynms(uint aa)
{
  uchar bb;
  while(aa--)
  {
   for(bb=0;bb<115;bb++)     //1ms基准延时程序
   {
    ;
   }
  }

void busy_lcd(void)
{
   busy=1;      //把忙标志位置1
   e=0;       //把使能端置0
   rs=0;      //把rs端置0,为指令操作
   rw=1;      //为读操作
   e=1;       //拉高使能端
   _nop_();      //等待
   while(busy==1);    //检测忙标志位,
   e=0;       //忙标志位为0,则把使能拉低

}

void wr_i_lcd(comm)
{
  busy_lcd();      //忙标志检测
  rs=0;        //指令操作
  rw=0;        //写入操作
  e=1;        //拉高使能端
  lcddata=comm;      //放上数据
  _nop_();       //等待
  e=0;        //拉低使能端,数据写入液晶
}

void wr_d_lcd(dat)
{
  busy_lcd();      //忙标志检测
  rs=1;        //数据操作
  rw=0;        //写入操作
  e=1;        //拉高使能端
  lcddata=dat;      //放上数据
  _nop_();       //等待
  e=0;        //拉低使能端,数据写入液晶
}

void init_lcd(void)
{
  wr_i_lcd(0x30);  //基本指令集
  delaynms(1);   //等待
  wr_i_lcd(0x30);  //再设置一次为基本指令集,因为ST7920中有2个寄存器用来设置使用哪个指令集
  delaynms(1);   //等待
  wr_i_lcd(0x0c);  //开显示,关游标,关游标位置
  delaynms(1);   //等待
  wr_i_lcd(0x01);  //清屏,地址指针指向00H
  delaynms(20);   //等待>10ms
  wr_i_lcd(0x06);  //光标右移,整体不移

void img_disp(uchar code *img)
{
  uchar i,j;
  for(j=0;j<32;j++)
  {
   for(i=0;i<8;i++)
 {
   wr_i_lcd(0x34);       //扩充指令集,关绘图
   wr_i_lcd(0x80+j);    //先将垂直坐标(Y)写入绘图RAM地址
   wr_i_lcd(0x80+i);    //再将水平坐标(X)写入绘图RAM地址
   wr_i_lcd(0x30);    //打开基本指令集
   wr_d_lcd(img[j*16+i*2]);  //将D15--D8写入到RAM,
   wr_d_lcd(img[j*16+i*2+1]);   //将D7--D0写入到RAM
 }
  }
  for(j=32;j<64;j++)    //下半屏
  {
   for(i=0;i<8;i++)
 {
   wr_i_lcd(0x34);       //扩充指令集,关绘图
   wr_i_lcd(0x80+j-32);    //先将垂直坐标(Y)写入绘图RAM地址
   wr_i_lcd(0x88+i);    //再将水平坐标(X)写入绘图RAM地址
   wr_i_lcd(0x30);    //打开基本指令集
   wr_d_lcd(img[j*16+i*2]);  //将D15--D8写入到RAM,
   wr_d_lcd(img[j*16+i*2+1]);   //将D7--D0写入到RAM
 }
  }
  wr_i_lcd(0x36);                //打开绘图显示

}

void main(void)
{
  while(1)
  {
    init_lcd();     //初始化
     img_disp(tab);    //显示图像
     delaynms(1000);
 
  }
}

永不止步步 发表于12-17 09:32 浏览65535次
分享到:

已有0条评论

暂时还没有回复哟,快来抢沙发吧

添加一条新评论

只有登录用户才能评论,请先登录注册哦!

话题作者

永不止步步
金币:67417个|学分:363741个
立即注册
畅学电子网,带你进入电子开发学习世界
专业电子工程技术学习交流社区,加入畅学一起充电加油吧!

x

畅学电子网订阅号