深蓝创客

arduino学习笔记003.LCD12864液晶显示屏(LCD12864RSPI库)

一、简介

  LCD12864液晶显示屏是一种带中文字库的128X64像素显示屏,具有4位/8位并行、2线或3线串行多种接口,内部含有国标一级、二级简体中文字库的点阵图形液晶显示模块。内置8192个16*16点汉字,和128个16*8点ASCII字符集,利用该模块灵活的接口方式和简单、方便的操作指令,可构成全中文人机交互界面。可以显示8x4行16x16点阵汉字,也可完成图形显示,低电压低功耗是其又一显著特点。由该模块构成的液晶显示方案与同类型的图形点阵液晶显示模块相比,不论硬件电路构造或显示程序都要简洁得多。

  在本次实验中,我们采用arduino UNO作为微控器,使用LCD12864RSPI库进行编程,为了节约引脚资源,本次实验中采用较少的引脚连接方式,具体连接详情请见“硬件连接”部分。在本次实验中,使用的材料:

  【1】LCD12864液晶显示屏(20引脚)

  【2】面包板

  【3】Arduino UNO

  【4】杜邦线若干

二、硬件连接

2.1连接图

图2.1 arduino UNO与LCD12864液晶显示屏的连接图

 

图2.2 arduino UNO和LCD12864液晶屏引脚连接方式

 

2.2 硬件设置

  刚买回来的LCD12864显示屏第一次烧录程序不显示,可能是因为屏幕背部的亮度调试电位器没有设置好,这个时候需要旋转设置一下这个电位器,请见下图。

图2.3 背部设置对比亮度电位器

三、软件编程

3.1 常用函数

  【1】LCD12864RSPI  LCDA(int  _latchPin,int  _dataPin,int  _clockPin);

    摘要:设置LCDA显示屏的命令数据引脚、读写引脚、使能引脚。LCDA:注册的LCD名称;_latchPin:命令数据引脚;_dataPin:读写引脚;_clockPin:使能引脚。

  【2】void  LCDA.clear();

    摘要:清空LCDA屏幕。LCDA:注册的LCD名称。

  【3】void  LCDA.setCursor(uint8_t  x, uint8_t  y); 

    摘要:设置光标位置。x:x轴坐标;y:y轴坐标。

  【4】void  LCDA.DrawFullScreen(uchar  *p);

    摘要:显示整张图片。*p:数组。

  【5】void  LCDA.print(uint8_t value);

    摘要:输出字符串。value:打印的字符串。

3.2 典例一:显示中英文

  LCD12864显示屏内置有简体中文字库,需用通过“汉字机内码获取工具”进行转换,转换方法如下图3.1所示。

图3.1 汉字机内码获取工具使用说明

  从图3.1可知,1号方框表示要转换的中文字体“深蓝创客空间”;2号方框表示获取得到的数组名称“show0”;3号方框表示转换后的数组函数。用户输入要转换的简体中文,设置好数组名称,点击右侧“转换”就可以得到3号方框的转换结果,最后点击右侧“复制结果”按钮就可以把数组复制到程序里。

代码:

#include "LCD12864RSPI.h"

#define AR_SIZE(a) sizeof(a)/sizeof(a[0])   //获取中文字数

LCD12864RSPI LCDA(A0,A1,A2);    //配置RS,R/W,E引脚

unsigned char show0[]={
  0xC9, 0xEE,
  0xC0, 0xB6,
  0xB4, 0xB4,
  0xBF, 0xCD,
  0xBF, 0xD5,
  0xBC, 0xE4
};                    //深蓝创客空间
 
void setup()
{
  LCDA.clear();//清屏
}

uint16_t time_num = 0;    //计时次数

void loop()
{
  LCDA.clear();//清屏
  LCDA.setCursor(0,1);    //设置屏幕坐标
  LCDA.chinese(show0,AR_SIZE(show0)); //第1行第2格开始,显示文字"深蓝创客空间"。
  LCDA.setCursor(1,0);    //设置屏幕坐标
  LCDA.print("shenlan-workshop");     //第2行第1格开始,显示字母"shenlen-workshop"
  time_num = millis()/1000;           //计时器(毫秒)数值除以1000为秒数
  LCDA.setCursor(2,1);                //设置屏幕坐标    
  LCDA.print("run:");                 //打印运行时间(秒)。
  LCDA.print(time_num);
  LCDA.print("times.");
  delay(500);
}

 效果图:

图3.2 中英文显示效果

3.3 典例二:显示整张图片

  LCD12864RSPI库提供了显示整张图片的函数,方便我们制作开机LOGO。这里我们需要借助字体取模软件“Lcmzimo”来获取128*64像素bmp格式图片的16进制数据,此软件的使用方法如下。

 

 

图3.3 字模提取软件配置图

  由图3.3可以看出,1号方框用于设置像素大小,我们采用的像素大小为128*64,所以X,Y分别设置为128和64。先设置1号方框像素的大小,然后点击2号方框载入要获取数据的图片,格式为128*64的bmp图片。载入成功后,会在左下角大方框里显示点阵图片。最后点击3号方框“数据保存”,把数据保存在h文件里,把h文件里的数组复制到程序里就可以使用了。

  在本次例程中我们使用的“龙”图片,例程如下:

代码:

#include "LCD12864RSPI.h"

#define AR_SIZE(a) sizeof(a)/sizeof(a[0])   //获取中文字数

LCD12864RSPI LCDA(A0,A1,A2);    //设置RS,R/W,E引脚

unsigned char logo0[]={                                         //龙图案
      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,0x10,
      0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,
      0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,
      0x00,0x4C,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,
      0x04,0xDC,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,
      0x06,0xFE,0x04,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x0F,
      0xC7,0xFF,0x0C,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xF7,
      0xFF,0xFF,0x8E,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
      0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x01,0xE0,0xFF,
      0xFF,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x1F,0x87,0xFF,
      0xFF,0xFF,0xFF,0xE0,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x01,0xFE,0x0F,0xF8,
      0x00,0x3F,0xFF,0xF8,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x0F,0xF8,0x1F,0xE0,
      0x00,0x87,0xF0,0xFC,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x3F,0xE0,0x3F,0xC0,
      0x18,0x70,0xFC,0x7F,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0xFF,0xC0,0x7F,0x80,
      0x07,0x1F,0xFF,0xFD,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x03,0xFF,0x80,0x7F,0x80,
      0x01,0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x0F,0xFF,0x00,0x7F,0xC0,
      0x00,0x03,0xFF,0xFF,0xC0,0x00,0x00,0x00,
      0x00,0x00,0x00,0x1F,0xFF,0x00,0x3F,0xE0,
      0x00,0x00,0x1F,0xFF,0xF0,0x00,0x00,0x00,
      0x00,0x00,0x00,0x7D,0xFF,0x18,0x3F,0xF8,
      0x00,0x00,0x03,0x1F,0xFC,0x00,0x00,0x00,
      0x00,0x00,0x00,0xF3,0xBE,0x70,0x1F,0xFF,
      0x80,0x00,0x00,0x80,0x3C,0x00,0x00,0x00,
      0x00,0x00,0x01,0xE7,0x7F,0xE0,0x47,0xFF,
      0xFE,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,
      0x00,0x00,0x03,0xC6,0x7F,0xE0,0xC0,0xFF,
      0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x07,0x8E,0x7F,0xE0,0xE0,0x0F,
      0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x0F,0x0C,0x3F,0xF0,0x70,0x00,
      0x7F,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,
      0x00,0x00,0x0E,0x0C,0x3F,0xF8,0x7F,0xFF,
      0x9F,0xFF,0xFF,0xE0,0x00,0x00,0x00,0x00,
      0x00,0x00,0x1C,0x0C,0x1F,0xFF,0xFF,0xFD,
      0xCF,0xFF,0xFF,0xF8,0x03,0x00,0x00,0x00,
      0x00,0x00,0x1C,0x04,0x0F,0xFF,0xFF,0xF8,
      0xDF,0xFE,0xFF,0xFC,0x0C,0x00,0x00,0x00,
      0x00,0x00,0x38,0x04,0x03,0x3F,0xFF,0xFD,
      0x3F,0xE6,0xDF,0xFC,0x38,0x00,0x00,0x00,
      0x00,0x00,0x38,0x02,0x00,0x80,0x33,0xFF,
      0xFC,0xE4,0x1F,0xFC,0x73,0x80,0x00,0x00,
      0x00,0x00,0x30,0x00,0x00,0x01,0x8E,0x1F,
      0xE1,0xC0,0x1F,0xFC,0xFF,0xF8,0x00,0x00,
      0x00,0x00,0x30,0x00,0x11,0xE0,0x00,0x00,
      0x01,0x00,0x7F,0xFC,0x9C,0x0C,0x00,0x00,
      0x00,0x00,0x30,0x00,0x00,0xFF,0xFF,0xFF,
      0xC2,0x0C,0x7F,0xFC,0x13,0x80,0x00,0x00,
      0x00,0x00,0x30,0x00,0x00,0x7F,0xFF,0xFF,
      0xF8,0x87,0xFF,0xF8,0xFF,0xC0,0x00,0x00,
      0x00,0x00,0x30,0x00,0x01,0xFF,0xFF,0xFF,
      0xFE,0xC0,0x7F,0xF8,0xF8,0xE0,0x00,0x00,
      0x00,0x00,0x10,0x00,0x1F,0xFF,0xF0,0x3F,
      0xFF,0xFF,0xFF,0xF1,0xF0,0x00,0x00,0x00,
      0x00,0x00,0x10,0x0F,0xFF,0xFF,0xC0,0x1F,
      0xFF,0xFF,0xFF,0xEF,0xFE,0x00,0x00,0x00,
      0x00,0x00,0x10,0x01,0xEF,0xFF,0x88,0x1F,
      0xFF,0xFF,0xFF,0xFE,0xFC,0x00,0x00,0x00,
      0x00,0x00,0x08,0x00,0x0F,0xFF,0x87,0xFE,
      0xFF,0xFF,0xFF,0xFD,0x80,0x00,0x00,0x00,
      0x00,0x00,0x08,0x00,0x1F,0xFF,0x83,0xF9,
      0xC7,0xFF,0xCF,0xE3,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x7F,0xF9,0xE0,0x00,
      0x00,0x00,0x3B,0x80,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x03,0xCF,0xFC,0x00,0x00,
      0x00,0x00,0xEC,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x1F,0xFF,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x23,0xFF,0xFC,0x07,
      0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,
      0xFF,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0xFF,
      0xFF,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x07,0xFF,0xFC,
      0x38,0x1F,0xFF,0xE0,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,
      0x10,0x0F,0xFF,0xC0,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,
      0x00,0x0E,0xFE,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x20,0x38,0x7F,0x80,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x60,0x00,0xFF,0xF0,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x00,
      0xE3,0x01,0xFC,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x03,0xE0,0x07,
      0xCE,0x03,0xF8,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,
      0xFC,0x0F,0xF0,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,
      0xFD,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xFF,
      0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
      0x82,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,
      0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x10,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 setup()
{
  LCDA.clear();                 //清屏
  LCDA.DrawFullScreen(logo0);   //显示龙图案
}
 
void loop()
{
}

效果图:

 

 

0000

posted on 2021-08-16 13:59  深蓝创客  阅读(1029)  评论(0编辑  收藏  举报

导航