本帖最后由 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 代码如下: - /*********************************************************************
- *
- * // # Update the Adafruit SSD1306 library to make it work
- * // # Description:
- * // # show a simple animation
- *
- * // # Connection:
- * // # SCL -> A5(Uno)/D3(Leonardo)
- * // # SDA -> A4(Uno)/D2(Leonardo)
- * // # RST -> D4
- * // # DC -> GND
- * // # 3.3 -> 3.3v
- * // # g -> GND
- * // #
- *
- * This is an example for OLED based on SSD1306 drivers
- *
- *
- * This example is for a 128x64 size display using I2C to communicate
- * 3 pins are required to interface (2 I2C and one reset)
- *
- * Adafruit invests time and resources providing this open source code,
- * please support Adafruit and open-source hardware by purchasing
- * products from Adafruit!
- *
- * All text above, and the splash screen must be included in any redistribution
- *********************************************************************/
- //本程序作用将多个汉字作为多个图形显示
- #include <Wire.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_SSD1306.h>
- #define OLED_RESET 4
- SSD1306 display(OLED_RESET);
- #define NUMFLAKES 10
- #define XPOS 0
- #define YPOS 1
- #define DELTAY 2
- #define LOGO16_GLCD_HEIGHT 64 //图片高度
- #define LOGO16_GLCD_WIDTH 128 //图片宽度
- static unsigned char PROGMEM bmp1[] =
- {
- /*-- 文字: 极 --*/
- /*-- 楷体_GB231222; 此字体下对应的点阵为:宽x高=30x29 --*/
- /*-- 宽度不是8的倍数,现调整为:宽度x高度=32x29 --*/
- 0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x03,0x80,0x00,0x00,0x03,0x80,0x00,0x00,
- 0x01,0x80,0x00,0x00,0x01,0x80,0x1E,0x00,0x01,0x81,0xFF,0x00,0x01,0x8F,0xFE,0x00,
- 0x01,0xE7,0xCC,0x00,0x0F,0xF1,0xDC,0x00,0x7F,0xE1,0xD8,0x00,0x3F,0x81,0x98,0x00,
- 0x03,0x01,0xB8,0x00,0x07,0xC3,0x9C,0x00,0x07,0xE3,0x0E,0x00,0x0D,0x67,0x0C,0x00,
- 0x1D,0x27,0x9C,0x00,0x1B,0x0E,0xDC,0x00,0x33,0x0C,0x78,0x00,0x63,0x18,0x78,0x00,
- 0xC3,0x38,0x7C,0x00,0x03,0x70,0xFF,0x00,0x03,0x61,0xCF,0xC0,0x03,0x07,0x07,0xF8,
- 0x03,0x0C,0x03,0xF0,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,
- };
- static unsigned char PROGMEM bmp2[] =
- {
- /*-- 文字: 客 --*/
- /*-- 楷体_GB231222; 此字体下对应的点阵为:宽x高=30x29 --*/
- /*-- 宽度不是8的倍数,现调整为:宽度x高度=32x29 --*/
- 0x00,0x00,0x00,0x00,0x00,0x1C,0x00,0x00,0x00,0x0E,0x00,0x00,0x00,0x0F,0x00,0x00,
- 0x00,0x02,0x3C,0x00,0x06,0x1F,0xFF,0x00,0x07,0xFF,0x8F,0x80,0x0F,0x30,0x0F,0x80,
- 0x1E,0x38,0x18,0x00,0x1C,0x39,0x80,0x00,0x08,0x7F,0xE0,0x00,0x00,0xFD,0xE0,0x00,
- 0x00,0xE3,0x80,0x00,0x01,0xFF,0x00,0x00,0x03,0x1F,0x00,0x00,0x00,0x0F,0x00,0x00,
- 0x00,0x3F,0xC0,0x00,0x00,0x79,0xF8,0x00,0x00,0xE0,0x7F,0x00,0x03,0xC0,0xFF,0xF8,
- 0x0F,0xFF,0xEF,0xF8,0x3C,0xFC,0xF3,0x80,0xF0,0xC0,0xE0,0x00,0x80,0xC0,0xE0,0x00,
- 0x00,0xE7,0xE0,0x00,0x00,0x7F,0xE0,0x00,0x00,0x60,0x00,0x00,0x00,0x40,0x00,0x00,
- 0x00,0x00,0x00,0x00,
- };
- static unsigned char PROGMEM bmp3[] =
- {
- /*-- 文字: 工 --*/
- /*-- 楷体_GB231222; 此字体下对应的点阵为:宽x高=30x29 --*/
- /*-- 宽度不是8的倍数,现调整为:宽度x高度=32x29 --*/
- 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,0xF8,0x00,0x00,0x0F,0xFC,0x00,
- 0x01,0xFF,0xF0,0x00,0x01,0xFF,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x06,0x00,0x00,
- 0x00,0x06,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x06,0x00,0x00,
- 0x00,0x06,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x06,0x3F,0x80,
- 0x00,0x7F,0xFF,0xC0,0x3F,0xFF,0xFF,0xE0,0x1F,0xC0,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,
- };
- static unsigned char PROGMEM bmp4[] =
- {
- /*-- 文字: 坊 --*/
- /*-- 楷体_GB231222; 此字体下对应的点阵为:宽x高=30x29 --*/
- /*-- 宽度不是8的倍数,现调整为:宽度x高度=32x29 --*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0xE0,0x00,
- 0x03,0x80,0xF0,0x00,0x03,0x80,0x70,0x00,0x03,0x80,0x38,0x00,0x03,0x80,0x00,0x00,
- 0x03,0x80,0x01,0xC0,0x03,0x80,0x3F,0xE0,0x03,0xE7,0xFF,0xE0,0x0F,0xFF,0xE0,0x00,
- 0x1F,0x88,0xE0,0x00,0x03,0x80,0xE0,0x00,0x03,0x80,0xCE,0x00,0x03,0x11,0xFF,0x00,
- 0x03,0x71,0x87,0x00,0x03,0xC3,0x87,0x00,0x07,0x87,0x0E,0x00,0x7F,0x0E,0x0E,0x00,
- 0x7C,0x0C,0x0E,0x00,0x38,0x38,0x1C,0x00,0x00,0x71,0x9C,0x00,0x00,0xE0,0xF8,0x00,
- 0x01,0x80,0xF0,0x00,0x00,0x00,0x70,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,
- };
- #if (SSD1306_LCDHEIGHT != 64)
- #error("Height incorrect, please fix Adafruit_SSD1306.h!");
- #endif
- void setup() {
- Serial.begin(9600);
- display.begin(SSD1306_SWITCHCAPVCC, 0x3c); // initialize with the I2C addr 0x3C (for the 128x64)
- // init done
- //初始化12864屏幕
- display.display(); // show splashscreen
- //显示闪屏,我理解是12864中固化的图片
- delay(2000);
- display.clearDisplay(); // clears the screen and buffer
- //清屏
- }
- int WIDTH=30; //汉字点陈宽度是30
- int HEIGHT=29; //汉字点陈高度是29
- void aa()//显示汉字
- {
- //由于每个汉字点陈宽度是30,所以它们间距是32比较合适
- display.clearDisplay();
- display.drawBitmap(0, 0, bmp1, WIDTH,HEIGHT, 1);
- display.display();
- //显示汉字“极”
- display.drawBitmap(32, 0, bmp2, WIDTH,HEIGHT, 1);
- display.display();
- //显示汉字“客”
- display.drawBitmap(64, 0, bmp3, WIDTH,HEIGHT, 1);
- display.display();
- //显示汉字“工”
- display.drawBitmap(96, 0, bmp4, WIDTH,HEIGHT, 1);
- display.display();
- //显示汉字“坊"
- delay(1500);
- }
- void loop() {
- aa();//显示汉字
- }
复制代码
本程序显示得不够精简,让人再笑了。如果用数组来表示,就会精简多了。
本人学识不足,目前只能这种写法了。
|