Hello world code for PCT2075 and LM75B component class library. The PCT2075 is a temperature-to-digital converter featuring +/-1 degree-C accuracy over -25 degree-C to +100 degree-C range. It uses an on-chip band gap temperature sensor and Sigma-Delta A-to-D conversion technique with an overtemperature detection output that is a drop-in replacement for other LM75 series thermal sensors.
PCT2075/PCT2075.h@1:5398b0799e20, 2015-02-27 (annotated)
- Committer:
- okano
- Date:
- Fri Feb 27 12:35:30 2015 +0000
- Revision:
- 1:5398b0799e20
- Parent:
- 0:3c3d4c5ac8e9
could built, no test done
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okano | 0:3c3d4c5ac8e9 | 1 | /** PCT2075 and LM75B component class library |
okano | 0:3c3d4c5ac8e9 | 2 | * PCT2075 と LM75B 用のコンポーネント・クラス・ライブラリです |
okano | 0:3c3d4c5ac8e9 | 3 | * |
okano | 0:3c3d4c5ac8e9 | 4 | * This is new NXP PCT2075 and classic LM75B component class library |
okano | 0:3c3d4c5ac8e9 | 5 | * This works for both PCT2075 and LM75B |
okano | 0:3c3d4c5ac8e9 | 6 | * |
okano | 0:3c3d4c5ac8e9 | 7 | * @author Tedd OKANO |
okano | 0:3c3d4c5ac8e9 | 8 | * @version 1.0 |
okano | 0:3c3d4c5ac8e9 | 9 | * @date 28-Feb-2015 |
okano | 0:3c3d4c5ac8e9 | 10 | * |
okano | 0:3c3d4c5ac8e9 | 11 | * For the details of PCT2075 and LM75B.. |
okano | 0:3c3d4c5ac8e9 | 12 | * PCT2075 and LM75Bの詳細は.. |
okano | 0:3c3d4c5ac8e9 | 13 | * http://i2c_sda.nxp.com/documents/data_sheet/PCT2075.pdf |
okano | 0:3c3d4c5ac8e9 | 14 | * http://i2c_sda.nxp.com/documents/data_sheet/LM75B.pdf |
okano | 0:3c3d4c5ac8e9 | 15 | */ |
okano | 0:3c3d4c5ac8e9 | 16 | |
okano | 1:5398b0799e20 | 17 | #ifndef MBED_PCT2075_H |
okano | 1:5398b0799e20 | 18 | #define MBED_PCT2075_H |
okano | 1:5398b0799e20 | 19 | |
okano | 0:3c3d4c5ac8e9 | 20 | #include "mbed.h" |
okano | 0:3c3d4c5ac8e9 | 21 | #include "I2CTempSensor.h" |
okano | 0:3c3d4c5ac8e9 | 22 | |
okano | 0:3c3d4c5ac8e9 | 23 | /** PCT2075 class library クラスライブラリ |
okano | 0:3c3d4c5ac8e9 | 24 | * |
okano | 0:3c3d4c5ac8e9 | 25 | * クラスライブラリは非常にシンプルなインターフェースを提供します |
okano | 0:3c3d4c5ac8e9 | 26 | * |
okano | 0:3c3d4c5ac8e9 | 27 | * コード例: |
okano | 0:3c3d4c5ac8e9 | 28 | * @code |
okano | 0:3c3d4c5ac8e9 | 29 | * #include "mbed.h" |
okano | 0:3c3d4c5ac8e9 | 30 | * #include "I2CTempSensor.h" |
okano | 0:3c3d4c5ac8e9 | 31 | * |
okano | 0:3c3d4c5ac8e9 | 32 | * I2CTempSensor temp0( p28, p27 ); |
okano | 0:3c3d4c5ac8e9 | 33 | * |
okano | 0:3c3d4c5ac8e9 | 34 | * I2C i2c( p28, p27 ); |
okano | 0:3c3d4c5ac8e9 | 35 | * I2CTempSensor temp1( i2c ); |
okano | 0:3c3d4c5ac8e9 | 36 | * |
okano | 0:3c3d4c5ac8e9 | 37 | * |
okano | 0:3c3d4c5ac8e9 | 38 | * int main() |
okano | 0:3c3d4c5ac8e9 | 39 | * { |
okano | 0:3c3d4c5ac8e9 | 40 | * float t0; |
okano | 0:3c3d4c5ac8e9 | 41 | * float t1; |
okano | 0:3c3d4c5ac8e9 | 42 | * |
okano | 0:3c3d4c5ac8e9 | 43 | * i2c.frequency( 400 * 1000 ); |
okano | 0:3c3d4c5ac8e9 | 44 | * |
okano | 0:3c3d4c5ac8e9 | 45 | * while(1) { |
okano | 0:3c3d4c5ac8e9 | 46 | * t0 = temp0; |
okano | 0:3c3d4c5ac8e9 | 47 | * t1 = temp1; |
okano | 0:3c3d4c5ac8e9 | 48 | * printf( "temp = %7.3f, %7.3f\r\n", t0, t1 ); |
okano | 0:3c3d4c5ac8e9 | 49 | * wait( 1 ); |
okano | 0:3c3d4c5ac8e9 | 50 | * } |
okano | 0:3c3d4c5ac8e9 | 51 | * } |
okano | 0:3c3d4c5ac8e9 | 52 | * @endcode |
okano | 0:3c3d4c5ac8e9 | 53 | */ |
okano | 0:3c3d4c5ac8e9 | 54 | class PCT2075 : I2CTempSensor |
okano | 0:3c3d4c5ac8e9 | 55 | { |
okano | 0:3c3d4c5ac8e9 | 56 | public: |
okano | 0:3c3d4c5ac8e9 | 57 | /** I2Cピンとスレーブアドレスを指定し,インスタンスを作成します |
okano | 0:3c3d4c5ac8e9 | 58 | * |
okano | 1:5398b0799e20 | 59 | * @param i2c_sda I2C-bus i2c_sdaピン |
okano | 1:5398b0799e20 | 60 | * @param i2c_scl I2C-bus i2c_sclピン |
okano | 1:5398b0799e20 | 61 | * @param i2c_address (オプション) I2C-bus スレーブアドレス (デフォルト: 0x90) |
okano | 0:3c3d4c5ac8e9 | 62 | */ |
okano | 0:3c3d4c5ac8e9 | 63 | PCT2075( PinName i2c_sda, PinName i2c_scl, char i2c_address = DEFAULT_I2C_SLAVE_ADDRESS ); |
okano | 0:3c3d4c5ac8e9 | 64 | |
okano | 0:3c3d4c5ac8e9 | 65 | /** I2Cオブジェクトとスレーブアドレスを指定し,インスタンスを作成します |
okano | 0:3c3d4c5ac8e9 | 66 | * |
okano | 0:3c3d4c5ac8e9 | 67 | * @param i2c_obj I2C オブジェクト (インスタンス) |
okano | 0:3c3d4c5ac8e9 | 68 | * @param i2c_address (オプション) I2C-bus スレーブアドレス (デフォルト: 0x90) |
okano | 0:3c3d4c5ac8e9 | 69 | */ |
okano | 0:3c3d4c5ac8e9 | 70 | PCT2075( I2C &i2c_obj, char i2c_address = DEFAULT_I2C_SLAVE_ADDRESS ); |
okano | 0:3c3d4c5ac8e9 | 71 | |
okano | 0:3c3d4c5ac8e9 | 72 | /** デストラクタ |
okano | 0:3c3d4c5ac8e9 | 73 | */ |
okano | 0:3c3d4c5ac8e9 | 74 | virtual ~PCT2075(); |
okano | 0:3c3d4c5ac8e9 | 75 | |
okano | 0:3c3d4c5ac8e9 | 76 | /** 温度の読み出し |
okano | 0:3c3d4c5ac8e9 | 77 | * |
okano | 0:3c3d4c5ac8e9 | 78 | * @return 摂氏温度を返します(float型) |
okano | 0:3c3d4c5ac8e9 | 79 | */ |
okano | 1:5398b0799e20 | 80 | virtual float read( void ); |
okano | 0:3c3d4c5ac8e9 | 81 | |
okano | 0:3c3d4c5ac8e9 | 82 | /** 温度の読み出し |
okano | 0:3c3d4c5ac8e9 | 83 | * |
okano | 0:3c3d4c5ac8e9 | 84 | * @return オブジェクトが読みだした値を返すようにしています |
okano | 0:3c3d4c5ac8e9 | 85 | */ |
okano | 1:5398b0799e20 | 86 | virtual operator float( void ); |
okano | 0:3c3d4c5ac8e9 | 87 | |
okano | 0:3c3d4c5ac8e9 | 88 | private: |
okano | 0:3c3d4c5ac8e9 | 89 | /** デフォルト・スレーブアドレス */ |
okano | 0:3c3d4c5ac8e9 | 90 | enum { |
okano | 0:3c3d4c5ac8e9 | 91 | DEFAULT_I2C_SLAVE_ADDRESS = 0x90 |
okano | 0:3c3d4c5ac8e9 | 92 | }; |
okano | 1:5398b0799e20 | 93 | }; |
okano | 0:3c3d4c5ac8e9 | 94 | |
okano | 1:5398b0799e20 | 95 | #endif // MBED_PCT2075_H |
okano | 1:5398b0799e20 | 96 |