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@0:3c3d4c5ac8e9, 2015-02-27 (annotated)
- Committer:
- okano
- Date:
- Fri Feb 27 10:47:24 2015 +0000
- Revision:
- 0:3c3d4c5ac8e9
- Child:
- 1:5398b0799e20
cannot built
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 | 0:3c3d4c5ac8e9 | 17 | #include "mbed.h" |
okano | 0:3c3d4c5ac8e9 | 18 | #include "I2CTempSensor.h" |
okano | 0:3c3d4c5ac8e9 | 19 | |
okano | 0:3c3d4c5ac8e9 | 20 | /** PCT2075 class library クラスライブラリ |
okano | 0:3c3d4c5ac8e9 | 21 | * |
okano | 0:3c3d4c5ac8e9 | 22 | * クラスライブラリは非常にシンプルなインターフェースを提供します |
okano | 0:3c3d4c5ac8e9 | 23 | * |
okano | 0:3c3d4c5ac8e9 | 24 | * コード例: |
okano | 0:3c3d4c5ac8e9 | 25 | * @code |
okano | 0:3c3d4c5ac8e9 | 26 | * #include "mbed.h" |
okano | 0:3c3d4c5ac8e9 | 27 | * #include "I2CTempSensor.h" |
okano | 0:3c3d4c5ac8e9 | 28 | * |
okano | 0:3c3d4c5ac8e9 | 29 | * I2CTempSensor temp0( p28, p27 ); |
okano | 0:3c3d4c5ac8e9 | 30 | * |
okano | 0:3c3d4c5ac8e9 | 31 | * I2C i2c( p28, p27 ); |
okano | 0:3c3d4c5ac8e9 | 32 | * I2CTempSensor temp1( i2c ); |
okano | 0:3c3d4c5ac8e9 | 33 | * |
okano | 0:3c3d4c5ac8e9 | 34 | * |
okano | 0:3c3d4c5ac8e9 | 35 | * int main() |
okano | 0:3c3d4c5ac8e9 | 36 | * { |
okano | 0:3c3d4c5ac8e9 | 37 | * float t0; |
okano | 0:3c3d4c5ac8e9 | 38 | * float t1; |
okano | 0:3c3d4c5ac8e9 | 39 | * |
okano | 0:3c3d4c5ac8e9 | 40 | * i2c.frequency( 400 * 1000 ); |
okano | 0:3c3d4c5ac8e9 | 41 | * |
okano | 0:3c3d4c5ac8e9 | 42 | * while(1) { |
okano | 0:3c3d4c5ac8e9 | 43 | * t0 = temp0; |
okano | 0:3c3d4c5ac8e9 | 44 | * t1 = temp1; |
okano | 0:3c3d4c5ac8e9 | 45 | * printf( "temp = %7.3f, %7.3f\r\n", t0, t1 ); |
okano | 0:3c3d4c5ac8e9 | 46 | * wait( 1 ); |
okano | 0:3c3d4c5ac8e9 | 47 | * } |
okano | 0:3c3d4c5ac8e9 | 48 | * } |
okano | 0:3c3d4c5ac8e9 | 49 | * @endcode |
okano | 0:3c3d4c5ac8e9 | 50 | */ |
okano | 0:3c3d4c5ac8e9 | 51 | class PCT2075 : I2CTempSensor |
okano | 0:3c3d4c5ac8e9 | 52 | { |
okano | 0:3c3d4c5ac8e9 | 53 | public: |
okano | 0:3c3d4c5ac8e9 | 54 | /** I2Cピンとスレーブアドレスを指定し,インスタンスを作成します |
okano | 0:3c3d4c5ac8e9 | 55 | * |
okano | 0:3c3d4c5ac8e9 | 56 | * @param i2c_sda I2C-bus i2c_sdaピン |
okano | 0:3c3d4c5ac8e9 | 57 | * @param i2c_scl I2C-bus i2c_sclピン |
okano | 0:3c3d4c5ac8e9 | 58 | * @param i2c_address (オプション) I2C-bus スレーブアドレス (デフォルト: 0x90) |
okano | 0:3c3d4c5ac8e9 | 59 | */ |
okano | 0:3c3d4c5ac8e9 | 60 | PCT2075( PinName i2c_sda, PinName i2c_scl, char i2c_address = DEFAULT_I2C_SLAVE_ADDRESS ); |
okano | 0:3c3d4c5ac8e9 | 61 | |
okano | 0:3c3d4c5ac8e9 | 62 | /** I2Cオブジェクトとスレーブアドレスを指定し,インスタンスを作成します |
okano | 0:3c3d4c5ac8e9 | 63 | * |
okano | 0:3c3d4c5ac8e9 | 64 | * @param i2c_obj I2C オブジェクト (インスタンス) |
okano | 0:3c3d4c5ac8e9 | 65 | * @param i2c_address (オプション) I2C-bus スレーブアドレス (デフォルト: 0x90) |
okano | 0:3c3d4c5ac8e9 | 66 | */ |
okano | 0:3c3d4c5ac8e9 | 67 | PCT2075( I2C &i2c_obj, char i2c_address = DEFAULT_I2C_SLAVE_ADDRESS ); |
okano | 0:3c3d4c5ac8e9 | 68 | |
okano | 0:3c3d4c5ac8e9 | 69 | /** デストラクタ |
okano | 0:3c3d4c5ac8e9 | 70 | */ |
okano | 0:3c3d4c5ac8e9 | 71 | virtual ~PCT2075(); |
okano | 0:3c3d4c5ac8e9 | 72 | |
okano | 0:3c3d4c5ac8e9 | 73 | /** 温度の読み出し |
okano | 0:3c3d4c5ac8e9 | 74 | * |
okano | 0:3c3d4c5ac8e9 | 75 | * @return 摂氏温度を返します(float型) |
okano | 0:3c3d4c5ac8e9 | 76 | */ |
okano | 0:3c3d4c5ac8e9 | 77 | float read( void ); |
okano | 0:3c3d4c5ac8e9 | 78 | |
okano | 0:3c3d4c5ac8e9 | 79 | /** 温度の読み出し |
okano | 0:3c3d4c5ac8e9 | 80 | * |
okano | 0:3c3d4c5ac8e9 | 81 | * @return オブジェクトが読みだした値を返すようにしています |
okano | 0:3c3d4c5ac8e9 | 82 | */ |
okano | 0:3c3d4c5ac8e9 | 83 | operator float( void ); |
okano | 0:3c3d4c5ac8e9 | 84 | |
okano | 0:3c3d4c5ac8e9 | 85 | private: |
okano | 0:3c3d4c5ac8e9 | 86 | /** デフォルト・スレーブアドレス */ |
okano | 0:3c3d4c5ac8e9 | 87 | enum { |
okano | 0:3c3d4c5ac8e9 | 88 | DEFAULT_I2C_SLAVE_ADDRESS = 0x90 |
okano | 0:3c3d4c5ac8e9 | 89 | }; |
okano | 0:3c3d4c5ac8e9 | 90 | |
okano | 0:3c3d4c5ac8e9 | 91 | I2C *i2c_p; |
okano | 0:3c3d4c5ac8e9 | 92 | I2C &i2c; |
okano | 0:3c3d4c5ac8e9 | 93 | char adr; |
okano | 0:3c3d4c5ac8e9 | 94 | }; |