/* ATtiny10 Thermometer v2 - see http://www.technoblogy.com/show?2G8A David Johnson-Davies - www.technoblogy.com - 7th March 2021 ATtiny10 @ 1MHz (internal oscillator) CC BY 4.0 Licensed under a Creative Commons Attribution 4.0 International license: http://creativecommons.org/licenses/by/4.0/ */ #include #include // One Wire Protocol ********************************************** // Buffer to read data or ROM code static union { uint8_t DataBytes[9]; unsigned int DataWords[4]; }; const int OneWirePin = 0; const int RedPin = 1; const int GreenPin = 2; const int ReadROM = 0x33; const int MatchROM = 0x55; const int SkipROM = 0xCC; const int ConvertT = 0x44; const int ReadScratchpad = 0xBE; inline void PinLow () { DDRB = DDRB | 1<>OneWirePin & 1; } void DelayMicros (unsigned int micro) { TCNT0 = 0; TIFR0 = 1<> 1; } } uint8_t OneWireRead () { uint8_t data = 0; for (int i = 0; i<8; i++) { LowRelease(6, 9); data = data | PinRead()<>1 ^ ((crc & 1) ? 0x8c : 0); } return crc; } // Display Error void DisplayError (int pin) { PORTB = PORTB | 1<=0; i--) { b = value>>i & 1; if (zeros || b || (i==0)) { if (value>>i & 1) Pulse(RedPin); else Pulse(GreenPin); zeros = true; } } } // Watchdog timer ********************************************** // Use Watchdog for time delay; n=0 is 16ms; n=6 is 1sec ; n=9 is 8secs, void WDDelay (int n) { set_sleep_mode(SLEEP_MODE_PWR_DOWN); WDTCSR = 1<>4); }