LoginSignup
0
0

More than 1 year has passed since last update.

STM32L010とS-5851Aで温度を液晶ACM1602K-NLW-BBWに出力

Last updated at Posted at 2021-09-09

x 原因は、わからないが液晶がちらつく場合は、ウェートを調整してね!!

x 74hc164を使用

目的
秋月で売っている安価なS-5851A(約110円)を使って温度を出力する。

h_con53.jpg

h_con39.jpg




#include "mbed.h"

//*          *****  *****       ***  * *
//*         *       *    *     *   * * *
//*         *       *    *     *   * * *
//*         *       *    *     *   * * *
//*         *       *    *     *   * * *
//********   *****  *****       ***  * *

#define swclk1  PA_5    //A4
#define swdio1  PA_7    //A6
#define en1     PA_4    //A3

DigitalOut swdclk(swclk1);
DigitalOut swdio(swdio1);
DigitalOut en(en1);

//              12345678   12345678   12345678   12345678
char b8[8] = {0b10000000,0b01000000,0b00100000,0b00010000,
              0b00001000,0b00000100,0b00000010,0b00000001 };

void seg1(int v,int rs)
{
    for(int jj=0;jj<8;jj++){
        if( (v & b8[jj]) == 0 ){
                swdio=0; //ビットが0
        } else {
                swdio=1; //ビットが1 
        }//endif
        swdclk=1;swdclk=0; //clk
    }//for

    swdio=rs;
    en=1;    wait_ms(1);
    en=0;
}//seg1

//文字列の表示 nana_seg
int ns_printf(char *str1) {

    //文字の中身がゼロか
    while(*str1){

        //一文字出力
        seg1( *str1 ++ , 1  );


    } //while

    //戻り値
    return(0);
}//ns_printf

int lcd_int[]={
  0x30,0x30,0x30,0x38,0x08,0x01,0x06,0x08+0x04
};//lcd_init

//I2C i2c(I2C_SDA, I2C_SCL); //767
//I2C i2c(dp5, dp27); //1114
I2C i2c(PA_10, PA_9); //010

//#define S5851A 0x48
#define ADDR        ((0x48)<<1)   //  address

int main() {

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

    //GPIOの初期化
    en=0;

    //液晶の初期化
    for(int ii=0;ii<8;ii++){ 
        seg1( lcd_int[ii] , 0);wait_ms(2);
    }//for

    seg1( 0x80+0x00 , 0  ); //1ライン目にカーソルを移動
    ns_printf( "START" ); wait_ms(500);

    //画面クリア
    seg1(   0x01  , 0  ); 
    wait_ms(5);

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

        seg1( 0x80+0x00 , 0  ); //1ライン目にカーソルを移動

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

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

        //温度の保存
        // Calculate temperature value in Celcius
        int tempval =  data_read[0]; //温度の転記

        //tempval = 12; //debug

        //表示用の変数の初期化
        int s = tempval;
        int n0,n10,n100,n1000;

        n10   = s / 10;            // 1234 -> 123
        n0    = s - (n10 *10);     // 1234 -  1230 -> 4
        n100  = n10 / 10;          // 123  -> 12
        n10   = n10 - (n100 *10);  // 123  -  120 -> 3
        n1000 = n100 / 10;         // 12   -> 1
        n100  = n100 - (n1000*10); // 12   -  10  -> 2

        //画面に表示
        //data_read[0] = '0' + n1000;
        //data_read[1] = '0' + n100;
        data_read[0] = '0' + n10;
        data_read[1] = '0' + n0;
        data_read[2] = 0;
        ns_printf(data_read);

        //1秒待つ
        wait_ms(1000);

    }//while

}//main

//容量削減
void error(const char* format, ...){}



i2c関連




//I2C i2c(I2C_SDA, I2C_SCL); //767
//I2C i2c(dp5, dp27); //1114
I2C i2c(PA_10, PA_9); //010

//#define S5851A 0x48
#define ADDR        ((0x48)<<1)   //  address



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


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


        //温度の保存
        // Calculate temperature value in Celcius
        int tempval =  data_read[0]; //温度の転記

        //tempval = 12; //debug

        //表示用の変数の初期化
        int s = tempval;
        int n0,n10,n100,n1000;

        n10   = s / 10;            // 1234 -> 123
        n0    = s - (n10 *10);     // 1234 -  1230 -> 4
        n100  = n10 / 10;          // 123  -> 12
        n10   = n10 - (n100 *10);  // 123  -  120 -> 3
        n1000 = n100 / 10;         // 12   -> 1
        n100  = n100 - (n1000*10); // 12   -  10  -> 2

        //画面に表示
        //data_read[0] = '0' + n1000;
        //data_read[1] = '0' + n100;
        data_read[0] = '0' + n10;
        data_read[1] = '0' + n0;
        data_read[2] = '.';
        data_read[3] = 0;
        ns_printf(data_read);

        //1秒待つ
        wait_ms(1000);



0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0