找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 287|回复: 1
打印 上一主题 下一主题
收起左侧

[基于STM32]Stduino-传感器拓展(三)LCD12864

[复制链接]
跳转到指定楼层
楼主
本帖最后由 Stduino 于 2020-8-24 12:43 编辑

说明:
带中文字库的LCD128X64是一种具有4/8位并行、2线或3线串行多种接口方式,内部含有国标一级、二级简体中文字库的点阵图形液晶显示模块其显示分辨率为128×64,内置819216*16点汉字,和12816*8ASCII字符集。利用该模块灵活的接口方式和简单、方便的操作指令,可构成全中文人机交互图形界面。可以显示8×416×16点阵的汉字。
LCD12864有多种接线方式,依据数据传输的方式可以分为8位并口、4位并口以及串口接线三种方式。串口接线只需要接一根数据线,节约了端口,因此,我们采用串口接线的方式。

实验目的:
在本例中,我们将利用LCD12864模块输出特定字符,以及让LCD显示图片。

器材:
Stduino UNO/Nano;杜邦线;LCD12864

电路连接:


示例一:
输出特定字符代码:

#include <LCD12864.h>

Lcd12864 lcd12864;
void setup()
{
  // put your setup code here, to run once:

    lcd12864.initial(A2,A1,A0,9);//  EN,RW,RS,PSB
    lcd12864.clean();//清屏
    delay(20);
   
}



void loop()
{
  // put your main code here, to run repeatedly:
    lcd12864.clean();//清屏
   
    lcd12864.ShowString(0,2,"思特诺");//从第0行第2列开始 输出"思特诺"内容
    lcd12864.ShowString(1,2,"Stduino");//从第1行第2列开始 输出"Stduino"内容
    lcd12864.ShowString(3,1,"创建时间:    年");//从第3行第1列开始输出"创建时间:    年"内容
    lcd12864.ShowInt(3,6,2020);//从第3行第6列开始 输出2020内容
    lcd12864.ShowDouble(2,1,123.43);//从第2行第1列开始 输出123.43内容
   
    delay(1000);//延时1000ms

}

示例二:显示128×64像素大小的图画。
首先我们需要利用Krita或者其他绘图软件制作一幅128×64大小的黑白bmp格式的图片。接下来,将其导入到取字模软件,获得Stduino IDE可识别的每一像素点的信息。随后利用DrawFullScreen()方法,将像素点的信息传递给LCD上的每一位地址,即可绘制全屏的像素图。

第一步:在Krita中新建128×64大小的文档,并绘制像素图,保存为BMP文件:

因为今年有千年一遇的新智彗星访问地球,因此画了一幅彗星的图片,嘿嘿,算作补上没有看到的遗憾吧。


第二步,利用取字模软件,将BMP图转化为像素信息:
参数确认:选择C语言以及输出大小(128×64),点击参数确认;


数据保存:载入图片没有问题之后,选择“数据保存”,信息以保存在新的文件当中。


利用Hbuider或者Notepad++等文本编译器打开保存的文件,大括号内的数据就是我们需要的内容:


第三步:编写代码。
把前面的数据复制到一个无符号字符数组中,再利用DrawFullScreen()方法处理即可。
代码如下:
  1. #include <LCD12864.h>

  2. Lcd12864 lcd12864;
  3. unsigned char newWise[]={  //你的图片的数据
  4.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  5.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  9.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  10.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  11.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  12.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  13.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  14.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  15.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  17.       0x00,0x00,0x00,0x00,0x19,0x87,0xBC,0x00,
  18.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  19.       0x00,0x00,0x00,0x01,0x18,0x10,0x00,0x00,
  20.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  21.       0x00,0x00,0x00,0x60,0xC2,0x40,0x00,0x00,
  22.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  23.       0x00,0x00,0x00,0x46,0x00,0x00,0x00,0x00,
  24.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  25.       0x00,0x00,0x29,0x08,0x00,0x00,0x00,0x00,
  26.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  27.       0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
  28.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  29.       0x00,0x08,0xB0,0x00,0x10,0x00,0x00,0x00,
  30.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31.       0x00,0xDC,0x00,0xA4,0x25,0x40,0x00,0x00,
  32.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33.       0x03,0x01,0x12,0x00,0x00,0x08,0x00,0x00,
  34.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  35.       0x3B,0x94,0x00,0x00,0x00,0x00,0x00,0x00,
  36.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
  37.       0x41,0x30,0x00,0x00,0x00,0x00,0x00,0x00,
  38.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,
  39.       0x7E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  40.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6B,
  41.       0xC8,0x00,0x00,0x00,0x00,0x00,0x00,0x04,
  42.       0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x8F,
  43.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  44.       0x04,0x00,0x00,0x00,0x00,0x00,0x05,0x98,
  45.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  46.       0x00,0x00,0x00,0x00,0x00,0x00,0x10,0xF8,
  47.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  48.       0x00,0x00,0x00,0x10,0x00,0x00,0xF7,0xF0,
  49.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  50.       0x00,0x00,0x00,0x00,0x00,0x01,0xFC,0xC0,
  51.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  52.       0x00,0x00,0x00,0x00,0x00,0x01,0xF3,0x00,
  53.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,
  54.       0x00,0x00,0x00,0x00,0x00,0x03,0xFC,0x00,
  55.       0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,
  56.       0x00,0x00,0x00,0x00,0x00,0x07,0xF8,0x00,
  57.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  58.       0x00,0x00,0x00,0x00,0x00,0x07,0xC0,0x00,
  59.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  60.       0x40,0x00,0x00,0x00,0x00,0x07,0x00,0x00,
  61.       0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,
  62.       0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,
  63.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  64.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  65.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,
  66.       0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
  67.       0x00,0x00,0x00,0x00,0x40,0x00,0x02,0x00,
  68.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
  69.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  70.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  71.       0x00,0x00,0x00,0x00,0x80,0x03,0x40,0x01,
  72.       0x40,0x40,0x03,0x00,0x00,0x00,0x00,0x00,
  73.       0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x10,
  74.       0x00,0x01,0x00,0x00,0x00,0x00,0x02,0x00,
  75.       0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,
  76.       0x00,0x40,0x00,0x01,0x00,0x80,0x00,0x00,
  77.       0x04,0x01,0x00,0x40,0xA3,0x80,0x06,0x18,
  78.       0x04,0x00,0x20,0x00,0x08,0x00,0x00,0x04,
  79.       0x00,0x96,0x00,0x20,0x80,0x10,0x80,0x04,
  80.       0x00,0x40,0x01,0x00,0x00,0x08,0x06,0x01,
  81.       0x40,0x00,0x08,0x00,0x00,0x00,0x84,0x00,
  82.       0x80,0x00,0x00,0x18,0x52,0x01,0x00,0x30,
  83.       0x01,0x00,0x60,0x29,0xB9,0xC0,0xC0,0x46,
  84.       0x90,0x00,0x00,0x40,0x00,0x02,0x80,0x02,
  85.       0x09,0x00,0x00,0x52,0x01,0x28,0x8C,0xFA,
  86.       0x40,0xA9,0x08,0x20,0x34,0x00,0x0E,0xE0,
  87.       0x43,0x94,0x73,0x62,0x0D,0xDC,0x0C,0x15,
  88.       0x42,0x00,0x20,0x04,0x00,0x00,0x19,0xB7,
  89.       0x3D,0xE8,0x7F,0x9A,0xEB,0x36,0xF9,0xFC,
  90.       0x00,0x08,0x44,0x00,0x14,0x0C,0xD5,0x7B,
  91.       0xC3,0x99,0x78,0xEB,0x20,0x43,0xBB,0x1A,
  92.       0x14,0xA1,0x80,0x11,0x00,0x02,0x00,0x3F,
  93.       0x81,0x81,0xC2,0x3F,0xAF,0xEF,0x3E,0x18,
  94.       0x31,0x0C,0x88,0xD0,0x98,0xB0,0x40,0x3E,
  95.       0x4D,0xFD,0xE4,0x1F,0xDF,0x3F,0xD8,0x58,
  96.       0xAC,0x00,0x0B,0x01,0x6E,0x88,0x02,0x5C,
  97.       0xFE,0xF9,0xEC,0x0F,0x9F,0x9D,0x70,0x0F,
  98.       0xF2,0x10,0xE4,0x00,0x65,0x00,0x03,0x09,
  99.       0xFE,0x7F,0xC9,0x07,0xBF,0xC7,0xC0,0x47,
  100.       0xCB,0x0C,0x49,0xB4,0x48,0x30,0x01,0xE3,
  101.       0xF1,0x3F,0x89,0x03,0xFF,0xB3,0x80,0x77,
  102.       0xF2,0xED,0xEF,0x6E,0xC3,0xF0,0x0D,0xF9,
  103.       0xC0,0x8E,0x02,0x10,0xFF,0xFF,0x01,0x3B,
  104.       0xE6,0x08,0x71,0xC3,0x00,0xC0,0x0C,0xF0,
  105.       0x00,0xE4,0x00,0x8F,0x1F,0xF8,0x01,0x39,
  106.       0x7E,0x0F,0x70,0x00,0x75,0x00,0x6E,0x62,
  107.       0x00,0x70,0x01,0xCF,0x0F,0xF0,0x03,0x3D,
  108.       0xFF,0xFF,0x4E,0x44,0x86,0x00,0xEF,0x00,
  109.       0x18,0x60,0x03,0xC7,0xE3,0xE0,0x03,0x3E,
  110.       0xE7,0xE8,0xC9,0xE6,0xFC,0x00,0xE7,0x00,
  111.       0x1C,0xA0,0x03,0xE3,0xF1,0x80,0x03,0xBE,
  112.       0x80,0xFB,0x7A,0xF2,0xF0,0x01,0xF8,0x00,
  113.       0x18,0x00,0x01,0xFB,0xF0,0x00,0x01,0x9F,
  114.       0x80,0x3F,0xBC,0xFF,0x80,0x03,0xF0,0x00,
  115.       0x38,0x60,0x01,0xC9,0x98,0x00,0x01,0xCF,
  116.       0x80,0x01,0x3F,0xE0,0x00,0x01,0xE0,0x00,
  117.       0x62,0x70,0x00,0xE7,0xF0,0x00,0x30,0xE7,
  118.       0x00,0x40,0x00,0x00,0x00,0x83,0x60,0x00,
  119.       0xF6,0x26,0x1C,0xD7,0x80,0x00,0x30,0xE7,
  120.       0x00,0x3F,0x10,0x00,0x00,0x00,0x00,0x09,
  121.       0xC7,0x72,0xCE,0x6B,0xE0,0x00,0x18,0x7F,
  122.       0x00,0x47,0xE0,0x00,0x00,0x00,0x00,0x13,
  123.       0x0F,0x04,0x81,0x65,0xF0,0x00,0x0C,0x7F,
  124.       0x00,0x53,0xF4,0x00,0x00,0x00,0x00,0x1E,
  125.       0x07,0x33,0x00,0xF4,0x60,0x00,0x0E,0x7F,
  126.       0x00,0x00,0x7D,0x80,0x00,0x00,0x00,0x3C,
  127.       0x07,0x3D,0x84,0x33,0x00,0x08,0x0E,0x3F,
  128.       0x01,0x00,0x3F,0xF0,0x00,0x08,0x02,0x1C,
  129.       0x47,0x1F,0x07,0x19,0x40,0x18,0x2E,0x3F,
  130.       0x00,0x00,0x07,0xE7,0x80,0x08,0x02,0x10,
  131.       0x44,0x1F,0x03,0xC0,0x00,0x10,0x26,0x3F
  132. };

  133. void setup()
  134. {
  135.   // put your setup code here, to run once:

  136.     lcd12864.initial(A2,A1,A0,9);
  137.     lcd12864.clean();
  138.     delay(20);
  139.    
  140. }



  141. void loop()
  142. {
  143.   // put your main code here, to run repeatedly:
  144.     lcd12864.clean();
  145.     lcd12864.DrawFullScreen(newWise);
  146.     delay(50000);

  147. }
复制代码

效果:



Stduino IDE是一款面向32位处理器快速入门学习的集成开发平台,目前已经支持Arduino_Core_STM32框架,集聚快捷、高效、免费、开源、易得于一身,软件还集成了GDB调试功能。IDE当前支持的功能有:

    GDB调试
    封装库下载安装
    代码自动补全提示
    中英文模式
    UTF-8\GBK编码格式
    代码快速格式化
    SWD\串口程序下载&调试(已验证)
    DFU程序下载方式(待验证)
    USB HID程序下载方式(待验证)
    maple DFU程序下载方式(待验证)
    maple DFU2程序下载方式(待验证)
    MassStorage程序下载方式(待验证)

更多功能细节请点击图片上水印显示的网址进行了解

已经支持的芯片&板型列表:

    Stduino UNO&Nano
    Nucleo 144 boards
    Nucleo 64 boards
    Nucleo 32 boards
    Discovery boards
    Eval boards
    STM32MP1 series coprocessor boards
    Generic STM32F0 boards
    Generic STM32F1 boards
    Generic STM32F3 boards
    Generic STM32F4 boards
    Generic STM32H7 boards
    Generic STM32L0 boards
    3D printer boards
    LoRa boards
    Electronic Speed Controller boards
    Generic flight controllers
    Garatronics boards
    Midatronics boards

更多功能集成正在进行中~

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏2 分享分享 分享淘帖 顶 踩
回复

使用道具 举报

沙发
added 发表于 2020-10-21 11:00 | 只看该作者
arduino与STM32的编程风格差异比较大,如何移植过去呢
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表