The DS3231 RTC chip has a temperature measurement junction which is automatically sampled every 64 seconds. The measurement is placed in registers 17 & 18. Register 17 contains whole degrees and 18 the fraction if you want it (this fraction is binary point, not decimal point so MSB is 0.5d, next is 0.25d etc.).
This can be useful for measuring the (ambient) temperature of an enclosure.
Assuming positive, whole degrees only:
Code:
RTC GetReg 17,x% ' read the whole degrees only into integer variable x
x%=x% AND &h7f ' mask off the sign
If you wish to measure negative values also, the sign bit must be extended from bit 7 to the 63rd bit of the integer. Failure to do so will result in negative values registering from 128 to 255. To make it play nicely, use the sign extend function to convert the value into a proper signed integer thus:
Code:
RTC GetReg 17,x%
x%=SgnX(7,x%) ' extend bit 7 to the end of the integer
Dependency:
Sign Extend Function