「デカ文字時計」LPC812とSSD1306(128x32)とDS1307


参考


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




「デカ文字時計」LPC812とSSD1306(128x32)とDS1307


lpc812 oled ssd1306 DS1307 mbed 


x めんどいので過去ログを見よ
x ソースが長い
x 時間合わせは、別


![o_cop409.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/3539be55-9794-82eb-302f-3d7dd0364185.jpeg)




```c++





//Keil Studio   ( mbed2 )
//oled_ds1307_24x64_812_1

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


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

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









  0xff, 0x00, 0xff, 0xfe, 0x18, 0x7f, 0xfc, 0xff, 0x3f, 0xf9, 0xff, 0x9f, 0xf3, 0xff, 0xcf, 0xf3, 
  0xff, 0xcf, 0xe7, 0xff, 0xe7, 0xe7, 0xff, 0xe7, 0xe7, 0xff, 0xe7, 0xe7, 0xff, 0xe7, 0xe7, 0xff, 
  0xe7, 0xe7, 0xff, 0xe7, 0xe7, 0xff, 0xe7, 0xe7, 0xff, 0xe7, 0xe7, 0xff, 0xe7, 0xe7, 0xff, 0xe7, 
  0xe7, 0xff, 0xe7, 0xe7, 0xff, 0xe7, 0xe7, 0xff, 0xe7, 0xe7, 0xff, 0xe7, 0xe7, 0xff, 0xe7, 0xe7, 
  0xff, 0xe7, 0xe7, 0xff, 0xe7, 0xe7, 0xff, 0xe7, 0xe7, 0xff, 0xe7, 0xe7, 0xff, 0xe7, 0xe7, 0xff, 
  0xe7, 0xf3, 0xff, 0xe7, 0xf3, 0xff, 0xcf, 0xf8, 0xff, 0x8f, 0xfc, 0x3e, 0x1f, 0xfe, 0x00, 0x3f, 
  0xff, 0x03, 0xff, 0xfe, 0x03, 0xff, 0xfc, 0xe7, 0xff, 0xf9, 0xe7, 0xff, 0xfb, 0xe7, 0xff, 0xff, 
  0xe7, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xe7, 
  0xff, 0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 
  0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 0xff, 
  0xe7, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xe7, 
  0xff, 0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 0xfe, 0x00, 0x7f, 0xfc, 0x00, 0x3f, 
  0xff, 0x00, 0xff, 0xfe, 0x18, 0x7f, 0xfc, 0xff, 0x3f, 0xf9, 0xff, 0x9f, 0xf3, 0xff, 0xcf, 0xf3, 
  0xff, 0xcf, 0xe7, 0xff, 0xe7, 0xe7, 0xff, 0xe7, 0xf7, 0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 0xff, 
  0xe7, 0xff, 0xff, 0xef, 0xff, 0xff, 0xcf, 0xff, 0xff, 0x9f, 0xff, 0xff, 0x3f, 0xff, 0x80, 0x7f, 
  0xff, 0x00, 0xff, 0xfe, 0x3f, 0xff, 0xfc, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xf3, 0xff, 0xff, 0xf3, 
  0xff, 0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 
  0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xf7, 0xff, 0xff, 0xf1, 0xfe, 0x07, 0xf8, 0x00, 0x07, 
  0xff, 0x00, 0xff, 0xfe, 0x18, 0x7f, 0xfc, 0xff, 0x3f, 0xf9, 0xff, 0x9f, 0xf3, 0xff, 0xcf, 0xf3, 
  0xff, 0xcf, 0xe7, 0xff, 0xe7, 0xe7, 0xff, 0xe7, 0xe7, 0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 0xff, 
  0xe7, 0xff, 0xff, 0xef, 0xff, 0xff, 0xcf, 0xff, 0xff, 0x9f, 0xff, 0xff, 0x3f, 0xff, 0x00, 0x7f, 
  0xff, 0x00, 0x7f, 0xff, 0xfe, 0x3f, 0xff, 0xff, 0x9f, 0xff, 0xff, 0xcf, 0xff, 0xff, 0xe7, 0xff, 
  0xff, 0xe7, 0xff, 0xff, 0xf3, 0xff, 0xff, 0xf3, 0xff, 0xff, 0xf3, 0xe7, 0xff, 0xf3, 0xe7, 0xff, 
  0xf3, 0xf3, 0xff, 0xf7, 0xf3, 0xff, 0xe7, 0xf8, 0xff, 0xcf, 0xfc, 0x3e, 0x1f, 0xfe, 0x00, 0x3f, 
  0xff, 0xfe, 0x7f, 0xff, 0xfc, 0x3f, 0xff, 0xfc, 0x7f, 0xff, 0xf8, 0xff, 0xff, 0xf9, 0xff, 0xff, 
  0xe1, 0xff, 0xff, 0xc3, 0xff, 0xff, 0xcf, 0xff, 0xff, 0x0f, 0xff, 0xfe, 0x19, 0xff, 0xfc, 0x39, 
  0xff, 0xf8, 0x79, 0xff, 0xf1, 0xf9, 0xff, 0xf3, 0xf9, 0xff, 0xe3, 0xf9, 0xff, 0xe7, 0xf9, 0xff, 
  0xe7, 0xf1, 0xf7, 0xe0, 0x00, 0x07, 0xe0, 0x00, 0x07, 0xff, 0xf9, 0xff, 0xff, 0xf9, 0xff, 0xff, 
  0xf9, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xf9, 
  0xff, 0xff, 0xf9, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xf9, 0xff, 0xff, 0xf9, 0xff, 
  0xf0, 0x00, 0x07, 0xf0, 0x00, 0x07, 0xe7, 0xff, 0xff, 0xef, 0xff, 0xff, 0xef, 0xff, 0xff, 0xe7, 
  0xff, 0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 
  0xff, 0xe3, 0xff, 0xff, 0xe3, 0xff, 0xff, 0xf1, 0xff, 0xff, 0xf8, 0x3f, 0xff, 0xfe, 0x00, 0x7f, 
  0xff, 0x20, 0x7f, 0xff, 0xfe, 0x3f, 0xff, 0xff, 0x9f, 0xff, 0xff, 0xcf, 0xff, 0xff, 0xe7, 0xff, 
  0xff, 0xe7, 0xff, 0xff, 0xf3, 0xff, 0xff, 0xf3, 0xff, 0xff, 0xf3, 0xff, 0xff, 0xf3, 0xff, 0xff, 
  0xf3, 0xff, 0xff, 0xf7, 0xf3, 0xff, 0xe7, 0xf8, 0xff, 0xcf, 0xfc, 0x3e, 0x1f, 0xfe, 0x00, 0x3f, 
  0xff, 0x00, 0xff, 0xfe, 0x18, 0x7f, 0xfc, 0xff, 0x3f, 0xf9, 0xff, 0x9f, 0xf3, 0xff, 0xcf, 0xf3, 
  0xff, 0xcf, 0xe7, 0xff, 0xe7, 0xe7, 0xff, 0xe7, 0xe7, 0xff, 0xef, 0xe7, 0xff, 0xff, 0xe7, 0xff, 
  0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xe1, 0xff, 0xff, 0xe0, 0x00, 0x7f, 
  0xe0, 0x00, 0x3f, 0xe1, 0xff, 0x3f, 0xe3, 0xff, 0x9f, 0xe7, 0xff, 0xcf, 0xe7, 0xff, 0xe7, 0xe7, 
  0xff, 0xe7, 0xe7, 0xff, 0xf3, 0xe7, 0xff, 0xf3, 0xe7, 0xff, 0xf3, 0xe7, 0xff, 0xf3, 0xe7, 0xff, 
  0xf3, 0xf3, 0xff, 0xf7, 0xf3, 0xff, 0xe7, 0xf8, 0xff, 0xcf, 0xfc, 0x3e, 0x1f, 0xfe,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7, 0xf3, 0xff, 0xe7, 0xf8, 0xff, 0xcf, 0xfc, 0x3e, 0x1f, 0xfe, 0x00, 0x3f, 
  0xff, 0x00, 0xff, 0xfe, 0x18, 0x7f, 0xfc, 0xff, 0x3f, 0xf9, 0xff, 0x9f, 0xf3, 0xff, 0xcf, 0xf3, 
  0xff, 0xc7, 0xe7, 0xff, 0xe7, 0xe7, 0xff, 0xe7, 0xe7, 0xff, 0xe7, 0xe7, 0xff, 0xe7, 0xe7, 0xff, 
  0xe7, 0xf3, 0xff, 0xe7, 0xf3, 0xff, 0xe7, 0xf9, 0xff, 0xe7, 0xfc, 0xff, 0x07, 0xfe, 0x00, 0x07, 
  0xff, 0x00, 0x67, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 
  0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xc7, 0xff, 0xff, 
  0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0x8f, 0xff, 0xfc, 0x1f, 0xff, 0xf0, 0x3f, 0xff, 0xe1, 0xff,



// 'F24x32_(colonQQ)', 24x32px


  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, 0xc3, 0xff, 0xff, 0xc3, 0xff, 0xff, 0xc3, 
  0xff, 0xff, 0xc3, 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, 0xc3, 0xff, 0xff, 
  0xc3, 0xff, 0xff, 0xc3, 0xff, 0xff, 0xc3, 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






 
    };

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


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



  char  databytes9[4*64];

for(int uu=0;uu<(64*4);uu++){databytes9[uu]=0;} //debug


  int jj2=0;

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

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

   databytes9[(ii*6)+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 < 3; jj++) {

      char koi[8];

      koi[0] = *(databytes9 + kk + 0);
      koi[1] = *(databytes9 + kk + 3);
      koi[2] = *(databytes9 + kk + 6);
      koi[3] = *(databytes9 + kk + 9);

      koi[4] = *(databytes9 + kk + 12);
      koi[5] = *(databytes9 + kk + 15);
      koi[6] = *(databytes9 + kk + 18);
      koi[7] = *(databytes9 + kk + 21);

      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;
    kk = kk + 7 * 3;

  } // for ii


} // bitmap32x32



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

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

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

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

  int cn[5];  //桁
  int x = 46; //数値

unsigned char uuh[]
    = {

	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

};

char    data_read[8];   //i2cバッファー



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


#define ADDR        (0xD0)   //  address


        //時間の読み込み
        i2c.write(ADDR, "\000", 1);
        i2c.read(ADDR | 1, data_read, 7);


  //表示変換する
  x=0;
  x = x + 1000*(data_read[2] >> 4);    //0
  x = x +  100*(data_read[2] & 0xf);   //1

  x = x +   10*(data_read[1] >> 4);    //2
  x = x +      (data_read[1] & 0xf);   //4



    //x = 1234;

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

    cn[4]    =  (  x - (DIV10(x) * 10)  );  // '0'+(d%10)
    x = DIV10(x);
    cn[3]    =  (  x - (DIV10(x) * 10)  );  // '0'+(d%10)
 
    cn[2]    = 10;
 
    x = DIV10(x);
    cn[1]    =  (  x - (DIV10(x) * 10)  );  // '0'+(d%10)
    cn[0]    =   DIV10(x);                  // '0'+(d/10)

//ビットマップの表示 枠-左
      oled.writeBitmap((uint8_t *)uuh, 
                        0,
                       (7 + 1 - 1),
                        0,
                       (0 + 4 - 1));

  //ビットマップの表示 枠-右
      oled.writeBitmap((uint8_t *)uuh, 
                        0,
                       (7 + 1 - 1),
                        124,
                       (124 + 4 - 1));






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

       bitmap32x64( &oled,(uint8_t *) ( databytes1+(cn[ii] *(24/8)*32)  ), 0 ,   (ii*24)+4 );

    }//for

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

  }//while

} // main









```