Custom

Dependencies:   mbed

Fork of OneWireCRC by Petras Saduikis

Committer:
fmanzano_dtk
Date:
Tue Oct 04 16:53:47 2016 +0000
Revision:
1:6af898f6c5e8
Parent:
0:01a6a40578c9
Owned;

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 }