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

Committer:
snatch59
Date:
Sun Jan 03 11:57:31 2010 +0000
Revision:
0:01a6a40578c9

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
snatch59 0:01a6a40578c9 1 /*
snatch59 0:01a6a40578c9 2 * OneWireCRC/OneWireThermometer demo.
snatch59 0:01a6a40578c9 3 *
snatch59 0:01a6a40578c9 4 * Copyright (C) <2009> Petras Saduikis <petras@petras.co.uk>
snatch59 0:01a6a40578c9 5 *
snatch59 0:01a6a40578c9 6 * This file is part of OneWireCRC/OneWireThermometer.
snatch59 0:01a6a40578c9 7 *
snatch59 0:01a6a40578c9 8 * OneWireCRC/OneWireThermometer is free software: you can redistribute it and/or modify
snatch59 0:01a6a40578c9 9 * it under the terms of the GNU General Public License as published by
snatch59 0:01a6a40578c9 10 * the Free Software Foundation, either version 3 of the License, or
snatch59 0:01a6a40578c9 11 * (at your option) any later version.
snatch59 0:01a6a40578c9 12 *
snatch59 0:01a6a40578c9 13 * OneWireCRC/OneWireThermometer is distributed in the hope that it will be useful,
snatch59 0:01a6a40578c9 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
snatch59 0:01a6a40578c9 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
snatch59 0:01a6a40578c9 16 * GNU General Public License for more details.
snatch59 0:01a6a40578c9 17 *
snatch59 0:01a6a40578c9 18 * You should have received a copy of the GNU General Public License
snatch59 0:01a6a40578c9 19 * along with OneWireCRC/OneWireThermometer0. If not, see <http://www.gnu.org/licenses/>.
snatch59 0:01a6a40578c9 20 */
snatch59 0:01a6a40578c9 21
snatch59 0:01a6a40578c9 22 ////////////////////////////////////////////////////////////////////
snatch59 0:01a6a40578c9 23 // Test code to read temperature from a Maxim DS18B20 or DS18S20
snatch59 0:01a6a40578c9 24 // 1-wire device
snatch59 0:01a6a40578c9 25 ////////////////////////////////////////////////////////////////////
snatch59 0:01a6a40578c9 26
snatch59 0:01a6a40578c9 27 #include <mbed.h>
snatch59 0:01a6a40578c9 28 #include "DS18S20.h"
snatch59 0:01a6a40578c9 29 #include "DS18B20.h"
snatch59 0:01a6a40578c9 30 #include "OneWireDefs.h"
snatch59 0:01a6a40578c9 31
snatch59 0:01a6a40578c9 32 //#define THERMOMETER DS18S20
snatch59 0:01a6a40578c9 33 #define THERMOMETER DS18B20
snatch59 0:01a6a40578c9 34
snatch59 0:01a6a40578c9 35 int main()
snatch59 0:01a6a40578c9 36 {
snatch59 0:01a6a40578c9 37 // device( crcOn, useAddress, parasitic, mbed pin )
snatch59 0:01a6a40578c9 38 THERMOMETER device(true, true, false, p25);
snatch59 0:01a6a40578c9 39
snatch59 0:01a6a40578c9 40 while (!device.initialize()); // keep calling until it works
snatch59 0:01a6a40578c9 41
snatch59 0:01a6a40578c9 42 while (true)
snatch59 0:01a6a40578c9 43 {
snatch59 0:01a6a40578c9 44 // changing the resolutions only affects the DS18B20. The DS18S20 is fixed.
snatch59 0:01a6a40578c9 45 device.setResolution(nineBit);
snatch59 0:01a6a40578c9 46 device.readTemperature();
snatch59 0:01a6a40578c9 47 wait(2);
snatch59 0:01a6a40578c9 48 device.setResolution(tenBit);
snatch59 0:01a6a40578c9 49 device.readTemperature();
snatch59 0:01a6a40578c9 50 wait(2);
snatch59 0:01a6a40578c9 51 device.setResolution(elevenBit);
snatch59 0:01a6a40578c9 52 device.readTemperature();
snatch59 0:01a6a40578c9 53 wait(2);
snatch59 0:01a6a40578c9 54 device.setResolution(twelveBit);
snatch59 0:01a6a40578c9 55 device.readTemperature();
snatch59 0:01a6a40578c9 56 wait(2);
snatch59 0:01a6a40578c9 57 }
snatch59 0:01a6a40578c9 58
snatch59 0:01a6a40578c9 59 return EXIT_SUCCESS;
snatch59 0:01a6a40578c9 60 }