TextLCDライブラリから継承すれば簡単にグラフィックモードでキャラクタディスプレイのように動作させることができた。
4x8ドットの極小フォントを使っているので2行25文字表示できます。
フォントには美咲フォントの1バイト文字フォント(misaki_4x8_jisx0201.bdf)を使っています。
ありがとうございました。
// WS0010 2012/3/10 #include "mbed.h" #include "TextLCD.h" class GraphicOLED : public TextLCD { public: GraphicOLED(PinName rs, PinName e, PinName d0, PinName d1, PinName d2, PinName d3, LCDType type = LCD16x2): TextLCD(rs, e, d0, d1, d2, d3, type) { wait_ms(500); // wait 500ms writeCommand(0x00); // 0x0 x 5 writeCommand(0x00); writeCommand(0x02); // function set writeCommand(0x28); // N=1 writeCommand(0x0c); // D=1 display on writeCommand(0x1f); // G/C=1 graphic mode } void g_wrtie(int pat, int x = 0, int y = 0) { writeCommand(0x40+y); // y position writeCommand(0x80+x); // x position writeData(pat); } void cls(int pat = 0x00) { for(int y = 0; y < 2; y++) { for(int x = 0; x < 100; x++) { g_wrtie(pat, x, y); } } } int columns() { return 25; } protected: virtual int _putc(int value); void character(int column, int row, int c); }; int GraphicOLED::_putc(int value) { if (value == '\n') { _column = 0; _row++; if (_row >= rows()) { _row = 0; } } else { character(_column, _row, value); _column++; if (_column >= columns()) { _column = 0; _row++; if (_row >= rows()) { _row = 0; } } } return value; } // misaki_bdf_b11a.tar.gz misaki_4x8_jisx0201.bdf const char misaki_4x8_jisx0201[][4] = { // 20 - 7e {0,0,0,0},{0,47,0,0},{3,0,3,0},{63,18,63,0},{22,63,26,0},{18,8,36,0}, {50,61,42,0},{2,1,0,0},{0,62,65,0},{65,62,0,0},{10,7,10,0},{8,62,8,0}, {0,64,32,0},{8,8,8,0},{0,32,0,0},{16,8,4,0},{28,42,28,0},{36,62,32,0}, {50,42,36,0},{34,42,20,0},{24,20,62,0},{46,42,18,0},{28,42,18,0},{2,58,6,0}, {20,42,20,0},{36,42,28,0},{0,20,0,0},{32,20,0,0},{8,20,34,0},{20,20,20,0}, {34,20,8,0},{2,41,6,0},{18,41,30,0},{62,9,62,0},{63,37,26,0},{30,33,33,0}, {63,33,30,0},{63,37,33,0},{63,5,1,0},{30,33,57,0},{63,8,63,0},{33,63,33,0}, {16,32,31,0},{63,4,59,0},{63,32,32,0},{63,6,63,0},{63,1,62,0},{30,33,30,0}, {63,9,6,0},{30,33,94,0},{63,9,54,0},{34,37,25,0},{1,63,1,0},{63,32,63,0}, {63,16,15,0},{63,24,63,0},{51,12,51,0},{3,60,3,0},{49,45,35,0},{0,127,65,0}, {21,62,21,0},{65,127,0,0},{2,1,2,0},{64,64,64,0},{0,1,2,0},{24,36,60,0}, {63,36,24,0},{24,36,36,0},{24,36,63,0},{24,44,44,0},{4,63,5,0},{72,84,60,0}, {63,4,56,0},{0,61,0,0},{64,61,0,0},{63,8,52,0},{1,63,0,0},{60,28,56,0}, {60,4,56,0},{24,36,24,0},{124,36,24,0},{24,36,124,0},{60,8,4,0},{40,60,20,0}, {4,62,36,0},{60,32,60,0},{60,16,12,0},{60,48,60,0},{36,24,36,0},{76,80,60,0}, {36,52,44,0},{8,54,65,0},{0,127,0,0},{65,54,8,0},{1,1,1,0}}; void GraphicOLED::character(int column, int row, int c) { if (c >= 0x20 && c <= 0x7e) { c -= 0x20; } else { c = 0; } for(int i = 0; i < 4; i++) { g_wrtie(misaki_4x8_jisx0201[c][i], column*4+i, row); } } GraphicOLED oled(p24, p26, p27, p28, p29, p30); // rs, e, d0-d3 int main() { oled.cls(); oled.locate(0, 0); while(1) { for (int c = 0x20; c <= 0x7e; c++) { oled.putc(c); wait(0.2); } } }
---
0 件のコメント:
コメントを投稿