LoginSignup
0
0

More than 1 year has passed since last update.

STM32F767のMbedでの温度,STTS751で温度表示(AQM0802A)

Last updated at Posted at 2021-02-20

x 愛用していたSTTS751の入手が難しくなったので代用品は、S-5851A。(おもにアドレスの違い)

1.SCLとSDAを接続、プルアップも忘れずに
2.電源の接続
3.下記のソースコードを書き込む
4.コンパイル実行で表示されたら終了
5.おわり


#include "mbed.h"
#include <stdio.h>

 
#define ADDR        (0x39<<1)   //  address
#define ADDR_LCD    (0x7C)      //  address


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

DigitalOut myled(LED1); //767 or 1114
//DigitalOut beep1(dp25); //1114
 


//Serial pc(USBTX, USBRX); // tx, rx
Serial pc(SERIAL_TX, SERIAL_RX);     //767
//Serial pc(dp16, dp15); // tx, rx

 
char    TempCelsiusDisplay[] = "+abc.d C";
int     tempval;
char    data_read[2];
char    cmd[2]={0,0};
int     ii; //ループカウンター
int     p_val; //戻り値

char INIT_com[]={0x0,0x38,
0x0,0x39,
0x0,0x4,
0x0,0x14,
0x0,0x70,
0x0,0x56,
0x0,0x6C,
0x0,0x38,
0x0,0xC,
0x0,0x1,
0x40,0x41,0x99,0x99};

char INIT_cls[]={0x0,0x1};

int main()
{
 
    for(ii=0;ii<10;ii++){
        myled = 1;
        wait(0.2);
        myled = 0;
        wait(0.2);
    }//for

    //液晶の初期化
    for(ii=0;ii<11;ii++){
        //pc.printf("%x %x \n\r",INIT_com[ii*2],INIT_com[(ii*2)+1]); //debug     
        p_val = i2c.write(ADDR_LCD, &INIT_com[ii*2], 2);
    } //for
 
    while (1) {
        //液晶のクリア
        //pc.printf("INIT_cls:");
        p_val = i2c.write(ADDR_LCD,INIT_cls,2);
        
        // Read temperature register
        i2c.read(ADDR, data_read,1,false);
 
        // Calculate temperature value in Celcius
        tempval =  data_read[0];

        // Integer part
      //TempCelsiusDisplay[0] = '+';
        TempCelsiusDisplay[1] =  (tempval / 100)       + '0';
        TempCelsiusDisplay[2] = ((tempval % 100) / 10) + '0';
        TempCelsiusDisplay[3] = ((tempval % 100) % 10) + '0';
      //TempCelsiusDisplay[4] = '.';
        TempCelsiusDisplay[5] = '0';
 
        // Display result
        pc.printf("temp = %s\n\r", TempCelsiusDisplay);
        //myled = !myled;
        cmd[0] = '@';
        cmd[1] = (tempval/10)+'0';
        p_val = i2c.write(ADDR_LCD, cmd ,2);
        cmd[1] = (tempval%10)+'0';
        p_val = i2c.write(ADDR_LCD, cmd ,2);
        
        wait_ms(1000);
    }//while
 
}//main
 



STTS751_i2c_lcd_767_1.jpg

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