Code:
''You really should not use constants for the address parameter for I2CREAD & I2CWRITE
'' From the PBP Manual
''Constants should not be used for the Address as the size can vary dependent on the size of the constant.
''Also, expressions should not be used as they can cause an improper Address size to be sent.
''TempRegister CON $11 'temperature integer REGISTER
''TempRegisterFRA CON $12 'temperature fraction REGISTER
TempRegister var byte ' variable to hold DS3231 register address to read/write
TempInt var byte ' Variable for temperature integer from register 11h
TempFrac var byte ' Variable for temperature fraction for register 12h
TempSign var bit ' Variable to hold sign bit
main:
LCDOut $fe,1
B0 = 0
button Taster0, 0, 100, 10, B0, 1, meni0
I2CRead SDA, SCL, RTC, SecReg, [sec,MINs,hr,day,date,mon,yr]
LCDOut $fe,2, HEX2 hr, ":", HEX2 MINs, ":", HEX2 sec
LCDOut $fe,$c0, HEX2 date, "/", HEX2 mon, "/","20" ,HEX2 yr
TempRegister = $11h ' DS3231 Temperature REgister High Byte (Integer portion)
I2Cread SDA, SCL, rtc, TempRegister, [TempInt, TempFrac]
TempFrac = (TempFrac >> 6) ' Shift <b7:b6> to <b1:b0>
TempFrac = (TempFrac * 25) ' Fractional portion is in .25 increments. Increment values are 0-3 (.00, .25, .50, .75)
TempSign = TempInt.7 ' save the sign bit for later
'''If TempSign = 1 then TempInt = (TempInt XOR $FF) + 1 'Do not use this, the DS3231 uses simple <b7> sign with <b6:b0> as absolute temperature value
If TempSign = 0 then ' Positive temperature
LCDOUT $FE, $80+9, "+", DEC2 TempInt, ".",DEC2 TempFrac 'Change to DEC2 to make sure LCD does not leave characters from previous temperature printout
Else ' Negative temperature
TempInt.7 = 0 ' Clear <b7> and use only the absolute value of 11h register value <b6:b0>
LCDOUT $FE, $80+9, "-", DEC2 TempInt, ".",DEC2 TempFrac 'Change to DEC2 to make sure LCD does not leave characters from previous temperature printout
Endif
GoTo main
Bookmarks