"LM75B" : I2C digital temperature sensor demo http://mbed.org/users/okano/notebook/nxp_lm75b-demo-code/

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
okano
Date:
Sat Jun 05 04:03:39 2010 +0000
Commit message:

Changed in this revision

NXP_LM75B.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NXP_LM75B.h	Sat Jun 05 04:03:39 2010 +0000
@@ -0,0 +1,99 @@
+/*
+ *  I2C digital temperature sensor "LM75B" library
+ *
+ *  LM75B is an I2C based digital temperature sensor
+ *  http://www.nxp.com/pip/LM75B_2.html
+ *
+ *  This is a library to operate this chip easy.
+ *
+ *  Released under the MIT License: http://mbed.org/license/mit
+ *
+ *  revision 1.0    16-Jan-2010     (a) 1st release
+ *  revision 1.1    23-Jan-2010     (a) class name has been changed from LM75B to NXP_LM75B
+ *                                  (b) copyright notice added
+ *  revision 2.0    05-Jun-2010     (a) demo modified to make the library simple
+ */
+
+#ifndef        MBED_NXP_LM75B
+#define        MBED_NXP_LM75B
+
+
+#include    "mbed.h"
+
+
+//  LM75B IIC address
+const char    LM75B_base_addr = 0x90;
+
+//  LM75B registers
+const char    Conf            = 0x01;
+const char    Temp            = 0x00;
+const char    Tos             = 0x03;
+const char    Thyst           = 0x02;
+
+
+class NXP_LM75B  {
+public:
+
+    NXP_LM75B(    PinName sda, 
+                PinName sdl, 
+                char dev_address = LM75B_base_addr, 
+                char vConf = 0x00, 
+                short vTos  = 0x5000, 
+                short vThyst = 0x4B00 
+             ) 
+             : i2c( sda, sdl ), device_address( dev_address ) 
+    {
+    
+        char    data[ 3 ];
+
+        data[ 0 ]    = Conf;
+        data[ 1 ]    = vConf;
+
+        if ( i2c.write( device_address, data, 2 ) )
+            ;
+
+        data[ 0 ]    = Tos;
+        data[ 1 ]    = (char)(vTos >> 8);
+        data[ 2 ]    = (char)vTos;
+
+        if ( i2c.write( device_address, data, 3 ) )
+            ;
+
+        data[ 0 ]    = Thyst;
+        data[ 1 ]    = (char)(vThyst >> 8);
+        data[ 2 ]    = (char)vThyst;
+
+        if ( i2c.write( device_address, data, 3 ) )
+            ;
+    }
+
+    int temp_short( void ) {
+        char    data[ 2 ];
+
+        data[ 0 ]    = 0;
+
+        if ( i2c.write( device_address, data, 1 ) )
+            ;
+
+        if ( i2c.read( device_address, data, 2 ) )
+            ;
+
+        return ( (((short)data[ 0 ]) << 8 | data[ 1 ]) >> 5 );
+    }
+
+    float temp( void ) {
+        return ( (float)(temp_short()) / 8.0 );
+    }
+
+    operator float( void ) {
+        return( temp() );
+    }
+    
+private:
+    I2C     i2c;
+    char    device_address;
+
+}
+;
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Jun 05 04:03:39 2010 +0000
@@ -0,0 +1,37 @@
+/*
+ *  I2C digital temperature sensor "LM75B" demo
+ *
+ *  LM75B is an I2C based digital temperature sensor
+ *  http://www.nxp.com/pip/LM75B_2.html
+ *
+ *  This is a library to operate this chip easy.
+ *
+ *  Released under the MIT License: http://mbed.org/license/mit
+ *
+ *  revision 1.0    16-Jan-2010     (a) 1st release
+ *  revision 1.1    23-Jan-2010     (a) class name has been changed from LM75B to NXP_LM75B
+ *                                  (b) copyright notice added
+ *  revision 2.0    05-Jun-2010     (a) demo modified to make the library simple
+ *
+ */
+
+#include "mbed.h"
+#include "TextLCD.h"
+#include "NXP_LM75B.h"
+
+NXP_LM75B  temp_sensor( p9, p10, 0x9E );           // sda, scl, I2C_address(0x9E)
+TextLCD    lcd(p24, p25, p26, p27, p28, p29, p30); // rs, rw, e, d0, d1, d2, d3
+
+int main() {
+
+    lcd.locate( 0, 1 );
+    lcd.printf( " NXP LM75B demo" );
+
+    while ( 1 ) {
+        lcd.locate( 0, 0 );
+        lcd.printf( "%4.1f (deg-C)", (float)temp_sensor );
+
+        wait( 1 );
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Jun 05 04:03:39 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/b3c9f16cbb96