![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
SPI 接続の温度センサ ADT7310 用のライブラリの使用例. Demo program of the library for temperature sensor ADT7310 connected using SPI interface.
Dependencies: UIT_ADT7310 UIT_AQM1602 mbed
main.cpp@4:16a9eda5ef78, 2017-06-03 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Sat Jun 03 12:08:36 2017 +0000
- Revision:
- 4:16a9eda5ef78
- Parent:
- 2:6b7bb0e0949a
- Child:
- 5:8da999cd764a
5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:563b65e407e1 | 1 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:563b65e407e1 | 2 | // Dual ADT7310's using SPI interface |
MikamiUitOpen | 4:16a9eda5ef78 | 3 | // このプログラムは printf() 文でマルチバイト文字“℃”を |
MikamiUitOpen | 4:16a9eda5ef78 | 4 | // 使っているので,コンパイル時に警告が出る |
MikamiUitOpen | 0:563b65e407e1 | 5 | // |
MikamiUitOpen | 4:16a9eda5ef78 | 6 | // このプログラムは温度センサを2個使うということを前提に |
MikamiUitOpen | 4:16a9eda5ef78 | 7 | // しているプログラムなので,温度センサが1個でも動くが, |
MikamiUitOpen | 4:16a9eda5ef78 | 8 | // その場合の対応は特に行っていない |
MikamiUitOpen | 4:16a9eda5ef78 | 9 | // |
MikamiUitOpen | 4:16a9eda5ef78 | 10 | // 2017/06/03, Copyright (c) 2017 MIKAMI, Naoki |
MikamiUitOpen | 0:563b65e407e1 | 11 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:563b65e407e1 | 12 | |
MikamiUitOpen | 0:563b65e407e1 | 13 | #define ADT7310_DEBUG // デバッグの場合 |
MikamiUitOpen | 0:563b65e407e1 | 14 | #define USING_AQM1602 // LCD 表示装置を使う場合 |
MikamiUitOpen | 0:563b65e407e1 | 15 | |
MikamiUitOpen | 0:563b65e407e1 | 16 | #ifdef USING_AQM1602 |
MikamiUitOpen | 0:563b65e407e1 | 17 | #include "AQM1602.hpp" |
MikamiUitOpen | 0:563b65e407e1 | 18 | #endif |
MikamiUitOpen | 0:563b65e407e1 | 19 | |
MikamiUitOpen | 0:563b65e407e1 | 20 | #include "ADT7310.hpp" |
MikamiUitOpen | 0:563b65e407e1 | 21 | using namespace Mikami; |
MikamiUitOpen | 0:563b65e407e1 | 22 | |
MikamiUitOpen | 0:563b65e407e1 | 23 | #ifdef USING_AQM1602 |
MikamiUitOpen | 0:563b65e407e1 | 24 | Aqm1602 lcd_; // using default port |
MikamiUitOpen | 0:563b65e407e1 | 25 | #endif |
MikamiUitOpen | 0:563b65e407e1 | 26 | |
MikamiUitOpen | 0:563b65e407e1 | 27 | // Declarations of the objects for ADT7310 |
MikamiUitOpen | 0:563b65e407e1 | 28 | ADT7310 sensor1(D10); // Slave select for the sensor: D10 |
MikamiUitOpen | 0:563b65e407e1 | 29 | ADT7310 sensor2(D9); // Slave select for the sensor: D9 |
MikamiUitOpen | 0:563b65e407e1 | 30 | |
MikamiUitOpen | 0:563b65e407e1 | 31 | int main() |
MikamiUitOpen | 0:563b65e407e1 | 32 | { |
MikamiUitOpen | 0:563b65e407e1 | 33 | printf("\r\nStart dual ADT7310s\r\n"); |
MikamiUitOpen | 0:563b65e407e1 | 34 | #ifdef USING_AQM1602 |
MikamiUitOpen | 1:649b6f2b8f38 | 35 | bool on = true; |
MikamiUitOpen | 0:563b65e407e1 | 36 | lcd_.WriteStringXY("Dual ADT7310s", 0, 0); |
MikamiUitOpen | 0:563b65e407e1 | 37 | #endif |
MikamiUitOpen | 0:563b65e407e1 | 38 | /* |
MikamiUitOpen | 0:563b65e407e1 | 39 | sensor1.SetResolution16(); // Set 13-bit resolution mode |
MikamiUitOpen | 0:563b65e407e1 | 40 | sensor2.SetResolution16(true); // Set 16-bit resolution mode |
MikamiUitOpen | 0:563b65e407e1 | 41 | */ |
MikamiUitOpen | 0:563b65e407e1 | 42 | #ifdef ADT7310_DEBUG |
MikamiUitOpen | 4:16a9eda5ef78 | 43 | // print out content of configuration registers |
MikamiUitOpen | 0:563b65e407e1 | 44 | uint8_t v1 = sensor1.GetConfigReg(); |
MikamiUitOpen | 0:563b65e407e1 | 45 | uint8_t v2 = sensor2.GetConfigReg(); |
MikamiUitOpen | 0:563b65e407e1 | 46 | printf("v1: 0x%02x, v2: 0x%02x\r\n", v1, v2); |
MikamiUitOpen | 0:563b65e407e1 | 47 | #endif |
MikamiUitOpen | 0:563b65e407e1 | 48 | |
MikamiUitOpen | 0:563b65e407e1 | 49 | while (true) |
MikamiUitOpen | 0:563b65e407e1 | 50 | { |
MikamiUitOpen | 0:563b65e407e1 | 51 | float tempr1 = sensor1.Read(); |
MikamiUitOpen | 0:563b65e407e1 | 52 | float tempr2 = sensor2.Read(); |
MikamiUitOpen | 0:563b65e407e1 | 53 | printf("Sensor1: %5.1f [℃], Sensor2: %5.1f [℃]\r\n", |
MikamiUitOpen | 0:563b65e407e1 | 54 | tempr1, tempr2); |
MikamiUitOpen | 0:563b65e407e1 | 55 | |
MikamiUitOpen | 0:563b65e407e1 | 56 | #ifdef USING_AQM1602 |
MikamiUitOpen | 4:16a9eda5ef78 | 57 | lcd_.ClearLine(1); |
MikamiUitOpen | 4:16a9eda5ef78 | 58 | lcd_.WriteValueXY("%5.1f, ", tempr1, 0, 1); |
MikamiUitOpen | 4:16a9eda5ef78 | 59 | lcd_.WriteValue("%5.1f \xDF\x43", tempr2); |
MikamiUitOpen | 4:16a9eda5ef78 | 60 | |
MikamiUitOpen | 1:649b6f2b8f38 | 61 | if (on) lcd_.WriteStringXY(".", 15, 0); |
MikamiUitOpen | 1:649b6f2b8f38 | 62 | else lcd_.WriteStringXY(" ", 15, 0); |
MikamiUitOpen | 1:649b6f2b8f38 | 63 | on = !on; |
MikamiUitOpen | 0:563b65e407e1 | 64 | #endif |
MikamiUitOpen | 0:563b65e407e1 | 65 | wait(1); |
MikamiUitOpen | 0:563b65e407e1 | 66 | } |
MikamiUitOpen | 0:563b65e407e1 | 67 | } |