Hello code for "Switch Science mbed LPC824"
Fork of SwitchSciencembedLPC824_test by
main.cpp
- Committer:
- okano
- Date:
- 2014-11-03
- Revision:
- 0:f947ed831c67
- Child:
- 1:3c29c04cfeb2
File content as of revision 0:f947ed831c67:
#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 ); }