「デカ文字温度計」(128x32)LPC812とSSD1306とS-5851A


参考


https://qiita.com/caa45040/items/66b5776e5222c0c47f52



x めんどいので過去ログを見よ

目的
OLEDのテスト
32x32の文字を4文字表示する


![o_cop347.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/dcfdf115-9871-f382-e399-642ddae84cfb.jpeg)




```c++



//oled_5851_DEC0_32x32_128x32_812_1

#include "mbed.h"
#include "SSD1308.h"

//5851
#define ADDR        (0x90) //  address

//i2c initialization
//       SDA    SCL
I2C i2c(P0_10, P0_11); //812

// ビットマップデータ
char databytes1[] =
    {



  0xff, 0xf0, 0x0f, 0xff, 0xff, 0xe1, 0x87, 0xff, 0xff, 0xcf, 0xf3, 0xff, 0xff, 0x9f, 0xf9, 0xff, 
  0xff, 0x3f, 0xfc, 0xff, 0xff, 0x3f, 0xfc, 0xff, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 
  0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 
  0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 
  0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 
  0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 
  0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xff, 0x3f, 0xfe, 0x7f, 
  0xff, 0x3f, 0xfc, 0xff, 0xff, 0x8f, 0xf8, 0xff, 0xff, 0xc3, 0xe1, 0xff, 0xff, 0xe0, 0x03, 0xff, 
  0xff, 0xf0, 0x3f, 0xff, 0xff, 0xe0, 0x3f, 0xff, 0xff, 0xce, 0x7f, 0xff, 0xff, 0x9e, 0x7f, 0xff, 
  0xff, 0xbe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 
  0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 
  0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 
  0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 
  0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 
  0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 
  0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xe0, 0x07, 0xff, 0xff, 0xc0, 0x03, 0xff, 
  0xff, 0xf0, 0x0f, 0xff, 0xff, 0xe1, 0x87, 0xff, 0xff, 0xcf, 0xf3, 0xff, 0xff, 0x9f, 0xf9, 0xff, 
  0xff, 0x3f, 0xfc, 0xff, 0xff, 0x3f, 0xfc, 0xff, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 
  0xff, 0x7f, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0xff, 
  0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xff, 0xf3, 0xff, 0xff, 0xf8, 0x07, 0xff, 
  0xff, 0xf0, 0x0f, 0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xcf, 0xff, 0xff, 0xff, 0x9f, 0xff, 0xff, 
  0xff, 0x3f, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 
  0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 
  0xfe, 0x7f, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0x1f, 0xe0, 0x7f, 0xff, 0x80, 0x00, 0x7f, 
  0xff, 0xf0, 0x0f, 0xff, 0xff, 0xe1, 0x87, 0xff, 0xff, 0xcf, 0xf3, 0xff, 0xff, 0x9f, 0xf9, 0xff, 
  0xff, 0x3f, 0xfc, 0xff, 0xff, 0x3f, 0xfc, 0xff, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 
  0xfe, 0x7f, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0xff, 
  0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xff, 0xf3, 0xff, 0xff, 0xf0, 0x07, 0xff, 
  0xff, 0xf0, 0x07, 0xff, 0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xff, 0xfc, 0xff, 
  0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0x3f, 
  0xff, 0xff, 0xff, 0x3f, 0xfe, 0x7f, 0xff, 0x3f, 0xfe, 0x7f, 0xff, 0x3f, 0xff, 0x3f, 0xff, 0x7f, 
  0xff, 0x3f, 0xfe, 0x7f, 0xff, 0x8f, 0xfc, 0xff, 0xff, 0xc3, 0xe1, 0xff, 0xff, 0xe0, 0x03, 0xff, 
  0xff, 0xff, 0xe7, 0xff, 0xff, 0xff, 0xc3, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0x8f, 0xff, 
  0xff, 0xff, 0x9f, 0xff, 0xff, 0xfe, 0x1f, 0xff, 0xff, 0xfc, 0x3f, 0xff, 0xff, 0xfc, 0xff, 0xff, 
  0xff, 0xf0, 0xff, 0xff, 0xff, 0xe1, 0x9f, 0xff, 0xff, 0xc3, 0x9f, 0xff, 0xff, 0x87, 0x9f, 0xff, 
  0xff, 0x1f, 0x9f, 0xff, 0xff, 0x3f, 0x9f, 0xff, 0xfe, 0x3f, 0x9f, 0xff, 0xfe, 0x7f, 0x9f, 0xff, 
  0xfe, 0x7f, 0x1f, 0x7f, 0xfe, 0x00, 0x00, 0x7f, 0xfe, 0x00, 0x00, 0x7f, 0xff, 0xff, 0x9f, 0xff, 
  0xff, 0xff, 0x9f, 0xff, 0xff, 0xff, 0x9f, 0xff, 0xff, 0xff, 0x9f, 0xff, 0xff, 0xff, 0x9f, 0xff, 
  0xff, 0xff, 0x9f, 0xff, 0xff, 0xff, 0x9f, 0xff, 0xff, 0xff, 0x9f, 0xff, 0xff, 0xff, 0x9f, 0xff, 
  0xff, 0xff, 0x9f, 0xff, 0xff, 0xff, 0x9f, 0xff, 0xff, 0xff, 0x9f, 0xff, 0xff, 0xff, 0x9f, 0xff, 
  0xff, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x7f, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 
  0xfe, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 
  0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x3f, 0xff, 0xff, 
  0xfe, 0x3f, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, 0xff, 0x83, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xff, 
  0xff, 0xf2, 0x07, 0xff, 0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xff, 0xfc, 0xff, 
  0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0x3f, 
  0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0x7f, 
  0xff, 0x3f, 0xfe, 0x7f, 0xff, 0x8f, 0xfc, 0xff, 0xff, 0xc3, 0xe1, 0xff, 0xff, 0xe0, 0x03, 0xff, 
  0xff, 0xf0, 0x0f, 0xff, 0xff, 0xe1, 0x87, 0xff, 0xff, 0xcf, 0xf3, 0xff, 0xff, 0x9f, 0xf9, 0xff, 
  0xff, 0x3f, 0xfc, 0xff, 0xff, 0x3f, 0xfc, 0xff, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 
  0xfe, 0x7f, 0xfe, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 
  0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x1f, 0xff, 0xff, 0xfe, 0x00, 0x07, 0xff, 
  0xfe, 0x00, 0x03, 0xff, 0xfe, 0x1f, 0xf3, 0xff, 0xfe, 0x3f, 0xf9, 0xff, 0xfe, 0x7f, 0xfc, 0xff, 
  0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xff, 0x3f, 0xfe, 0x7f, 0xff, 0x3f, 
  0xfe, 0x7f, 0xff, 0x3f, 0xfe, 0x7f, 0xff, 0x3f, 0xfe, 0x7f, 0xff, 0x3f, 0xff, 0x3f, 0xff, 0x7f, 
  0xff, 0x3f, 0xfe, 0x7f, 0xff, 0x8f, 0xfc, 0xff, 0xff, 0xc3, 0xe1, 0xff, 0xff, 0xe0, 0x03, 0xff, 
  0xfc, 0x00, 0x00, 0xff, 0xfc, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xfe, 0x3f, 0xff, 0xff, 0xfc, 0x7f, 
  0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xe3, 0xff, 
  0xff, 0xff, 0xc3, 0xff, 0xff, 0xff, 0xcf, 0xff, 0xff, 0xff, 0x9f, 0xff, 0xff, 0xff, 0x3f, 0xff, 
  0xff, 0xfe, 0x3f, 0xff, 0xff, 0xfc, 0x7f, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xf0, 0xff, 0xff, 
  0xff, 0xe1, 0xff, 0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xc3, 0xff, 0xff, 0xff, 0x8f, 0xff, 0xff, 
  0xff, 0x0f, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, 0xfe, 0x1f, 0xff, 0xff, 0xfe, 0x1f, 0xff, 0xff, 
  0xfe, 0x1f, 0xff, 0xff, 0xfe, 0x3f, 0xff, 0xff, 0xfe, 0x3f, 0xff, 0xff, 0xfe, 0x3f, 0xff, 0xff, 
  0xfe, 0x3f, 0xff, 0xff, 0xfe, 0x3f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 
  0xff, 0xf0, 0x0f, 0xff, 0xff, 0xe1, 0x87, 0xff, 0xff, 0xcf, 0xf3, 0xff, 0xff, 0x9f, 0xf9, 0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  0xff, 0xf0, 0x06, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 
  0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfe, 0x7f, 
  0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xfc, 0x7f, 0xff, 0xff, 0xfc, 0x7f, 0xff, 0xff, 0xfc, 0x7f, 
  0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xc1, 0xff, 0xff, 0xff, 0x03, 0xff, 0xff, 0xfe, 0x1f, 0xff



  
  
    };

int gop[8][8] = {{0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0},
                 {0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0},

                 {0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0},
                 {0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}};

unsigned char bbh[]
    // 1122
    = {0, 0, 0, 0, 0, 0, 0, 0};


void p_m270(char ttt[]) {
  char cc;
  for (int ii = 0; ii < 8; ii++) {
    cc = ttt[ii];
    gop[ii][7] = cc & 0x1;    cc = cc >> 1;
    gop[ii][6] = cc & 0x1;    cc = cc >> 1;
    gop[ii][5] = cc & 0x1;    cc = cc >> 1;
    gop[ii][4] = cc & 0x1;    cc = cc >> 1;

    gop[ii][3] = cc & 0x1;    cc = cc >> 1;
    gop[ii][2] = cc & 0x1;    cc = cc >> 1;
    gop[ii][1] = cc & 0x1;    cc = cc >> 1;
    gop[ii][0] = cc & 0x1;
  } // for
} // p_m270


void p_out(unsigned char ttt[]) {
  char cc;
  for (int ii = 0; ii < 8; ii++) {
    cc = 0;
    cc = cc + (gop[0][ii] * 1);
    cc = cc + (gop[1][ii] * 2);
    cc = cc + (gop[2][ii] * 4);
    cc = cc + (gop[3][ii] * 8);
    cc = cc + (gop[4][ii] * 16);
    cc = cc + (gop[5][ii] * 32);
    cc = cc + (gop[6][ii] * 64);
    cc = cc + (gop[7][ii] * 128);
    ttt[ii] = cc;
  } // for
} // p_out


//32x64
void bitmap32x64( SSD1308 *oled, uint8_t * databytesB,   int p_row ,  int p_col ) {

  char  databytes9[4*64];

  int jj2=0;

  for(int ii=0;ii<32;ii++) {

   databytes9[(ii*8)+0] = databytesB[jj2];jj2=jj2+1;
   
   databytes9[(ii*8)+1] = databytesB[jj2];jj2=jj2+1;

   databytes9[(ii*8)+2] = databytesB[jj2];jj2=jj2+1;

   databytes9[(ii*8)+3] = databytesB[jj2];jj2=jj2+1;

  }//for


  int o_row = 0;
  int o_col = 0;
  int kk = 0;

  o_row = p_row;

  for (int ii = 0; ii < 8; ii++) {

    o_col = p_col;

    for (int jj = 0; jj < 4; jj++) {

      char koi[8];

      koi[0] = *(databytes9 + kk + 0);
      koi[1] = *(databytes9 + kk + 4);
      koi[2] = *(databytes9 + kk + 8);
      koi[3] = *(databytes9 + kk + 12);

      koi[4] = *(databytes9 + kk + 16);
      koi[5] = *(databytes9 + kk + 20);
      koi[6] = *(databytes9 + kk + 24);
      koi[7] = *(databytes9 + kk + 28);

      kk = kk + 1;

      p_m270(koi);
      p_out(bbh);

      oled->writeBitmap((uint8_t *)bbh, 
                        o_row,
                       (o_row + 1 - 1),
                        o_col,
                       (o_col + 8 - 1));

      o_col = o_col + 8;

    } // for jj

    o_row = o_row + 1;

    kk = kk + 7 * 4;

  } // for ii


} // bitmap32x32


//メイン関数
int main() {

  wait_ms(500); // 0.5秒の待ち

  // Instantiate OLED
  SSD1308 oled = SSD1308(&i2c, SSD1308_SA0);

  int p_row = 0;
  int p_col = 0;


  int c1000 = 1; //千の桁
  int c100  = 2; //百の桁
  int c10   = 3; //十の桁
  int c1    = 4; //一の桁

  int x = 46; //数値

  char    tempval;        //温度


  //無限ループ
  while (1) {

    //初期化
    //set address 0
    i2c.write(ADDR, "\000", 1); //addres 0

    //温度の読み込み
    // Read temperature register
    i2c.read(ADDR, &tempval,1);

    //tempval = 21; //debug

    x = tempval;

//10の割り算 0から9999までは、正しい。 stm32
#define DIV10(n) (((n*409)+((n*154)>>8))>>12)

    c1    =  (  x - (DIV10(x) * 10)  );  // '0'+(d%10)
    x = DIV10(x);
    c10   =  (  x - (DIV10(x) * 10)  );  // '0'+(d%10)
    x = DIV10(x);
    c100  =  (  x - (DIV10(x) * 10)  );  // '0'+(d%10)
    c1000 =   DIV10(x);                  // '0'+(d/10)

    p_col = 0;

    bitmap32x64( &oled,(uint8_t *) ( databytes1+(c1000 *(32/8)*32)  ), p_row ,   p_col );

    p_col = p_col + 32; 

    bitmap32x64( &oled,(uint8_t *) ( databytes1+(c100  *(32/8)*32)  ) , p_row ,  p_col );

    p_col = p_col + 32;

    bitmap32x64( &oled,(uint8_t *) ( databytes1+(c10   *(32/8)*32)  ) , p_row ,  p_col );

    p_col = p_col + 32;

    bitmap32x64( &oled,(uint8_t *) ( databytes1+(c1    *(32/8)*32)  ) , p_row ,  p_col );

    wait_ms(1000); // 1秒の待ち

  }//while

} // main





```