极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 19620|回复: 6

Microduino-OLED以点阵方式显示汉字

[复制链接]
发表于 2013-8-3 20:43:29 | 显示全部楼层 |阅读模式
本帖最后由 tom 于 2013-8-6 23:22 编辑

以点阵方式驱动显示汉字,实际上把每个汉字作为一个图形显示。

如是嫌一个个显示麻烦,可以把要显示的汉字画在一个图片中,一个语句就可显示出来。
参阅链接http://www.geek-workshop.com/thread-5529-1-1.html

Arduino IDE V1.01
专用版本的库Adafruit Adafruit-gfx

以张老师的SSD1306 I2C 12864显示器为例。

为了显示汉字,用字模提取 V2.0输出 图形字模。

1.输入汉字 “极客工坊”  s1.jpg


2 按回车结束输入 s2.jpg



3.选择C51格式,生成字模代码 s03.jpg


4.保存成文件
在基本操作中选择,保存成点阵数据

5.将数据拷入Arduino 程序文件中,如下
为防止变形,原始宽度是30,所以程序中图片的宽度也是30

Arduino 代码如下:
  1. /*********************************************************************
  2. *
  3. * // # Update the Adafruit SSD1306 library to make it work
  4. * // # Description:
  5. * // #                 show a simple animation
  6. *
  7. * // # Connection:
  8. * // #        SCL  -> A5(Uno)/D3(Leonardo)
  9. * // #        SDA  -> A4(Uno)/D2(Leonardo)
  10. * // #        RST  -> D4
  11. * // #        DC  -> GND
  12. * // #        3.3  -> 3.3v
  13. * // #        g  -> GND
  14. * // #
  15. *
  16. * This is an example for  OLED based on SSD1306 drivers
  17. *
  18. *
  19. * This example is for a 128x64 size display using I2C to communicate
  20. * 3 pins are required to interface (2 I2C and one reset)
  21. *
  22. * Adafruit invests time and resources providing this open source code,
  23. * please support Adafruit and open-source hardware by purchasing
  24. * products from Adafruit!
  25. *
  26. * All text above, and the splash screen must be included in any redistribution
  27. *********************************************************************/
  28. //本程序作用将多个汉字作为多个图形显示
  29. #include <Wire.h>
  30. #include <Adafruit_GFX.h>
  31. #include <Adafruit_SSD1306.h>

  32. #define OLED_RESET 4
  33. SSD1306 display(OLED_RESET);

  34. #define NUMFLAKES 10
  35. #define XPOS 0
  36. #define YPOS 1
  37. #define DELTAY 2


  38. #define LOGO16_GLCD_HEIGHT 64 //图片高度
  39. #define LOGO16_GLCD_WIDTH  128 //图片宽度
  40. static unsigned char PROGMEM bmp1[] =
  41. {
  42.   /*--  文字:  极  --*/
  43.   /*--  楷体_GB231222;  此字体下对应的点阵为:宽x高=30x29   --*/
  44.   /*--  宽度不是8的倍数,现调整为:宽度x高度=32x29  --*/
  45.   0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x03,0x80,0x00,0x00,0x03,0x80,0x00,0x00,
  46.   0x01,0x80,0x00,0x00,0x01,0x80,0x1E,0x00,0x01,0x81,0xFF,0x00,0x01,0x8F,0xFE,0x00,
  47.   0x01,0xE7,0xCC,0x00,0x0F,0xF1,0xDC,0x00,0x7F,0xE1,0xD8,0x00,0x3F,0x81,0x98,0x00,
  48.   0x03,0x01,0xB8,0x00,0x07,0xC3,0x9C,0x00,0x07,0xE3,0x0E,0x00,0x0D,0x67,0x0C,0x00,
  49.   0x1D,0x27,0x9C,0x00,0x1B,0x0E,0xDC,0x00,0x33,0x0C,0x78,0x00,0x63,0x18,0x78,0x00,
  50.   0xC3,0x38,0x7C,0x00,0x03,0x70,0xFF,0x00,0x03,0x61,0xCF,0xC0,0x03,0x07,0x07,0xF8,
  51.   0x03,0x0C,0x03,0xF0,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  52.   0x00,0x00,0x00,0x00,
  53. };

  54. static unsigned char PROGMEM bmp2[] =
  55. {
  56.   /*--  文字:  客  --*/
  57.   /*--  楷体_GB231222;  此字体下对应的点阵为:宽x高=30x29   --*/
  58.   /*--  宽度不是8的倍数,现调整为:宽度x高度=32x29  --*/
  59.   0x00,0x00,0x00,0x00,0x00,0x1C,0x00,0x00,0x00,0x0E,0x00,0x00,0x00,0x0F,0x00,0x00,
  60.   0x00,0x02,0x3C,0x00,0x06,0x1F,0xFF,0x00,0x07,0xFF,0x8F,0x80,0x0F,0x30,0x0F,0x80,
  61.   0x1E,0x38,0x18,0x00,0x1C,0x39,0x80,0x00,0x08,0x7F,0xE0,0x00,0x00,0xFD,0xE0,0x00,
  62.   0x00,0xE3,0x80,0x00,0x01,0xFF,0x00,0x00,0x03,0x1F,0x00,0x00,0x00,0x0F,0x00,0x00,
  63.   0x00,0x3F,0xC0,0x00,0x00,0x79,0xF8,0x00,0x00,0xE0,0x7F,0x00,0x03,0xC0,0xFF,0xF8,
  64.   0x0F,0xFF,0xEF,0xF8,0x3C,0xFC,0xF3,0x80,0xF0,0xC0,0xE0,0x00,0x80,0xC0,0xE0,0x00,
  65.   0x00,0xE7,0xE0,0x00,0x00,0x7F,0xE0,0x00,0x00,0x60,0x00,0x00,0x00,0x40,0x00,0x00,
  66.   0x00,0x00,0x00,0x00,
  67. };

  68. static unsigned char PROGMEM bmp3[] =
  69. {
  70.   /*--  文字:  工  --*/
  71.   /*--  楷体_GB231222;  此字体下对应的点阵为:宽x高=30x29   --*/
  72.   /*--  宽度不是8的倍数,现调整为:宽度x高度=32x29  --*/
  73.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  74.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x00,0x00,0x0F,0xFC,0x00,
  75.   0x01,0xFF,0xF0,0x00,0x01,0xFF,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x06,0x00,0x00,
  76.   0x00,0x06,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x06,0x00,0x00,
  77.   0x00,0x06,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x06,0x3F,0x80,
  78.   0x00,0x7F,0xFF,0xC0,0x3F,0xFF,0xFF,0xE0,0x1F,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,
  79.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  80.   0x00,0x00,0x00,0x00,  
  81. };

  82. static unsigned char PROGMEM bmp4[] =
  83. {
  84.   /*--  文字:  坊  --*/
  85.   /*--  楷体_GB231222;  此字体下对应的点阵为:宽x高=30x29   --*/
  86.   /*--  宽度不是8的倍数,现调整为:宽度x高度=32x29  --*/
  87.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0xE0,0x00,
  88.   0x03,0x80,0xF0,0x00,0x03,0x80,0x70,0x00,0x03,0x80,0x38,0x00,0x03,0x80,0x00,0x00,
  89.   0x03,0x80,0x01,0xC0,0x03,0x80,0x3F,0xE0,0x03,0xE7,0xFF,0xE0,0x0F,0xFF,0xE0,0x00,
  90.   0x1F,0x88,0xE0,0x00,0x03,0x80,0xE0,0x00,0x03,0x80,0xCE,0x00,0x03,0x11,0xFF,0x00,
  91.   0x03,0x71,0x87,0x00,0x03,0xC3,0x87,0x00,0x07,0x87,0x0E,0x00,0x7F,0x0E,0x0E,0x00,
  92.   0x7C,0x0C,0x0E,0x00,0x38,0x38,0x1C,0x00,0x00,0x71,0x9C,0x00,0x00,0xE0,0xF8,0x00,
  93.   0x01,0x80,0xF0,0x00,0x00,0x00,0x70,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,
  94.   0x00,0x00,0x00,0x00,  
  95. };

  96. #if (SSD1306_LCDHEIGHT != 64)
  97. #error("Height incorrect, please fix Adafruit_SSD1306.h!");
  98. #endif

  99. void setup()   {               
  100.   Serial.begin(9600);

  101.   display.begin(SSD1306_SWITCHCAPVCC, 0x3c);  // initialize with the I2C addr 0x3C (for the 128x64)
  102.   // init done
  103.   //初始化12864屏幕
  104.   display.display(); // show splashscreen
  105.   //显示闪屏,我理解是12864中固化的图片

  106.   delay(2000);
  107.   display.clearDisplay();   // clears the screen and buffer
  108.   //清屏



  109. }

  110. int WIDTH=30; //汉字点陈宽度是30
  111. int HEIGHT=29; //汉字点陈高度是29
  112. void aa()//显示汉字
  113. {
  114.   //由于每个汉字点陈宽度是30,所以它们间距是32比较合适
  115.   display.clearDisplay();  
  116.   display.drawBitmap(0, 0,  bmp1, WIDTH,HEIGHT, 1);   
  117.   display.display();
  118.   //显示汉字“极”
  119.   display.drawBitmap(32, 0,  bmp2, WIDTH,HEIGHT, 1);     
  120.   display.display();
  121.   //显示汉字“客”
  122.   display.drawBitmap(64, 0,  bmp3, WIDTH,HEIGHT, 1);     
  123.   display.display();  
  124.   //显示汉字“工”

  125.   display.drawBitmap(96, 0,  bmp4, WIDTH,HEIGHT, 1);     
  126.   display.display();  
  127.   //显示汉字“坊"
  128.   delay(1500);  
  129. }

  130. void loop() {
  131.   aa();//显示汉字

  132. }


复制代码

本程序显示得不够精简,让人再笑了。如果用数组来表示,就会精简多了。
本人学识不足,目前只能这种写法了。
s1.jpg
s2.jpg
s3.jpg

评分

参与人数 1 +3 收起 理由
Microduino + 3

查看全部评分

回复

使用道具 举报

发表于 2014-1-9 01:21:59 | 显示全部楼层
E:\Arduino\libraries\Robot_Control\ArduinoRobot.cpp: In constructor 'RobotControl::RobotControl()':
E:\Arduino\libraries\Robot_Control\ArduinoRobot.cpp:8: error: 'LCD_CS' was not declared in this scope
E:\Arduino\libraries\Robot_Control\ArduinoRobot.cpp:8: error: 'DC_LCD' was not declared in this scope
E:\Arduino\libraries\Robot_Control\ArduinoRobot.cpp:8: error: 'RST_LCD' was not declared in this scope
E:\Arduino\libraries\Robot_Control\ArduinoRobot.cpp: In member function 'void RobotControl::begin()':
E:\Arduino\libraries\Robot_Control\ArduinoRobot.cpp:18: error: 'MUXA' was not declared in this scope
E:\Arduino\libraries\Robot_Control\ArduinoRobot.cpp:18: error: 'MUXB' was not declared in this scope
E:\Arduino\libraries\Robot_Control\ArduinoRobot.cpp:18: error: 'MUXC' was not declared in this scope
E:\Arduino\libraries\Robot_Control\ArduinoRobot.cpp:18: error: 'MUXD' was not declared in this scope
E:\Arduino\libraries\Robot_Control\ArduinoRobot.cpp:19: error: 'MUX_IN' was not declared in this scope
E:\Arduino\libraries\Robot_Control\ArduinoRobot.cpp:22: error: 'BUZZ' was not declared in this scope
回复 支持 反对

使用道具 举报

发表于 2014-3-4 15:03:47 | 显示全部楼层
移动大金条 发表于 2014-1-9 01:21
E:\Arduino\libraries\Robot_Control\ArduinoRobot.cpp: In constructor 'RobotControl::RobotControl()':
...

也遇到这个问题,求解答,
回复 支持 反对

使用道具 举报

发表于 2014-3-24 11:32:10 | 显示全部楼层
求解,这个程序显示汉字是一直在刷新的,怎么让汉字静止不刷新啊?
回复 支持 反对

使用道具 举报

发表于 2016-12-16 11:03:12 | 显示全部楼层
求取模软件
回复 支持 反对

使用道具 举报

发表于 2017-7-15 21:02:58 | 显示全部楼层
学到了很多,谢谢楼主分享
回复 支持 反对

使用道具 举报

发表于 2020-4-10 22:38:45 | 显示全部楼层
先收下,改日再試
回复 支持 反对

使用道具 举报

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

本版积分规则

Archiver|联系我们|极客工坊 ( 浙ICP备09023225号 )

GMT+8, 2020-10-2 04:19 , Processed in 0.053237 second(s), 29 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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