Hello code for "Switch Science mbed LPC824"

Dependencies:   mbed

Fork of SwitchSciencembedLPC824_test by Mako SHIMURA

Files at this revision

API Documentation at this revision

Comitter:
okano
Date:
Mon Nov 03 00:03:55 2014 +0000
Child:
1:3c29c04cfeb2
Commit message:
very basic code for hardware verification

Changed in this revision

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/main.cpp	Mon Nov 03 00:03:55 2014 +0000
@@ -0,0 +1,48 @@
+#include "mbed.h"
+
+//  LM75B I2C slave address
+#define     ADDRESS_LM75B   0x90
+
+//  LM75B registers
+#define     LM75B_Conf      0x01
+#define     LM75B_Temp      0x00
+#define     LM75B_Tos       0x03
+#define     LM75B_Thyst     0x02
+
+I2C     i2c( p28, p27 );
+
+void    init( void );
+float   read_temp( void );
+
+
+int main()
+{
+    init();
+
+    while(1) {
+        printf( "temp = %7.3f\r\n", read_temp() );
+        wait( 1 );
+    }
+}
+
+void init( void )
+{
+    char    command[ 2 ];
+
+    command[ 0 ]    = LM75B_Conf;
+    command[ 1 ]    = 0x00;
+
+    i2c.write( ADDRESS_LM75B, command, 2 );
+}
+
+float read_temp( void )
+{
+    char    command[ 2 ];
+
+    command[ 0 ]    = LM75B_Temp;
+
+    i2c.write( ADDRESS_LM75B, command, 1 );  // Send command string
+    i2c.read(  ADDRESS_LM75B, command, 2 );  // read two bytes data
+
+    return ( (float)( (command[ 0 ] << 8)| command[1] ) / 256.0 );
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Nov 03 00:03:55 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/031413cf7a89
\ No newline at end of file