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/base_class/I2CTempSensor.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://www.nxp.com/documents/data_sheet/PCT2075.pdf |
okano | 0:3c3d4c5ac8e9 | 14 | * http://www.nxp.com/documents/data_sheet/LM75B.pdf |
okano | 0:3c3d4c5ac8e9 | 15 | */ |
okano | 0:3c3d4c5ac8e9 | 16 | |
okano | 1:5398b0799e20 | 17 | #ifndef MBED_I2CTempSensor_H |
okano | 1:5398b0799e20 | 18 | #define MBED_I2CTempSensor_H |
okano | 1:5398b0799e20 | 19 | |
okano | 0:3c3d4c5ac8e9 | 20 | #include "mbed.h" |
okano | 0:3c3d4c5ac8e9 | 21 | |
okano | 0:3c3d4c5ac8e9 | 22 | /** I2CTempSensor class library クラスライブラリ |
okano | 0:3c3d4c5ac8e9 | 23 | * |
okano | 0:3c3d4c5ac8e9 | 24 | * This class is an abstract class. So no instance can be made. |
okano | 0:3c3d4c5ac8e9 | 25 | * このクラスは抽象クラスなのでインスタンスを作成することはできません |
okano | 0:3c3d4c5ac8e9 | 26 | * クラスライブラリは非常にシンプルなインターフェースを提供します |
okano | 0:3c3d4c5ac8e9 | 27 | */ |
okano | 0:3c3d4c5ac8e9 | 28 | |
okano | 0:3c3d4c5ac8e9 | 29 | class I2CTempSensor |
okano | 0:3c3d4c5ac8e9 | 30 | { |
okano | 1:5398b0799e20 | 31 | public: |
okano | 1:5398b0799e20 | 32 | virtual float read( void ) = 0; |
okano | 1:5398b0799e20 | 33 | virtual operator float( void ) = 0; |
okano | 1:5398b0799e20 | 34 | |
okano | 0:3c3d4c5ac8e9 | 35 | protected: |
okano | 0:3c3d4c5ac8e9 | 36 | |
okano | 0:3c3d4c5ac8e9 | 37 | /** LM75Bのレジスタ名とアドレス */ |
okano | 0:3c3d4c5ac8e9 | 38 | enum command_reg { |
okano | 0:3c3d4c5ac8e9 | 39 | LM75B_Temp = 0x00, |
okano | 0:3c3d4c5ac8e9 | 40 | LM75B_Conf, |
okano | 0:3c3d4c5ac8e9 | 41 | LM75B_Thyst, |
okano | 0:3c3d4c5ac8e9 | 42 | LM75B_Tos |
okano | 0:3c3d4c5ac8e9 | 43 | }; |
okano | 0:3c3d4c5ac8e9 | 44 | |
okano | 0:3c3d4c5ac8e9 | 45 | /** I2Cピンとスレーブアドレスを指定し,インスタンスを作成します |
okano | 0:3c3d4c5ac8e9 | 46 | * |
okano | 0:3c3d4c5ac8e9 | 47 | * @param i2c_sda I2C-bus i2c_sdaピン |
okano | 0:3c3d4c5ac8e9 | 48 | * @param i2c_scl I2C-bus i2c_sclピン |
okano | 0:3c3d4c5ac8e9 | 49 | * @param address (オプション) I2C-bus スレーブアドレス (デフォルト: 0x90) |
okano | 0:3c3d4c5ac8e9 | 50 | */ |
okano | 0:3c3d4c5ac8e9 | 51 | I2CTempSensor( PinName i2c_sda, PinName i2c_scl, char address ); |
okano | 0:3c3d4c5ac8e9 | 52 | |
okano | 0:3c3d4c5ac8e9 | 53 | /** I2Cオブジェクトとスレーブアドレスを指定し,インスタンスを作成します |
okano | 0:3c3d4c5ac8e9 | 54 | * |
okano | 0:3c3d4c5ac8e9 | 55 | * @param i2c_obj I2C オブジェクト (インスタンス) |
okano | 0:3c3d4c5ac8e9 | 56 | * @param address (オプション) I2C-bus スレーブアドレス (デフォルト: 0x90) |
okano | 0:3c3d4c5ac8e9 | 57 | */ |
okano | 0:3c3d4c5ac8e9 | 58 | I2CTempSensor( I2C &i2c_obj, char address ); |
okano | 0:3c3d4c5ac8e9 | 59 | |
okano | 0:3c3d4c5ac8e9 | 60 | /** デストラクタ |
okano | 0:3c3d4c5ac8e9 | 61 | */ |
okano | 0:3c3d4c5ac8e9 | 62 | ~I2CTempSensor(); |
okano | 0:3c3d4c5ac8e9 | 63 | |
okano | 0:3c3d4c5ac8e9 | 64 | /** 初期化 |
okano | 0:3c3d4c5ac8e9 | 65 | */ |
okano | 0:3c3d4c5ac8e9 | 66 | void init( void ); |
okano | 0:3c3d4c5ac8e9 | 67 | |
okano | 0:3c3d4c5ac8e9 | 68 | /** 温度の読み出し |
okano | 0:3c3d4c5ac8e9 | 69 | * |
okano | 0:3c3d4c5ac8e9 | 70 | * @return 摂氏温度を返します(float型) |
okano | 0:3c3d4c5ac8e9 | 71 | */ |
okano | 1:5398b0799e20 | 72 | short read16( void ); |
okano | 0:3c3d4c5ac8e9 | 73 | |
okano | 0:3c3d4c5ac8e9 | 74 | private: |
okano | 0:3c3d4c5ac8e9 | 75 | I2C *i2c_p; |
okano | 0:3c3d4c5ac8e9 | 76 | I2C &i2c; |
okano | 0:3c3d4c5ac8e9 | 77 | char adr; |
okano | 0:3c3d4c5ac8e9 | 78 | }; |
okano | 1:5398b0799e20 | 79 | |
okano | 1:5398b0799e20 | 80 | #endif // MBED_I2CTempSensor_H |
okano | 1:5398b0799e20 | 81 |