今天加了一個LCD12864,IC看說明上是ST7567,結果一頓U8g2,發現兩個問題:工具
一、買的時候不知道是賣家寫的我理解錯了仍是怎麼了,反正是不出漢字的。oop
二、U8g2太大了…………佔了uno的80%還多ui
而後,破罐子破摔吧,換成U8glib小了不少;漢字麼,用圖形表示好了,看了一下U8glib的範例,發現能夠用二進制來表示黑白點,而後弄一小工具,讀16×16點陣,轉化爲二進制就能夠了:spa
const uint8_t wen[] PROGMEM = { 0x00,0x00,0x23,0xF8,0x12,0x08,0x12,0x08,0x83,0xF8,0x42,0x08,0x42,0x08,0x13,0xF8, 0x10,0x00,0x27,0xFC,0xE4,0xA4,0x24,0xA4,0x24,0xA4,0x24,0xA4,0x2F,0xFE,0x00,0x00, };
這是溫字,加PROGMEN關鍵字就不佔運行內存了,因此這樣的字能夠放一些,固然會使得程序佔用的空間大一點,但好處是有針對性,通常咱們也用不了幾個字不是。code
三、用那個聲明?blog
U8glib這個庫在用的時候須要把它註釋掉的若干行u8g定義中的一行註釋掉,而名字也很直觀,可是無奈的是我確實沒找到我這個的聲明,因此只好找一個類似的咯,幾番實驗和觀察代碼下來,發現主要是位置不一樣,因此選了一個庫就這樣用起來就能夠了:內存
U8GLIB_NHD_C12864 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
四、「英漢混合顯示」it
其實說白了,不管什麼東西顯示的時候都是設置點的顏色而已。因此處理的時候都會和上面所說的圖形同樣。至於咱們寫代碼麼,只要算好偏移,分別用兩種方法顯示:漢字用圖形,其餘英文字母數字字符什麼的仍是用原來的方法,原來的方法即直觀又高效:class
void draw(void) { // graphic commands to redraw the complete screen should be placed here u8g.drawBitmapP(0, 0, 2, 16, wen); u8g.drawBitmapP(16, 0, 2, 16, du); u8g.setFont(u8g_font_unifont); u8g.drawStr(32, 14, ": 33.70"); u8g.drawBitmapP(96, 0, 2, 16, sheshidu); u8g.drawBitmapP(0, 16, 2, 16, shi); u8g.drawBitmapP(16, 16, 2, 16, du); u8g.setFont(u8g_font_unifont); u8g.drawStr(32, 30, ": 33.70 %RH"); }
五、所有代碼:map
#include <U8glib.h> U8GLIB_NHD_C12864 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8 const uint8_t wen[] PROGMEM = { 0x00,0x00,0x23,0xF8,0x12,0x08,0x12,0x08,0x83,0xF8,0x42,0x08,0x42,0x08,0x13,0xF8, 0x10,0x00,0x27,0xFC,0xE4,0xA4,0x24,0xA4,0x24,0xA4,0x24,0xA4,0x2F,0xFE,0x00,0x00, }; const uint8_t du[] PROGMEM = { 0x01,0x00,0x00,0x80,0x3F,0xFE,0x22,0x20,0x22,0x20,0x3F,0xFC,0x22,0x20,0x22,0x20, 0x23,0xE0,0x20,0x00,0x2F,0xF0,0x24,0x10,0x42,0x20,0x41,0xC0,0x86,0x30,0x38,0x0E, }; const uint8_t sheshidu[] PROGMEM{ 0x60,0x00,0x91,0xF4,0x96,0x0C,0x6C,0x04,0x08,0x04,0x18,0x00,0x18,0x00,0x18,0x00, 0x18,0x00,0x18,0x00,0x18,0x00,0x08,0x00,0x0C,0x04,0x06,0x08,0x01,0xF0,0x00,0x00, }; const uint8_t shi[] PROGMEM{ 0x00,0x00,0x27,0xF8,0x14,0x08,0x14,0x08,0x87,0xF8,0x44,0x08,0x44,0x08,0x17,0xF8, 0x11,0x20,0x21,0x20,0xE9,0x24,0x25,0x28,0x23,0x30,0x21,0x20,0x2F,0xFE,0x00,0x00, }; void draw(void) { // graphic commands to redraw the complete screen should be placed here u8g.drawBitmapP(0, 0, 2, 16, wen); u8g.drawBitmapP(16, 0, 2, 16, du); u8g.setFont(u8g_font_unifont); u8g.drawStr(32, 14, ": 33.70"); u8g.drawBitmapP(96, 0, 2, 16, sheshidu); u8g.drawBitmapP(0, 16, 2, 16, shi); u8g.drawBitmapP(16, 16, 2, 16, du); u8g.setFont(u8g_font_unifont); u8g.drawStr(32, 30, ": 33.70 %RH"); } void setup(void) { } void loop(void) { // picture loop u8g.firstPage(); do { draw(); } while (u8g.nextPage()); // rebuild the picture after some delay delay(1000); }