Sample code with BluePill STM32F103C8 and Oled SSD1306 and LCD1602 on same connect on DS18B20.

Dependencies:   TextLCD

Committer:
diltech
Date:
Sun May 29 18:40:06 2022 -0400
Revision:
1:27d0c6ee0e55
Parent:
0:47b4bbc994df
Etape1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
diltech 0:47b4bbc994df 1 /* MIT License
diltech 0:47b4bbc994df 2 *
diltech 0:47b4bbc994df 3 * Copyright (c) 2020 Lukas Gessner
diltech 0:47b4bbc994df 4 *
diltech 0:47b4bbc994df 5 * Permission is hereby granted, free of charge, to any person obtaining a copy
diltech 0:47b4bbc994df 6 * of this software and associated documentation files (the "Software"), to deal
diltech 0:47b4bbc994df 7 * in the Software without restriction, including without limitation the rights
diltech 0:47b4bbc994df 8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
diltech 0:47b4bbc994df 9 * copies of the Software, and to permit persons to whom the Software is
diltech 0:47b4bbc994df 10 * furnished to do so, subject to the following conditions:
diltech 0:47b4bbc994df 11 *
diltech 0:47b4bbc994df 12 * The above copyright notice and this permission notice shall be included in all
diltech 0:47b4bbc994df 13 * copies or substantial portions of the Software.
diltech 0:47b4bbc994df 14 *
diltech 0:47b4bbc994df 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
diltech 0:47b4bbc994df 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
diltech 0:47b4bbc994df 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
diltech 0:47b4bbc994df 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
diltech 0:47b4bbc994df 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
diltech 0:47b4bbc994df 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
diltech 0:47b4bbc994df 21 * SOFTWARE.
diltech 0:47b4bbc994df 22 */
diltech 0:47b4bbc994df 23
diltech 0:47b4bbc994df 24 #ifndef DS18B20_h
diltech 0:47b4bbc994df 25 #define DS18B20_h
diltech 0:47b4bbc994df 26
diltech 0:47b4bbc994df 27 #include "mbed.h"
diltech 0:47b4bbc994df 28
diltech 0:47b4bbc994df 29
diltech 0:47b4bbc994df 30 #define OWI_SKIP_ROM 0xCC
diltech 0:47b4bbc994df 31 #define DS18B20_START 0x44
diltech 0:47b4bbc994df 32 #define DS18B20_READ_SCRATCH_PAD 0xBE
diltech 0:47b4bbc994df 33
diltech 0:47b4bbc994df 34 class OWI
diltech 0:47b4bbc994df 35 {
diltech 0:47b4bbc994df 36 public:
diltech 0:47b4bbc994df 37 OWI(PinName pin);
diltech 0:47b4bbc994df 38 void sendByte(unsigned char data);
diltech 0:47b4bbc994df 39 unsigned char receiveByte();
diltech 0:47b4bbc994df 40 unsigned char detectPresence();
diltech 0:47b4bbc994df 41
diltech 0:47b4bbc994df 42 private:
diltech 0:47b4bbc994df 43 void write0();
diltech 0:47b4bbc994df 44 void write1();
diltech 0:47b4bbc994df 45 unsigned char readBit();
diltech 0:47b4bbc994df 46 DigitalInOut owi_io;
diltech 0:47b4bbc994df 47 };
diltech 0:47b4bbc994df 48
diltech 0:47b4bbc994df 49 class DS18B20
diltech 0:47b4bbc994df 50 {
diltech 0:47b4bbc994df 51 public:
diltech 0:47b4bbc994df 52 DS18B20(PinName pin);
diltech 0:47b4bbc994df 53 float readTemp();
diltech 0:47b4bbc994df 54
diltech 0:47b4bbc994df 55 private:
diltech 0:47b4bbc994df 56 OWI DS18B20_OWI;
diltech 0:47b4bbc994df 57 };
diltech 0:47b4bbc994df 58
diltech 0:47b4bbc994df 59 #endif