Dependencies:   mbed

Committer:
okano
Date:
Sat Jan 23 13:45:32 2010 +0000
Revision:
0:188e389bc1b7

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
okano 0:188e389bc1b7 1 /*
okano 0:188e389bc1b7 2 * I2C digital temperature sensor "LM75B" test
okano 0:188e389bc1b7 3 *
okano 0:188e389bc1b7 4 * LM75B is an I2C based digital temperature sensor
okano 0:188e389bc1b7 5 * http://www.nxp.com/pip/LM75B_2.html
okano 0:188e389bc1b7 6 *
okano 0:188e389bc1b7 7 * This program is Expecting to use the pins 9 and 10 for I2C bus
okano 0:188e389bc1b7 8 * these pins should be pulled-up properly.
okano 0:188e389bc1b7 9 *
okano 0:188e389bc1b7 10 * The temperature read out will be shown on terminal on the PC screen.
okano 0:188e389bc1b7 11 *
okano 0:188e389bc1b7 12 * In this demo code, two LM75B devices can be driven.
okano 0:188e389bc1b7 13 * These two devices should have different I2C address setting
okano 0:188e389bc1b7 14 * using its address pins (LM75B's A0 to A2 (pins 5 to 7)).
okano 0:188e389bc1b7 15 * One LM75B should have all those pins tied to GND.
okano 0:188e389bc1b7 16 * And another should have the pin A0(pin7) pulled-up.
okano 0:188e389bc1b7 17 *
okano 0:188e389bc1b7 18 * From the software, those devices can be accessed by I2C addresses
okano 0:188e389bc1b7 19 * "0x90" and "0x92".
okano 0:188e389bc1b7 20 * It will not be as "0x90" and "0x91" because the address has
okano 0:188e389bc1b7 21 * 7 bit only and stuffed to left. So the "A0" setting become 0xX2.
okano 0:188e389bc1b7 22 * The LSB does not care because it will be set by I2C libraly when
okano 0:188e389bc1b7 23 * it transfer the data for read and write.
okano 0:188e389bc1b7 24 *
okano 0:188e389bc1b7 25 * This code is new version that can handle the LM75B are the objects.
okano 0:188e389bc1b7 26 *
okano 0:188e389bc1b7 27 * Copyright (c) 2010 Tedd OKANO
okano 0:188e389bc1b7 28 * Released under the MIT License: http://mbed.org/license/mit
okano 0:188e389bc1b7 29 *
okano 0:188e389bc1b7 30 * revision 1.0 16-Jan-2010 a. 1st release
okano 0:188e389bc1b7 31 * revision 1.1 23-Jan-2010 a. class name has been changed from LM75B to TempSensor_LM75B
okano 0:188e389bc1b7 32 * b. class name has been changed from lcd_SB1602E to TextLCD_SB1602E
okano 0:188e389bc1b7 33 * c. copyright notice added
okano 0:188e389bc1b7 34 */
okano 0:188e389bc1b7 35
okano 0:188e389bc1b7 36 #include "mbed.h"
okano 0:188e389bc1b7 37 #include "TempSensor_LM75B.h"
okano 0:188e389bc1b7 38 #include "TextLCD_SB1602E.h"
okano 0:188e389bc1b7 39
okano 0:188e389bc1b7 40 Serial pc(USBTX, USBRX); // tx, rx
okano 0:188e389bc1b7 41
okano 0:188e389bc1b7 42 I2C i2c( p9, p10 ); // sda, scl
okano 0:188e389bc1b7 43
okano 0:188e389bc1b7 44 TempSensor_LM75B thermo_sensor_0( &i2c ); // sensor_0 using with default I2C address "0x90".
okano 0:188e389bc1b7 45 TempSensor_LM75B thermo_sensor_1( &i2c, 0x92 ); // sensor_1 gaved I2C address since that address pin A0=HIGH.
okano 0:188e389bc1b7 46 TextLCD_SB1602E lcd( &i2c );
okano 0:188e389bc1b7 47
okano 0:188e389bc1b7 48 int main() {
okano 0:188e389bc1b7 49 float t0;
okano 0:188e389bc1b7 50 float t1;
okano 0:188e389bc1b7 51 int i = 0;
okano 0:188e389bc1b7 52
okano 0:188e389bc1b7 53 while (1) {
okano 0:188e389bc1b7 54 t0 = thermo_sensor_0;
okano 0:188e389bc1b7 55 t1 = thermo_sensor_1;
okano 0:188e389bc1b7 56
okano 0:188e389bc1b7 57 pc.printf( " (%d) sensor_0= %4.1f\xDF, sensor_1= %4.1f(degree-C)\n", i++, t0, t1 );
okano 0:188e389bc1b7 58
okano 0:188e389bc1b7 59 lcd.printf( 0, "sensor0 %4.1f%cC\r", t0, 0xDF );
okano 0:188e389bc1b7 60 lcd.printf( 1, "sensor1 %4.1f%cC\r", t1, 0xDF );
okano 0:188e389bc1b7 61
okano 0:188e389bc1b7 62 wait( 1 );
okano 0:188e389bc1b7 63 }
okano 0:188e389bc1b7 64 }
okano 0:188e389bc1b7 65