Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
DS1Wire.cpp
00001 #include "DS1Wire.h" 00002 #include "mbed.h" 00003 #include <stdint.h> 00004 00005 // Timing delay for 1-wire serial standard option 00006 enum DELAY { A = 6, B = 64, C = 60, D = 10, E = 9, F = 55, G = 0, H = 480, I = 70, J = 410 }; 00007 00008 00009 int Reset(DigitalInOut& pin) { 00010 pin.output(); 00011 pin = 0; // drive bus low 00012 wait_us(H); 00013 pin.input(); // release bus 00014 wait_us(I); 00015 uint32_t result = pin; // read bus value 00016 wait_us(J); 00017 return result; 00018 } 00019 00020 void WriteBit(DigitalInOut& pin, uint32_t bit) { 00021 pin.output(); 00022 if (bit) { 00023 pin = 0; // drive bus low 00024 wait_us(A); // delay A 00025 pin.input(); // release bus 00026 wait_us(B); // delay B 00027 } else { 00028 pin = 0; // drive bus low 00029 wait_us(C); // delay C 00030 pin.input(); // release bus 00031 wait_us(D); // delay D 00032 } 00033 } 00034 00035 uint32_t ReadBit(DigitalInOut& pin) { 00036 uint32_t bit_value; 00037 pin.output(); 00038 pin = 0; // drive bus low 00039 wait_us(A); // delay A 00040 pin.input(); // release bus 00041 wait_us(E); // delay E 00042 bit_value = pin; // master sample bus 00043 wait_us(F); 00044 return bit_value; 00045 } 00046 00047 void WriteByte(DigitalInOut& pin, uint32_t byte) { 00048 for (uint32_t bit = 0; bit < 8; ++bit) { 00049 WriteBit(pin, byte & 0x01); // lsb to msb 00050 byte >>= 1; // right shift by 1-bit 00051 } 00052 } 00053 00054 uint32_t ReadByte(DigitalInOut& pin) { 00055 uint32_t byte = 0; 00056 for (uint32_t bit = 0; bit < 8; ++bit) { 00057 byte |= (ReadBit(pin) << bit); // Reads lsb to msb 00058 } 00059 return byte; 00060 }
Generated on Thu Jul 14 2022 10:54:31 by
1.7.2