关于u8g2lib显示汉字的问题-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 8165|回复: 2

[未解决] 关于u8g2lib显示汉字的问题

[复制链接]
发表于 2018-10-21 13:05 | 显示全部楼层 |阅读模式
本帖最后由 feierdog 于 2018-10-21 13:22 编辑

这是我用 arduion UNO R3 、openjump mini12864和u8g2lib做的一个小实验,
微信图片_20181021125045.jpg

文字和符号全部用的是书中提到的软件图片模式取的模,数值是读的dht11模块的(问题在代码的后面)
360软件小助手截图20181021125514.jpg
代码:(拼凑的,见笑)

[mw_shl_code=cpp,true]
#define DHT11PIN 2 // Data链接数字针脚2

#include <U8glib.h>
#include <dht11.h>

//创建一个u8g(LCD12864)对象
U8GLIB_MINI12864 u8g(13, 11, 10, 9, 8);  // U8GLIB_PCD8544(sck/sclk, mosi/sdin, ce/sce, d0/dc, reset)
//创建一个DHT11对象
dht11 DHT11;
#define DHT11PIN 2
#define w1 96
#define h1 16
#define w2 32
#define h2 24
#define w3 16
#define h3 24
#define w4 32
#define h4 28
#define w5 128
#define h5 12
static unsigned char bitmap1[] U8G_PROGMEM = {0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x10,0x01,0xC4,0x1F,0xE4,0x1F,
0x00,0x01,0xF8,0x0F,0xFC,0x1F,0x10,0x12,0x48,0x10,0x28,0x10,0xFC,0x7F,0x08,0x08,
0x00,0x00,0x50,0x12,0x48,0x10,0x28,0x10,0x44,0x04,0x08,0x08,0x00,0x00,0x48,0x10,
0xC1,0x1F,0xE1,0x1F,0x44,0x04,0xF8,0x0F,0x00,0x00,0x48,0x10,0x42,0x10,0x22,0x10,
0xFC,0x3F,0x08,0x08,0x00,0x00,0x8C,0x08,0x42,0x10,0x22,0x10,0x44,0x04,0x08,0x08,
0xFF,0x7F,0x8C,0x08,0xC8,0x1F,0xE8,0x1F,0x44,0x04,0xF8,0x0F,0x80,0x00,0x8A,0x08,
0x08,0x00,0x88,0x04,0xC4,0x07,0x20,0x02,0x80,0x00,0x09,0x05,0xE4,0x3F,0x84,0x04,
0x04,0x00,0x22,0x22,0x88,0x08,0x08,0x05,0x27,0x25,0x97,0x24,0xF4,0x0F,0x24,0x22,
0x88,0x10,0x08,0x02,0x24,0x25,0xA4,0x14,0x24,0x08,0x28,0x12,0x84,0x20,0x08,0x02,
0x24,0x25,0xC4,0x0C,0x42,0x04,0x28,0x0A,0x82,0x40,0x08,0x05,0x24,0x25,0x84,0x04,
0x82,0x03,0x20,0x02,0x81,0x40,0x88,0x08,0xF4,0x7F,0xF4,0x7F,0x61,0x0C,0xFF,0x7F,
0xA0,0x00,0x48,0x10,0x00,0x00,0x00,0x00,0x1C,0x70,0x00,0x00,0x40,0x00,0x28,0x60,
};//显示汉字“温湿度显示仪”

static unsigned char bitmap2[] U8G_PROGMEM = {0xF3,0x07,0x18,0x00,0x14,0x84,0xFF,0x01,0xF0,0x87,0x44,0x00,0x13,0x84,0xFE,0x61,
0xF6,0x87,0x44,0x60,0x10,0x84,0x7C,0x00,0x06,0x80,0x00,0x00,0xF2,0x87,0xFE,0x61,
0x52,0x85,0xCC,0x60,0x53,0xC5,0x78,0x00,0xFB,0x4F,0xCF,0x03,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xF3,0x07,0x18,0x00,0x16,0x84,0xFF,0x01,0xF0,0x87,0x44,0x00,
0x13,0x84,0xFE,0x61,0xF6,0x87,0x44,0x60,0x40,0x81,0x7C,0x00,0x58,0x8D,0x00,0x00,
0x76,0x87,0xFE,0x61,0x62,0x83,0xCC,0x60,0x43,0xC1,0x78,0x00,0xF9,0x4F,0xCF,0x03,};
//显示汉字“温度:湿度:”

static unsigned char bitmap3[] U8G_PROGMEM = {0x00,0x00,0x0C,0x1F,0x92,0x00,0x52,0x00,0x4C,0x00,0x40,0x00,0x40,0x00,0x40,0x00,
0xC0,0x00,0x80,0x00,0x00,0x1F,0x00,0x00,0x00,0x00,0x00,0x08,0x18,0x04,0x24,0x02,
0x24,0x01,0x98,0x00,0x40,0x00,0x20,0x00,0x10,0x06,0x08,0x09,0x04,0x09,0x02,0x06,};
//显示符号“℃ % ”

static unsigned char bitmap4[] U8G_PROGMEM = {0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x00,0x80,0x71,0x0C,0xE0,0x80,0x71,0x1C,0xC0,0x80,
0xF1,0xFF,0xC0,0x81,0xF9,0x36,0xB8,0x8F,0x71,0x3B,0x3C,0x8C,0xF1,0x1F,0x3E,0x9C,
0x79,0x6E,0x3E,0x98,0x79,0x37,0x3E,0x9E,0xF1,0x1D,0x3E,0x8E,0x71,0x7F,0x30,0x86,
0xF1,0xE3,0xF0,0x87,0x01,0x00,0x00,0x80,0x01,0x00,0x00,0x80,0xE1,0x39,0x1C,0x83,
0x79,0x3F,0x1C,0x83,0x71,0x3E,0xFE,0x9F,0xF9,0x3D,0x1C,0x83,0x71,0x3B,0xFC,0x9F,
0xF1,0x3E,0xFC,0x8C,0xF9,0x39,0xDF,0x8E,0x79,0xFC,0x9C,0x87,0xF9,0x3F,0x9C,0x83,
0x71,0x38,0xDC,0x8F,0x71,0x38,0x7E,0x9C,0x01,0x00,0x00,0x80,0xFF,0xFF,0xFF,0xFF
,};
//显示汉字“核心科技”

static unsigned char bitmap5[] U8G_PROGMEM = {
0x7C,0x3E,0x7C,0x3E,0x7C,0x3E,0x7C,0x3E,0x7C,0x3E,0x7C,0x3E,0x7C,0x3E,0x7C,0x3E,
0xFE,0x7F,0xFE,0x7F,0xFE,0x7F,0xFE,0x7F,0xFE,0x7F,0xFE,0x7F,0xFE,0x7F,0xFE,0x7F,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFE,0x7F,0xFE,0x7F,0xFE,0x7F,0xFE,0x7F,0xFE,0x7F,0xFE,0x7F,0xFE,0x7F,0xFE,0x7F,
0xFC,0x7F,0xFC,0x7F,0xFC,0x7F,0xFC,0x7F,0xFC,0x7F,0xFC,0x7F,0xFC,0x7F,0xFC,0x7F,
0xFC,0x3F,0xFC,0x3F,0xFC,0x3F,0xFC,0x3F,0xFC,0x3F,0xFC,0x3F,0xFC,0x3F,0xFC,0x3F,
0xF8,0x1F,0xF8,0x1F,0xF8,0x1F,0xF8,0x1F,0xF8,0x1F,0xF8,0x1F,0xF8,0x1F,0xF8,0x1F,
0xF0,0x0F,0xF0,0x0F,0xF0,0x0F,0xF0,0x0F,0xF0,0x0F,0xF0,0x0F,0xF0,0x0F,0xF0,0x0F,
0xE0,0x07,0xE0,0x07,0xE0,0x07,0xE0,0x07,0xE0,0x07,0xE0,0x07,0xE0,0x07,0xE0,0x07,
0x80,0x03,0x80,0x03,0x80,0x03,0x80,0x03,0x80,0x03,0x80,0x03,0x80,0x03,0x80,0x03,
0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01
,};
//显示符号爱心

void draw(void) {
  u8g.drawXBMP(16, 0, w1, h1, bitmap1);
  u8g.drawXBMP(1, 16, w2, h2, bitmap2);
   u8g.drawXBMP(50, 16, w3, h3, bitmap3);
    u8g.drawXBMP(80, 16, w4, h4, bitmap4);
    u8g.drawXBMP(0, 50, w5, h5, bitmap5);
   u8g.setFont(u8g_font_unifont);
   //u8g.drawStr( 0, 27, "HUMI(%) :");
   u8g.setPrintPos(35, 27);
u8g.print(DHT11.temperature);
// u8g.setPrintPos(0, 40);
// u8g.print("TEMP(oC):");
  u8g.setPrintPos(35, 40);
  u8g.print(DHT11.humidity);
//u8g.setRot180();

}

void setup()
{  
  Serial.begin(9600);//串口波特率
  Serial.println("DHT11 TEST PROGRAM ");
  Serial.print("LIBRARY VERSION: ");
  Serial.println(DHT11LIB_VERSION);
  Serial.println();
}

void loop()
{
  Serial.println("\n");

  int chk = DHT11.read(DHT11PIN);

  Serial.print("Read sensor: ");
  switch (chk)
  {
    case DHTLIB_OK:
                Serial.println("OK");
                break;
    case DHTLIB_ERROR_CHECKSUM:
                Serial.println("Checksum error");
                break;
    case DHTLIB_ERROR_TIMEOUT:
                Serial.println("Time out error");
                break;
    default:
                Serial.println("Unknown error");
                break;
  }

  Serial.print("Humidity (%): ");
  Serial.println((float)DHT11.humidity, 2);

  Serial.print("Temperature (oC): ");
  Serial.println((float)DHT11.temperature, 2);


  u8g.firstPage();  
  do {
    draw();
  } while( u8g.nextPage() );

  delay(1000);
}[/mw_shl_code]

现在有两个问题:
1、我将输入到串口监视器的那段代码去掉后,屏幕上温湿度均显示为0;
2、字模提取软件有两种模式,一种是图片模式,一种的文字模式,取到的代码不一样,我将文字模式下取到的代码直接粘贴到原代码内覆盖掉,出来的字要么是乱码,要么是竖着的(温湿度显示仪这几个字)!

以上两个问题如何解决,请高手支招,谢谢!




发表于 2018-10-22 09:00 | 显示全部楼层
发表于 2021-4-18 05:42 | 显示全部楼层
求救,用你贴出来的字模数据,就能正确显示,但是我自己用字模软件生成的数据,一样的文字,生成出来的数据总是和你发的不一样,能把你字模软件的配置发一下吗?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-29 07:34 , Processed in 0.080911 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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