Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@caa45040

STM32F767のMbedでの温度,STTS751で温度表示

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


#include "mbed.h"

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

I2C i2c(I2C_SDA, I2C_SCL);

DigitalOut myled(LED1);

Serial pc(SERIAL_TX, SERIAL_RX);

volatile char TempCelsiusDisplay[] = "+abc.d C";

//i2cdetect -y 9
//     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
//00:          -- -- -- -- -- -- -- -- -- -- -- -- --
//10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
//20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
//30: -- -- -- -- -- -- -- -- -- 39 -- -- -- -- -- --
//40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
//50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
//60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
//70: -- -- -- -- -- -- -- --
//i2cget -y 9 0x39
//0x1c

int tempval;

void led_temp(int temp);

int main()
{

    char data_read[2];

    while (1) {
        // Read temperature register

        i2c.read(ADDR, data_read,1,false);

        // Calculate temperature value in Celcius
        int tempval =  data_read[0];

        if( !(tempval >= 10 && tempval <= 29) ) tempval = 25;
        //led_temp(15);
        led_temp(tempval);

        // Integer part

    //TempCelsiusDisplay[0] = '+';
        TempCelsiusDisplay[1] = (tempval / 100) + 0x30;
        TempCelsiusDisplay[2] = ((tempval % 100) / 10) + 0x30;
        TempCelsiusDisplay[3] = ((tempval % 100) % 10) + 0x30;
    //TempCelsiusDisplay[4] = '.';
    TempCelsiusDisplay[5] = '0';

        // Display result
        pc.printf("temp = %s\n\r", TempCelsiusDisplay);
        //myled = !myled;
        //wait(1.0);
    }

}

void led_temp(int temp)
{ 
        //int temp;
        //temp = 15;

        //開始時の余白 1500ms
        myled = 0; // LED is ON
        wait(0.5); // 200 ms

        //十の桁
        //10から19        
        if( temp >= 10 && temp <= 19) {
            myled = 1; // LED is ON
            wait(3.5); // 200 ms

            myled = 0; // LED is OFF
            wait(0.5); // 1 sec
        } //end if 10-19
        //20から29

        if( temp >= 20 && temp <= 29) {
            myled = 1; // LED is ON
            wait(1.5); // 200 ms

            myled = 0; // LED is OFF
            wait(0.5); // 1 sec

            myled = 1; // LED is ON
            wait(1.5); // 200 ms

            myled = 0; // LED is OFF
            wait(0.5); // 1 sec
        } //enf if 20-29

        //一の桁
        //一の桁の空白
        myled = 0; // LED is OFF
        wait(0.5); // 1 sec

        for(int n = 0;n < (temp % 10);n++){
            myled = 1; // LED is ON
            wait(0.5); // 200 ms

            myled = 0; // LED is OFF
            wait(0.5); // 1 sec
        }//end for

} //end sub

//int main() {
//    
//    
//    
//    while(1) {
//        //myled = 1; // LED is ON
//        //wait(2.5); // 200 ms
//        //myled = 0; // LED is OFF
//        //wait(2.5); // 1 sec
//        
//        led_temp(25);
//        
//    }
//}


f767_stts751_1.jpg

f767_stts751_3.jpg

f767_stts751_4.jpg

いろいろ
http://caa45040.jugem.jp/

0
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
0
Help us understand the problem. What is going on with this article?