Now supports DS18B20 and DS18S20 Maxim/Dallas one-wire thermometer devices. Also supports DS18S20 in 9, 10, 11, and 12 bit resolution modes. 'Use Address' mode now checks if the correct device type is present, and informs the user which device to use. Correct temperature conversion times now used in non-parasitic mode. The device should be placed at least 6 inches (15 cm) from the mbed board in order to accurately read ambient temperature.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*
00002 * OneWireCRC/OneWireThermometer demo.
00003 *
00004 * Copyright (C) <2009> Petras Saduikis <petras@petras.co.uk>
00005 *
00006 * This file is part of OneWireCRC/OneWireThermometer.
00007 *
00008 * OneWireCRC/OneWireThermometer is free software: you can redistribute it and/or modify
00009 * it under the terms of the GNU General Public License as published by
00010 * the Free Software Foundation, either version 3 of the License, or
00011 * (at your option) any later version.
00012 * 
00013 * OneWireCRC/OneWireThermometer is distributed in the hope that it will be useful,
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 * GNU General Public License for more details.
00017 *
00018 * You should have received a copy of the GNU General Public License
00019 * along with OneWireCRC/OneWireThermometer0.  If not, see <http://www.gnu.org/licenses/>.
00020 */
00021 
00022 ////////////////////////////////////////////////////////////////////
00023 // Test code to read temperature from a Maxim DS18B20 or DS18S20
00024 // 1-wire device 
00025 ////////////////////////////////////////////////////////////////////
00026 
00027 #include <mbed.h>
00028 #include "DS18S20.h"
00029 #include "DS18B20.h"
00030 #include "OneWireDefs.h"
00031 
00032 //#define THERMOMETER DS18S20
00033 #define THERMOMETER DS18B20
00034 
00035 int main()
00036 {
00037     // device( crcOn, useAddress, parasitic, mbed pin )
00038     THERMOMETER device(true, true, false, p25);
00039     
00040     while (!device.initialize());    // keep calling until it works
00041     
00042     while (true)
00043     {
00044         // changing the resolutions only affects the DS18B20. The DS18S20 is fixed.
00045         device.setResolution(nineBit);
00046         device.readTemperature(); 
00047         wait(2);
00048         device.setResolution(tenBit);
00049         device.readTemperature(); 
00050         wait(2);
00051         device.setResolution(elevenBit);
00052         device.readTemperature(); 
00053         wait(2);
00054         device.setResolution(twelveBit);
00055         device.readTemperature(); 
00056         wait(2);
00057     }
00058      
00059     return EXIT_SUCCESS;
00060 }